manual
38 www.microsoft.com/sharepoint
dollar sign ($) denotes a variable in Windows PowerShell. The semicolon (;) means "You
are done running this cmdlet, process the next cmdlet." This is the same as starting a
new line in Windows PowerShell.
Get-Content usernames.txt
This cmdlet reads each line of the file Usernames.txt and stores them as objects.
|
The pipe symbol means "Send the output of the preceding cmdlet to the next cmdlet."
ForEach-Object {New-SPManagedAccount -password $password -username litwareinc\$_; Set-
SPManagedAccount -identity $_ -autogenerate -confirm:$False}
The ForEach-Object cmdlet tells Windows PowerShell to run all cmdlets inside the braces ({ })
on each object separately until it processes all objects. In Steve’s case, this means "Take each
username, one at a time, and process them."
New-SPManagedAccount -password $password -username litwareinc\$_;
The first step in that process is to define each account as a managed account. The
New-SPManagedAccount is passed the $password variable Steve entered earlier, and for the
user name it uses the current username (object) from the text file. This is represented by the
variable $_ which Windows PowerShell automatically created when you got the objects from
the text file. Finally the semicolon (;) is used to say "This cmdlet is done, move to the next."
Set-SPManagedAccount -identity $_ -autogenerate -confirm:$False
This cmdlet takes the created managed account of $_ and automatically generates a new
password for it. The –confirm:$False string suppresses the command from prompting Steve to
confirm the password change.
Now Steve has configured all of his managed accounts and can use them for such things as
configuring service applications and application pool identities without regard to their actual
passwords.
Windows PowerShell Out-Performing Stsadm Scenario
Nicole needs to activate a feature across 5,500 site collections. By using Windows
PowerShell to run the Stsadm command, she came up with the following script to
automate the work: