小编Rob*_*Ppl的帖子

将 PowerShell 变量作为 cmdlet 参数传递

我正在学习 PowerShell 为我的团队编写工具。我今天很忙,但我想通过删除 ForEach 循环中的 IF 语句来简化它,因为命令之间的唯一区别是参数-replace-remove

Write-Host "This script removes or replaces en masse users' msds-SyncServerURL property"

DO {
    $TargetSSU=Read-Host "`nWhat msds-SyncServerURL do you want to replace or remove?"
    $UsersToBeFixed=Get-ADUser -Filter {msds-SyncServerURL -like $TargetSSU} -Properties ('name','samaccountname','msDS-SyncServerURL')
    IF ($UsersToBeFixed -eq $null) {
        Write-Host "`nNo users appear to have $TargetSSU as their msds-SyncServerURL value. Please try again."
    }
} UNTIL ($UsersToBeFixed -ne $null)

Write-Host "`n`nThe following users have $TargetSSU as their msds-SyncServerURL value:"
$UsersToBeFixed |select name,samaccountname,msds-syncserverurl|ft

DO …
Run Code Online (Sandbox Code Playgroud)

variables parameters powershell scripting active-directory

6
推荐指数
1
解决办法
3649
查看次数