2

I'm a bit stumped and have referenced multiple other entries on both SuperUser and StackOverflow concerning issues similar to mine, but to no avail thus far. I have also read various other websites and such via google search. Still stuck, however. Maybe I'm just dense :)

Anyway, I've got a shared folder entitled "WindowsUpdate" on my personal work computer that is available to all other computers (if an Admin) on our LAN here where I work. This folder includes a PowerShell script that automates my update process of which includes finding Windows updates, downloading them and then installing them. I'm using the Windows Update PowerShell Module to accomplish this task. Everything works fine from an update standpoint, except I'd like to also include a small line of code that copies the PowerShell Windows Update Module from my shared folder to the appropriate place on the C:\ of the remote machine. I have been unsuccessful in my numerous trials thus far. Any help will be much appreciated.

I have attempted to use the Copy-Item for this as well as my most recent attempt below in my script.

Echo ""
Echo "Setting Execution policy to BYPASS"
Set-ExecutionPolicy Bypass -Confirm:$false

Echo ""
Echo "Copying Module PSWindowsUpdate to PowerShell Modules Folder"
Invoke-Command -ComputerName AssistDirOffice -ScriptBlock {Copy-Item -Path  \\ASSISTDIROFFICE\WindowsUpdate\PSWindowsUpdate -Destination C:\Windows\System32\WindowsPowerShell\v1.0\Modules}
Pause

Echo""
Echo "Updating Chocolatey Packages"
#Queries Chocolatey.org database for updates to locally installed packages and updates them if necessary
cup all -y -allowemptychecksums

Echo ""
Echo "Importing Powershell Module PSWindowsUpdate"
#Installs Powershell Update module
Import-Module PSWindowsUpdate
refreshenv

Echo ""
Echo "Querying Microsoft Update Server for Windows Updates"
#Queries Microsoft Windows Update servers for updates and install any new  ones found.
Get-WUList

Echo ""
Echo "Hiding Microsoft Security Essentials and Skype Install and Updates"
Hide-WUUpdate -Title "Microsoft Security Essentials*" -Confrim:$false
Hide-WUUpdate -Title "Skpe*" -Confirm:$false
Hide-WUUpdate -Title "Preview*" -Confirm:$false

Echo ""
Echo "Downloading and Installing Windows Updates"
Get-WUInstall -acceptall 

Here is the error message I'm receiving from the above code:

[AssistDirOffice] Connecting to remote server AssistDirOffice failed with the following error message : The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. You can get more information about that by running the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.

  • CategoryInfo : OpenError: (AssistDirOffice:String) [], PSRemotingTransportException
  • FullyQualifiedErrorId : ServerNotTrusted,PSSessionStateBroken

My questions are as follows:

1) Am I using the correct code and syntax to accomplish this task?
2) There appears to be some sort of security issue involving a trusted host. What's the best way to resolve this?

UPDATE

I've continued fiddling with things and figured out how to make my computer a trusted host on the remote machine; however, I am now receiving this error message:

[AssistDirOffice] Connecting to remote server AssistDirOffice failed with the following error message : The WinRM client cannot process the request because the server name cannot be resolved. For more information, see the about_Remote_Troubleshooting Help topic.

  • CategoryInfo : OpenError: (AssistDirOffice:String) [], PSRemotingTransportException
  • FullyQualifiedErrorId : ComputerNotFound,PSSessionStateBroken

Other Notes That Might Be Helpful

I'm not trying to connect to an actual server or domain, just my work desktop which is effectively acting as a server I suppose.

2
  • 1
    Are we supposed to guess the error message? Please edit and include it in the question.
    – DavidPostill
    Commented Dec 7, 2016 at 23:51
  • 1
    @DavidPostill My apologies. I've edited my question to clarify things.
    – ahelton
    Commented Dec 8, 2016 at 17:57

1 Answer 1

2

Here's the problem(s):

Invoke-Command -ComputerName AssistDirOffice -ScriptBlock {
  Copy-Item -Path \\ASSISTDIROFFICE\WindowsUpdate\update-automation.ps1 
 -Destination C:\Windows\System32\WindowsPowerShell\v1.0\Modules
 }

1) If this is copy/pasted accurately, then your -Destination argument is on it's own line instead of being part of the Copy-Item command.

2) You are invoking Copy-Item on the remote computer (AssistDirOffice), yet you're referencing the paths as if it's running on the local computer.

Try replacing that block with just this:

Copy-Item -Path \\ASSISTDIROFFICE\WindowsUpdate\update-automation.ps1 -Destination C:\Windows\System32\WindowsPowerShell\v1.0\Modules
3
  • I just double-checked and it's all one line in my text editor. I have my editor set to auto-return after the line reaches a specified length, so that's why it copy and pasted as it did. I've edited my question to more specifically clarify my problem.
    – ahelton
    Commented Dec 8, 2016 at 17:59
  • I realized also that I was attempting to copy the wrong thing. I intended to copy my PSWindowsUpdate module over to the PowerShell Modules directory. I've made the appropriate change in my question to reflect this. I'm still receiving an error message, however.
    – ahelton
    Commented Dec 8, 2016 at 18:25
  • I changed my script block with what you suggested and it works! I was misunderstanding the invoke-command. Read a bit more about it and it makes sense now. Thanks for your help!
    – ahelton
    Commented Dec 8, 2016 at 22:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .