Using boolean properties with New-ADUser and Import-csv


hello all, trying bulk import users script wrote imports properties .csv file, when run it, error -enabled property, requires boolean input. still learning powershell, open suggestions regarding script. thanks! :)

this .csv looks like:
"name","samaccountname","givenname","surname","description","departement","enabled"
testuser01,testuser01,test,user,test account,it,$true

this script:


import-csv .\adusers.csv | foreach-object {    new-aduser     -name $_.name -samaccountname $_.samaccountname -givenname $_.givenname -surname $_.surname -description $_.description -department $_.departement `  -accountpassword (get-content .\password.txt | convertto-securestring) -enabled:$_.enabled -changepasswordatlogon $true -passthru    }  
, error get:

new-aduser : cannot convert 'system.string' type 'system.nullable`1[system.boolean]' required parameter 'enabled'.

at c:\test\createusers.ps1:3 char:81

+ ... ring) -enabled:$_.enabled -changepasswordatlogon $true -passthru

+                    ~~~~~~~~~~

    + categoryinfo          : invalidargument: (:) [new-aduser], parameterbindingexception

    + fullyqualifiederrorid : cannotconvertargument,microsoft.activedirectory.management.commands.newaduser







thank replies. able resolve issue.

had change boolean values in csv file $true , $false 1 , 0.


, in code had rewrite this:

-enabled:([bool]([int]$_.enabled ))

hope can in future. :)


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group