Trying to come up with a script to create an AD account and assign a password from a .csv file. When I run the script, I get the error "ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null." This would indicate that it's not pulling the password from the .csv file, but when I run import-csv q:\filepath.csv, it shows both columns in the csv: account and password.
Here is my script:
Import-Module ActiveDirectoryset-executionpolicy unrestricted
$Users = read-host "Enter the path to .csv file"
foreach ($User in $Users)
{
$OU = "OU=subfolder,OU=folder,DC=domain,DC=local"
$Detailedname = $user.account
$UserFirstname = $user.account
$SAM = $user.account
$Password = $user.password
New-ADUser -Name $Detailedname -SamAccountName $SAM -UserPrincipalName $SAM -DisplayName $Detailedname -AccountPassword (ConvertTo-SecureString -string $Password -AsPlainText -Force) -Enabled $true -Path $OU
}
Why would I be getting the error?