I m试图从我们每个域控制员那里为每个用户检索自动取款财产<代码>。 由于时间有限,Im试图使用Parallel
在PowerShell 7号专栏
Example
$users = Get-ADUser -Filter "[filter]"
$DCs = Get-ADDomainController -Filter * | Where-Object { $_.Site -in $using:sites }
$users | ForEach-Object -ThrottleLimit 2 -Parallel {
$serv = $using:DCs
foreach ($DC in $serv) {
$lastLogonAD = Get-ADUser -Identity $_ -Properties LastLogon -Server $DC -ErrorAction Stop | Select-Object -ExpandProperty LastLogon
$lastLogonConverted = [datetime]::FromFileTimeUTC($lastLogonAD)
}
}
Error
Get-ADUser:
Line |
7 | … $lastLogonAD = Get-ADUser -Identity $_ -Properties LastLogon -Server …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The server has returned the following error: invalid enumeration context.
我发现的是,如果我删除<条码>-Server<>>>参数,它就会发挥作用,或者如果我不将财产储存成一个变数,它就会发挥作用。
Removing the server parameter
foreach ($DC in $DCs) {
$lastLogonAD = Get-ADUser -Identity $_ -Properties LastLogon -ErrorAction Stop | Select-Object -ExpandProperty LastLogon
$lastLogonConverted = [datetime]::FromFileTimeUTC($lastLogonAD)
}
Not storing the variable
foreach ($DC in $DCs) {
Get-ADUser -Identity $_ -Properties LastLogon -Server $DC -ErrorAction Stop | Select-Object -ExpandProperty LastLogon
$lastLogonConverted = [datetime]::FromFileTimeUTC($lastLogonAD)
}