我试图立即在多个窗口中调用powershell脚本来安装软件。这将解决必须远程进入每个服务器并从我们的中央服务器调用此脚本的问题。我需要脚本启动多个窗口才能与安装脚本的自定义PowerShell菜单进行交互。提前谢谢。
Clear-Host
#Get-Credential
$a = @()
do{
$input = (Read-Host "Please enter the computer name")
if ($input -ne '') {$a += $input}
cls
Write-Host "Current servers: $($a)"
}until ($input -eq '')
$session
cls
for($i=0;$i -lt $a.Length;$i++)
{
if(!(Test-Connection -ComputerName $a[$i] -BufferSize 16 -Count 1 -ErrorAction 0 -Quiet))
{
Write-Host $a[$i] -ForegroundColor White -BackgroundColor Red
}
else
{
$session = New-PSSession $a[$i]
#$compString = ($computerarray|group|?{$_.count}|Select -ExpandProperty Name) -join ", "
#Invoke-Command -Session $session -ScriptBlock {Start-Process powershell '\\SERVER\D$\Inetsvcs\Software\IIS\test.ps1'}
#Invoke-expression 'cmd /c start powershell -Command {"\\SERVER\D$\Inetsvcs\Software\IIS\test.ps1"}'
Invoke-Command -Session $session -FilePath "\\SERVER\D$\Inetsvcs\Software\IIS\test.ps1"
}
}
foreach ($server in $a) {Remove-PSSession -ComputerName $server}