Home » Microsoft » 70-640 » Which script should you run?
You have a Windows PowerShell script that contains the following code:
import-csv Accounts.csv | Foreach {New-ADUser -Name $_.Name -Enabled $true – AccountPassword $_.password}
When you run the script, you receive an error message indicating that the format of the password is incorrect.
The script fails.
You need to run a script that successfully creates the user accounts by using the password contained in accounts.csv.
Which script should you run?
A. import-csv Accounts.csv | Foreach {New-ADUser -Name $_.Name -Enabled $true – AccountPassword (ConvertTo-SecureString "Password" -AsPlainText -force)}
B. import-csv Accounts.csv | Foreach {New-ADUser -Name $_.Name -Enabled $true – AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -force)}
C. import-csv Accounts.csv | Foreach {New-ADUser -Name $_.Name -Enabled $true – AccountPassword (Read-Host -AsSecureString "Password")}
D. import-csv Accounts.csv | Foreach {New-ADUser -Name $_.Name -Enabled $true – AccountPassword (Read-Host -AsSecureString $_.Password)}
Correct Answer: B
Explanation/Reference:
import-csv Accounts.csv | Foreach {
New-ADUser -Name $_.Name -Enabled $true – AccountPassword (ConvertTo-SecureString $_.Password
-AsPlainText -force)}
Personal comment:
import comma separated values file (most probably containing a column for Name and one for Password) for each line of values
create a new AD user
with the name contained in the Name
enable the account
and set the password with the value contained in the Password column; import the password from plain text as a secure string and ignore warnings/errors
http://technet.microsoft.com/en-us/library/hh849818.aspx
ConvertTo-SecureString
..
Parameters
-AsPlainText
Specifies a plain text string to convert to a secure string. The secure string cmdlets help protect confidential text. The text is encrypted for privacy and is deleted from computer memory after it is used. If you use this parameter to provide plain text as input, the system cannot protect that input in this manner. To use this parameter, you must also specify the Force parameter.
-Force
Confirms that you understand the implications of using the AsPlainText parameter and still want to use it.
…