I’m probably doing something silly but I can’t see where I’m failing here. Part of my script is
foreach($line in (Get-content .\accounts.txt)){
$LocAdmins = $_.Replace(‘',’/')
$LAdmins = ADSI
$Group = ADSI
$objGroup.PSBase.Invoke(“Add”,$LAdmins.PSBase.Path)
}
In accounts.txt I have a number of accounts in form of domain\accountname. What I need is to add these accounts to local admins.
I’m getting
You cannot call a method on a null-valued expression.
At line:2 char:9
Thanks for picking this up. Indeed there should be $line in that line, yet when I run it in debugging my $LocAdmins doesn’t get any value even though when I hover over $line.Replace I see the account I want to add to administrators…