# $cred = get-Credential -credential kdoan-a $Username = 'kimconnect\kim-Admin $Password = 'PASSWORD' $pass = ConvertTo-SecureString -AsPlainText $Password -Force $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$pass # Initialize $servers="servero1","server02" $services="" $output="" # List all currently running services on remote hosts > output to comma delimited strings function listServices{ Foreach ($server in $servers){ $runningServices=Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock {Get-WmiObject win32_service -Filter "State='running' AND StartMode='Auto'"}; $runningServices='"{0}"' -f ($runningServices.name -join '","') $output+=@(($server),($runningServices)) } $output } listServices
March 29, 2019March 29, 2019
0 Comments