Powershell : PS Sessions to multiple Computers from Text File
Hello to all and thanks for reading or corrections,
I Wrote this script without the possibility to test with multiple platforms cause I'm at work and it is a sensitive production environment so WinRM is not enabled/allowed for management purposes (X_X) .
Just use a simple text file without text formating like this :
Srv01
Srv02
Srv03
Or Srv01,Srv02,Srv03
So here is the code to copy/paste :
# Note that PS Remoting use Kerberos authentification Only so you have to provide Domain\User credentials
$Cred = Get-Credential
$computer = get-content c:\computers.txt
$Psession = New-PSSession -Credential $Cred -ComputerName $computers -ErrorAction:SilentlyContinue
Foreach ($computers in $computer)
{$Psession}
# Get all Currents PsSessions
$ListPsession = Get-pssession | ft Id,Name,ComputerName,State
If ($pssession -eq $True)
{Write-Output "Connected to $ListPsession. `r"}
Elseif ($pssession -ne $True)
{Write-Output "Can not connect to $pssession. You have to verify WinRM listner config (winrm g config) on computer or execute winrm qc command lines.Quick Help : get-service winrm,get-pssessionconfiguration ,Enable-PsRemoting -Force .`r"}
Break