1

I was going to automate some regular task on client computers using Powershell module. In this way, PSWINDOWSUPDATE is one of bests. But, I receive an error during install that:

    PS C:\Users\stackoverflow> install-module -name pswindowsupdate -scope currentuser 
    PackageManagement\Install-Package : Package 'PSWindowsUpdate' failed to be installed because: 
Access to the path        'C:\Users\stackoverflow\AppData\Local\Temp\ipufiq2h\PSWindowsUpdate.dll' is denied.
    At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
    + ...          $null = PackageManagement\Install-Package @PSBoundParameters
    +                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidResult: (PSWindowsUpdate:String) [Install-Package], Exception
        + FullyQualifiedErrorId : Package '{0}' failed to be installed because: {1},Microsoft.PowerShell.PackageManagement
       .Cmdlets.InstallPackage

running the command in administrative mode and without -scope switch didn't solve the problem.

Edit1: The problem is solved. But there is another problem. When I call import-module pswindowsupdate following error occurs:

import-module : Errors occurred while loading the format data file:
C:\Users\stackoverflow\Documents\WindowsPowerShell\Modules\pswindowsupdate\2.2.0.2\PSWindowsUpdate.Format.ps1xml, ,
C:\Users\stackoverflow\Documents\WindowsPowerShell\Modules\pswindowsupdate\2.2.0.2\PSWindowsUpdate.Format.ps1xml: The file was skipped because of the following validation exception: File
C:\Users\stackoverflow\Documents\WindowsPowerShell\Modules\pswindowsupdate\2.2.0.2\PSWindowsUpdate.Format.ps1xml cannot be loaded because running scripts is disabled on this system. For more
information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170..
At line:1 char:1
+ import-module pswindowsupdate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Salem
  • 11
  • 1
  • 3
  • 2
    Read the MS link in the error code - there's a `Set-ExecutionPolicy` command..... – Scepticalist Jan 25 '22 at 11:07
  • Does this answer your question? [PowerShell says "execution of scripts is disabled on this system."](https://stackoverflow.com/questions/4037939/powershell-says-execution-of-scripts-is-disabled-on-this-system) – Albin May 19 '22 at 03:32

1 Answers1

1

Use Get-ExecutionPolicy to set it e.g. to RemoteSigned:

Get-ExecutionPolicy -List
Set-ExecutionPolicy RemoteSigned

also see here

Albin
  • 1,000
  • 1
  • 11
  • 33