csv - Powershell Error -
i getting below error when run powershell code. cannot figure out @ all. not sure if has name of file location or not.
import-csv : cannot bind parameter 'delimiter'. cannot convert value "csv" type "system.char". error: "string must 1 character long." @ line:4 char:60 + ... grouplist = import-csv c:\users\eh3599\desktop\powershell csv test\te ... + ~~~ + categoryinfo : invalidargument: (:) [import-csv], parameterbindingexception + fullyqualifiederrorid : cannotconvertargumentnomessage,microsoft.powershell.commands.importcsvcommand
script source:
set-executionpolicy unrestricted import-module activedirectory $grouplist = import-csv c:\users\eh3599\desktop\powershell csv test\test2-testoutput1.csv -header groupname,domain | select groupname,domain $table = @() $record = @{} foreach ($group in $grouplist) { if ($group.domain -eq "a") {$domainpath = "a.corp"} if ($group.domain -eq "x") {$domainpath = "x.corp"} if ($group.domain -eq "y") {$domainpath = "y.com"} if ($group.domain -eq "b") {$domainpath = "b.com"} #get-adgroupmember command -recursive switch includes object type users members of nested groups $groupmembership = get-adgroupmember -identity $group.groupname -server $domainpath -recursive | select samaccountname, name, objectclass, distinguishedname #get-adgroupmember command without -recursive switch includes both user , group objects no membership of nested groups #$groupmembership = get-adgroupmember -identity $group.groupname -server $domainpath | select samaccountname, name, objectclass, distinguishedname foreach ($groupmember in $groupmembership) { $record."account name" = $groupmember.samaccountname $record."full name" = $groupmember.name $record."objectclass" = $groupmember.objectclass $record."object distinguishedname" = $groupmember.distinguishedname $record."group name" = $group.groupname $record."group domain" = $group.domain $objrecord = new-object psobject -property $record $table += $objrecord } } $table | export-csv "c:\users\eh3599\desktop\powershell csv test\$(get-date -f yyyy-mm-dd-hh-mm-ss)-adgroupmembers.csv" -notypeinformation
whenever have path (file or folder name) contains white space, need quote it:
$grouplist = import-csv "c:\users\eh3599\desktop\powershell csv test\test2-testoutput1.csv" -header groupname,domain | select groupname,domain
Comments
Post a Comment