gpt4 book ai didi

powershell - WS-Management服务无法处理请求:Powershell

转载 作者:行者123 更新时间:2023-12-03 00:44:11 25 4
gpt4 key购买 nike

我随机得到以下错误

The WS-Management service cannot process the request. This user is allowed a maximum number of 5 concurrent shells, which has been exceeded. Close existing shells or raise the quota for this user. For more information, see the about_Remote_Troubleshooting Help topic.



我的示例代码如下
try
{
$serverlist=server1...server100
foreach($computer in $computers)
{
Enter-PSSession -ComputerName $computer

$Ostype = (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer -ErrorAction SilentlyContinue ).Caption

Exit-PSSession
}
}
Catch
{
[System.Windows.MessageBox]::Show($_.exception.message)
}
finally
{
Exit-pssession
}

在执行脚本的过程中有时会发生错误,因此上述错误使我相信,我没有正确关闭PSsession。

有人可以让我知道我做得对吗

最佳答案

请尝试以下代码。它不使用交互式 session ,而是使用Invoke-Command cmdlet。

try
{
$serverlist=server1...server100
foreach($computer in $computers)
{
$s = New-PSSession -ComputerName $computer
Invoke-Command -Session $s -ScriptBlock {$os = (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer -ErrorAction SilentlyContinue ).Caption}

Remove-PSSession -Session $s
}
}
Catch
{
[System.Windows.MessageBox]::Show($_.exception.message)
}

关于powershell - WS-Management服务无法处理请求:Powershell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51752872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com