I need to execute a PopwerShell script on a remote host (i.e. to add or remove Windows features).
The script uses some Powershell commands to be executed on the remote host (i.e. to add or remove Windows features).
I made part of the job but I am unable to go on...
After enabling PSremoting on the target host I run a script with the following commands:
winrm s winrm/config/client '@{TrustedHosts="remoteserver"}'
$mysession = new-pssession -computername remoteserver -credential remotedomain\remoteuser
If I enter the above lines interactiverly I can go on interactively by entering:
Enter-PSSession $mysession
and execute all the PowerShell commands I need.
My problem is that everything must be part of a script.
I attempted using "Invoke-command" with no success: maybe there is a syntax error or it is not the right command to be used in a script.
Can anybody please provede a sample of a script containing PowerShell commands to be executed on the remore host?
Regards
marius