error when executing powershell script

Posted on 2012-08-10
Last Modified: 2012-08-13

When, I execute this script, this error is returned :
$Computer = (Get-WmiObject Win32_Computersystem).Name
$Username = "$U"
$Domain = "$D"
set-location $env:SYSTEMDRIVE\cygwin\bin

$Group = [ADSI]"WinNT://$Computer/Administrators,group"
$User = [ADSI]"WinNT://$Domain/$Username,user"



Question by:bibi92
    1 Comment
    LVL 12

    Accepted Solution

    You did not provide the error!

    I am going to guess it is the cryptic "format-default : The following exception occurred while retrieving member "PSComputerName".....

    That would indicate your domain or username does not exist and so could not be found.

    It would be a lot simpler to use the AD Powershell cmdlets, which are available on any DC or a machine where you have installed the RSAT for AD features.  

    Add-ADGroupMember $Group $Username

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
    The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now