1

PowerShell を初めて使用するので、スクリプトのエラーについてサポートが必要です。基本的に、Active Directory からすべてのユーザーをインポートしようとしています。スクリプトは以下のとおりです。

#Location the CSV file is being saved.
$csvFileLocation = "C:\ADImport\ADImport.csv"

#Verifies that the AD Module is loaded.  If it is not, checks if it is available, if it is, loads it.

Function Get-ADModule {
    if(-not(Get-Module -Name ActiveDirectory)) {
        if(Get-Module -ListAvailable | Where-Object {$_.Name -eq "ActiveDirectory" }) {
            Import-Module -Name ActiveDirectory
            $true
        } else {
            $false
        }
    } else {
        $true
    }
}

if (Get-ADModule) {
    #Creates the CSV Table Format, change the AD DS TableNames to the CoarseMail TableNames
    $tableFormat = @{ Expression = { $_.GivenName -replace ","," " };Label = "FirstName" },
                   @{ Expression = { $_.SurName -replace ","," " };Label = "LastName" },
                   @{ Expression = { $_.SAMAccountName -replace ","," " };Label = "ID" }
    #Gets AD User Objects that are enabled, and only specified properties for perfomance, filters out specified OU's, filters out objects with no first or last name or EmployeeID.
    Get-ADUser -SearchBase "DC=mydomain,DC=com" -Properties SAMAccountName, GivenName, Surname `
    | Where-Object {
         ($_.GivenName -ne $null) -and
         (($_.GivenName.Length -ne 0) -and ($_.SurName.Length -ne 0))
      } `
    | Select-Object $tableFormat | Export-Csv
    $csvFileLocation -NoType
} else {
    Add-Content ($csvFileLocation + ".txt") "The ActiveDirecotry Powershell Module does not
    exist on this machine."
}

私が得ているエラーは以下の通りです:

PS C:\Users\benc> C:\Users\benc\Desktop\ADImportTest.ps1
Get-ADUser : Cannot validate argument on parameter 'Filter'. The argument is null or empty.
Supply an argument that is not null or empty and then try the command again.
At C:\Users\benc\Desktop\ADImportTest.ps1:27 char:15
+     Get-ADUser <<<<  -SearchBase "DC=mydomain,DC=com" `
    + CategoryInfo          : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
    + FullyQualifiedErrorId :
ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser

スクリプトのどこが間違っているのかわかりませんが、助けていただければ幸いです。

4

1 に答える 1