I’m trying to learn how to use an Invoke-Command with a ScriptBlock to add a registry key. My end goal is to be able to run this against a list of remote computers, but for now I’m just testing it on my local Windows 10 machine. I have already run ‘WinRM Quickconfig’ and ‘Enable-PSRemoting -force’. However, when I run the script against my local hostname it appears to skip the reg commands in the script block. When I run those same commands directly in a PS prompt they run as expected and the reg key gets created.
I have Don Jones’ book “Learn Windows PowerShell in a Month of Lunches” and it mentions a common error after running the Enable-PSRemoting command which is related to “one of the network connection types on this machine is set to Public”. I did receive this error so I ran the following command to check it:
Thanks for the -SkipNetworkProfilecheck switch. I ran this and it did not return the error this time.
PS C:\coding> Enable-PSRemoting -SkipNetworkProfileCheck -Force
WinRM is already set up to receive requests on this computer.
WinRM has been updated for remote management.
WinRM firewall exception enabled.
However, when I run my script it still does not execute the script block as expected.
When I run then directly in the PowerShell command prompt they run fine and they create the reg key as expected. But they are not running from my script. Here is the output I’m seeing now:
Transcript started, output file is C:\coding\PowerShell\RegFixes\serverlog.txt
Working on XYZ-Workstation
Transcript stopped, output file is C:\coding\PowerShell\RegFixes\serverlog.txt
Hi. It seems maybe this forum is not very active these days but I found the solution in another forum. I didn’t realize that Invoke-Command would not work on a non-server class machine. Once I tried it on a Windows server it worked perfectly fine. Thanks again.
[quote quote=214044]Hi. It seems maybe this forum is not very active these days but I found the solution in another forum. I didn’t realize that Invoke-Command would not work on a non-server class machine. Once I tried it on a Windows server it worked perfectly fine. Thanks again.
[/quote]
To identify the issue you should go through the error. You are suppressing the same. How could we understand whats going on there? Even when we asked, you also failed to submit that.