$VerbosePreference='continue' ###################################################################################### # # Servers you want to connect # ###################################################################################### $list_of_server_to_connect = [ordered]@{ "te-prd-app-01" = [PSCustomObject]@{ "Name"="te-prd-app-01.roser-total.local" "username"="roser-total\pgeeraert" "password"="Pr0m3th3us!!" } } ###################################################################################### # # Command to type # ###################################################################################### $command_to_type = hostname $pw = convertto-securestring -AsPlainText -Force -String "Pr0m3th3us!!" $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "roser-total\pgeeraert",$pw $server_to_connect = $list_of_server_to_connect.$server.Name $session = New-PSSession -ComputerName $server_to_connect -Credential $cred Invoke-Command -Session $session -ScriptBlock { hostname } <# foreach($server in $list_of_server_to_connect.keys){ write-output $server write-output $list_of_server_to_connect.$server.Name $pw = convertto-securestring -AsPlainText -Force -String $list_of_server_to_connect.$server.password $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $list_of_server_to_connect.$server.username,$pw $server_to_connect = $list_of_server_to_connect.$server.Name $session = New-PSSession -ComputerName $server_to_connect -Credential $cred Invoke-Command -Session $session -ScriptBlock { hostname } } #get the target #>