Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Importing CSV successfully, getting error "ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null"

$
0
0

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 ActiveDirectory 
set-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?


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>