我是Powershell的初学者。
所以我试图远程启动一项服务并将其设置为自动。
以某种方式我会丢失一些东西,因为它每次运行时仅执行一个命令,并且不会给我返回错误。
有人可以帮我吗?
#Get target systems by user input
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$computerlist = [Microsoft.VisualBasic.Interaction]::InputBox("Bitte kompletten Computernamen eingeben [mit komma getrennt!] `n`nExample: wst10071234", "Target systems")
$computerlistarray = $computerlist.split(",").Trim()
#Check if input is not empty
if (!$computerlist) {
write-error -Message "No system defined. Script will abort!"
exit
}
#Check, clean and create list of computers
foreach ($cpt in $computerlistarray) {
if ($cpt -match "^\d{4}$") {
$computers += $cptprefixtype+$cptprefix+$cpt
}
elseif ($cpt -match "^(wst|mob)\d{8}$") {
$computers += $cpt
}
elseif ($cpt -match "^\d{8}$") {
$computers += $cptprefixtype+$cpt
}
else { write-host "Wrong pattern for $cpt! Skipped!" -ForegroundColor Yellow
}
}
foreach ($computer in $computers) {
Get-Service ZKB_CollectPerfCounters -Computer $computer | start-service}
foreach ($computer in $computers) {
Set-Service ZKB_CollectPerfCounters –Computer $computer –StartupType automatic}