当我本地在服务器中运行此功能时,
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = New-Object System.Net.WebClient; $webClient.DownloadFile('https://bod-T2.com:8140/packages/current/install.ps1', 'install.ps1'); .install.ps1 extension_requests:pp_role=utility extension_requests:pp_environment=e1 agent:noop=true
但是当我尝试大量运行它时,我创建了这个脚本,您可以找到Bellow,但无法正常工作。你们能帮我吗?
$InputServerList=Import-Csv -Delimiter ";" .ServerList.txt
$pw = convertto-securestring 'PASSWORD' -AsPlainText -Force
$mycreds = new-object -typename
System.Management.Automation.PSCredential -argumentlist
"domainmyuser",$pw
$ErrorActionPreference = "Stop"
$InputServerList | ForEach {
if ($session_id=new-pssession -computername $_.IPAddress -credential $mycreds)
{
#If we reached here it is because credentials were OK on the first attempt so we now silently continue on errors
$ErrorActionPreference = "SilentlyContinue"
Set-ExecutionPolicy -Scope Process -ExecutionPolicy AllSigned
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = New-Object System.Net.WebClient; $webClient.DownloadFile('https://bod-T2.com:8140/packages/current/install.ps1', 'install.ps1'); .install.ps1 extension_requests:pp_role=utility extension_requests:pp_environment=e1 agent:noop=true
write-host "$($_.ServerName) was configured" -BackgroundColor 00 -ForegroundColor 10
Remove-PSSession $Session_id
} else {
write-host "$($_.ServerName) $($_.IPaddress) Unable to connect" -BackgroundColor RED -ForegroundColor Yellow
}
}
基本上我需要在多个服务器中运行它:
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = New-Object System.Net.WebClient; $webClient.DownloadFile('https://bod-T2.com:8140/packages/current/install.ps1', 'install.ps1'); .install.ps1 extension_requests:pp_role=utility extension_requests:pp_environment=e1 agent:noop=true
也许我错过了一些东西,但是您似乎并没有使用 $session_id
,请看一下Invoke-command
您需要做类似:
的事情$MySB = {
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile('https://bod-T2.com:8140/packages/current/install.ps1', 'install.ps1')
.install.ps1 extension_requests:pp_role=utility extension_requests:pp_environment=e1 agent:noop=true
}
invoke-command -Session $session_id -ScriptBlock $MySB