[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1124
  • 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

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

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