• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1135
  • Last Modified:

error when executing powershell script

Hello,

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"
$Group.Add($User.Path)

Thanks

Regards

bibi
0
bibi92
Asked:
bibi92
1 Solution
 
Carlo-GiulianiCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now