Which script should you run?

You have a Windows PowerShell scriptthat 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?

You have a Windows PowerShell scriptthat 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)}

Explanation:
import-csv Accounts.csv |
Foreach {
New-ADUser -Name $_.Name-Enabled $true – AccountPassword (ConvertTo-SecureString $_.PasswordAsPlainText -force)}
Personal comment:
import comma separated values file (most probably containing a column for Nameand one for Password)
for each line of values
create a new AD user
with the name contained in the Namecolumn
enable the account
and set the password with the value contained in the Passwordcolumn; 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 useit.



Leave a Reply 0

Your email address will not be published. Required fields are marked *