Note that there are some explanatory texts on larger screens.

plurals
  1. POPowerShell script issue
    primarykey
    data
    text
    <p>We're trying to bulk-create users on a Windows 2012 Server system; the system is only intended to allow us to validate an ALM solution and it will be extremely short lived, which means we do not care for now for security. When running the script below, the shell reports Exception calling "SetInfo" with "0" argument(s): "The specified username is invalid." for each line in the input file. However, if we manually execute the lines inside the loop, the user is properly created.</p> <pre><code># Work on the local system $Computer =[ADSI]"WinNT://$env:ComputerName,Computer" $UsersFilePath = "C:\users\Administrator\Downloads\ActiveUsers.txt" $Group=[ADSI]"WinNT://WORKGROUP/./Developers,Group" Get-Content $UsersFilePath | % { $_ # Debug only line, remove it when done $LocalUser=$Computer.Create("User", $_ ) $LocalUser.SetPassword( $_ ) $LocalUser # Debug only line, remove it when done $LocalUser.SetInfo() } </code></pre> <p>How should we write the loop? </p> <p>[Here is the answer, as suggested by mjolinor; the main change is the trimming of the name read from the file] </p> <pre><code># Work on the local system $Computer =[ADSI]"WinNT://$env:ComputerName,Computer" $UsersFilePath = "C:\users\Administrator\Downloads\ActiveUsers1.txt" $Group=[ADSI]"WinNT://WORKGROUP/./Developers,Group" Get-Content $UsersFilePath | % { $_ # Debug only line, remove it when done $UserName = $_.Trim() $LocalUser=$Computer.Create("User", $UserName) $LocalUser.SetPassword( $UserName ) #$LocalUser.put("userPrincipalName", "${name}@svr-tfs2013" ) $LocalUser # Debug only line, remove it when done $LocalUser.SetInfo() $Group.Add($LocalUser.path) } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload