【发布时间】:2020-02-19 03:00:41
【问题描述】:
我正在尝试运行以下代码来搜索 OU 中的非活动用户帐户。似乎我正在使用的变量类型可能无法与参数一起使用。这看起来正确吗?如果正确,我应该使用什么类型的变量?
$scope = "-UsersOnly"
$accounts = Search-ADAccount -SearchBase "OU=Users,OU=testLab02,DC=test,DC=local" -AccountInactive -TimeSpan ([timespan]7D) $scope
foreach($account in $accounts){
If ($noDisable -notcontains $account.Name) {
Write-Host $account
#Disable-ADAccount -Identity $account.DistinguishedName -Verbose $whatIf | Export-Csv $logFile
}
}
我收到以下错误:
Search-ADAccount:找不到接受参数“-UsersOnly”的位置参数。 在 C:\Users\Administrator\Documents\Disable-ADAccounts.ps1:63 char:21 + ... $accounts = Search-ADAccount -SearchBase $OU.DistinguishedName -Accou ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Search-ADAccount], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SearchADAccount
但是,如果我在没有变量的情况下手动运行命令,它会按预期工作:
Search-ADAccount -SearchBase "OU=Users,OU=testLab02,DC=test,DC=local" -AccountInactive -TimeSpan ([timespan]7D) -UsersOnly
【问题讨论】:
-
PowerShell 错误消息的屏幕截图真的对于我们这些色盲且无法看到蓝色红色的人来说很难。也许改为发布文字?
-
对不起,请看我的编辑。
标签: powershell parameters active-directory powershell-5.0