Forum Discussion
Entering in commands on a remote workstation using a PS script
Use the credentials when creating the session, not with Invoke-Command
Please try this script.
$cred = Get-Credential
$session = New-PSSession -ComputerName $workstationName -Credential $cred
if ($session -ne $null) {
Invoke-Command -Session $session -ScriptBlock {
netsh advfirewall firewall set rule name="File and Printer Sharing (Echo Request - ICMPv4-In)" new enable=yes profile=domain
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value 0
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
netsh advfirewall firewall set rule group="windows management instrumentation (wmi)" new enable=yes
Set-NetFirewallRule -DisplayGroup "Network Discovery" -Enabled True
Get-Process
}
Remove-PSSession -Session $session
} else {
Write-Host "Failed to establish a session."
}