i wrote a script that works perfect. The code is:
[Array] $Services = '1.service','2.serviec','3.service';
# loop through each service, if its running, stop it
foreach($ServiceName in $Services)
{
$arrService = Get-Service -Name $ServiceName
write-host $ServiceName
while ($arrService.Status -eq 'Running')
{
Stop-Service $ServiceName
write-host $arrService.status
write-host $ServiceName stopping
Start-Sleep -seconds 60
$arrService.Refresh()
if ($arrService.Status -eq 'Stopped')
{
Write-Host $ServiceName is now Stopped
}
}
}
But I need a script that ask a names service and enter in [Array] $Services = ... I tryed to add this:
$Dienst = Read-Host "Please enter the Services"
[Array] $Services = $Dienst
# loop through each service, if its running, stop it
foreach($ServiceName in $Services)
{
$arrService = Get-Service -Name $ServiceName
write-host $ServiceName
while ($arrService.Status -eq 'Running')
{
Stop-Service $ServiceName
write-host $arrService.status
write-host $ServiceName stopping
Start-Sleep -seconds 60
$arrService.Refresh()
if ($arrService.Status -eq 'Stopped')
{
Write-Host $ServiceName is now Stopped
}
}
}
When i started the script receive an error
My Question is - How i can add a different service, which powershell can find in system? Thanks a lot.