PS版本:5.0.10586.117
我的要求是遍历服务器列表并使用“Get-ADDefaultDomainPasswordPolicy”。我想生成一个具有服务器名称和MaxPasswordAge的列表。我已经验证我的凭据可用于远程服务。我不想更改MaxPasswordAge,我只是想知道它对于指定的服务器是什么。
Server Name MaxPasswordAge
Server1.domain.com 90
Server2.domain.com 109
Server3.domain.com 109
我经常遇到的错误如下:
New-PSSession : [Server1.domain.com] Connecting to remote server Server1.domain.com failed with the following error message : The WS-Management service cannot process the request. The maximum number of concurrent shells for this user has been
exceeded. Close existing shells or raise the quota for this user. For more information, see the about_Remote_Troubleshooting Help topic.
At line:4 char:12
+ $Install = New-PSSession -ComputerName $SServer -Credential $Cred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : -2144108123,PSSessionOpenFailed
VERBOSE: Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
这是我正在使用的代码。任何帮助将不胜感激。我应该使用:Get-ADFineGrainedPasswordPolicy -Filter {Name -like "*"}
吗?
$servers = get-content "C:\TEMP\servers.txt"
$Cred = Get-Credential
$Result = $()
ForEach ($Computer in $servers)
{
Try
{
$Session = New-PSSession -ComputerName $Computer -Credential $Cred
$Result = Invoke-Command -Session $Session -ScriptBlock {param($RName) Get-ADDefaultDomainPasswordPolicy -server $RName | Select $RName, maxpasswordage | Format-Table} -ErrorAction Stop -ArgumentList $Computer
Remove-PSSession $Session
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Verbose -Message $ErrorMessage -Verbose
}
}
$Result | Export-Csv "C:\TEMP\ServerMaxPWAge.csv" -NoTypeInformation