$computers =
@"
computer1
computer2
"@ -split [Environment]::NewLine
$computers | ForEach-Object {
$ServerUserId = "_$\user1"
$ServerPassword = ConvertTo-SecureString -String 'complexpassword' -AsPlainText -Force
$Credential = New-Object -TypeName PSCredential -ArgumentList $ServerUserId, $ServerPassword
Enter-PSSession -ComputerName $_ -Credential $Credential
"Computer name: $_"
get-service -ComputerName $computers -Name `
Service* `
Exit-PSSession
}
Output:
Computer name: Computer1
Service A
Service B
Computer name: Computer2
Service Y
Service Z
Would like it to look like:
Service A Computer1
Service B Computer1
Service Y Computer2
Service Z Computer2