-1
當我運行我的PowerShell代碼時,出現以下錯誤。我根本弄不清楚。我不確定它是否與我的文件位置的名稱有關。PowerShell錯誤
Import-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "CSV" to type "System.Char". Error: "String must be exactly one character long."
At 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
腳本來源:
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 with -Recursive switch includes only object type users with 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 and Group objects but 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
導入請確保您的路徑放在引號當。 'Import-CSV C:\ Users \ eh3599 \ Desktop \ Powershell CSV Test \ Test2-TestOutput1.csv'您的導入路徑缺少引號,導致沒有任何內容被加載。 –
標記爲關閉/錯字 –
@JasonSnell不完全正確。它將'CSV'綁定到分隔符位置參數,並且該路徑只被解釋爲'C:\ Users \ eh3599 \ Desktop \ Powershell'因此它試圖找到一個名爲'Powershell'的文件並使用'CSV'分隔條目hah – TheIncorrigible1