"Install-Package : Exception calling CloneRequest" while installing Powershell modules over SSH - powershell

I am trying to automate installing a module from a custom repository on a windows machine by pushing a ps1 script from a Linux machine to the windows machine, and then trying to execute the script over ssh. The windows is running a cygwin server. When I run the ps1 script directly on powershell, the script runs fine. But when I run the same over ssh, it fails with the following error:
PackageManagement\Install-Package : Exception calling "CloneRequest" with "3" argument(s): "Object reference not set
to an instance of an object."
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1875 char:34
+ ... $null = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exce
ption
+ FullyQualifiedErrorId : NullReferenceException,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
The script fails at the line:
Find-Module -Name <module name> -AllVersions -Repository <repo name> | Install-Module -SkipPublisherCheck -Scope AllUsers -Force
This is how I am calling the script from the linux machine:
ssh user#windowsIp powershell -NonInteractive -File E:\moduleInstaller.ps1 repositoryUrl moduleName moduleVersion

Related

module 'posh-git' was not loaded : getting error in powershell

I uninstalled the posh-git for Windows module and now whenever I open my PowerShell, I get the below error same time.
Import-Module : The specified module 'posh-git' was not loaded because no valid module file was found in any module
directory.
At C:\\Users\\Parth\\OneDrive\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1:2 char:1
+ Import-Module posh-git
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (posh-git:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
(not sure) I run all the below code in my PowerShell so I Getting this error :
##To enable posh-git to be available in just the current host, execute:
Add-PoshGitToProfile
##To enable posh-git to be available in all your PowerShell hosts-console, ISE, etc, execute:
Add-PoshGitToProfile -AllHosts
##To enable posh-git to be available for all users on the system, execute:
Add-PoshGitToProfile -AllUsers -AllHosts
##To enable posh-git to be available for all users but only for the current host
Add-PoshGitToProfile -AllUsers

Error during installing PSWindows Update module

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
Use Get-ExecutionPolicy to set it e.g. to RemoteSigned:
Get-ExecutionPolicy -List
Set-ExecutionPolicy RemoteSigned
also see here

Install .cer certificate in "Trusted Devices" folder via PowerShell

I need to install .cer certificate into "Trusted Devices" folder because I have PowerShell script which automatically installs software and only thing that is blocks the hole script is windows which asks about trustworthy of the dongle driver.
I use this cmdlet inside Vagrant
vagrant.exe powershell -c "Import-Certificate -Filepath C:\vagrant\Microcosm.cer -CertStoreLocation Cert:\Local Computer\TrustedDevices"
Here is error message output
vagrant.exe : The following WinRM command responded with a non-zero exit status.
At line:1 char:2
+ vagrant.exe powershell -c "Import-Certificate -Filepath C:\vagrant\Microcosm.ce ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (The following W...ro exit status.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Vagrant assumes that this means the command failed!
Import-Certificate -Filepath C:\vagrant\Microcosm.cer -CertStoreLocation Cert:\Local Computer\TrustedDevices
Stdout from the command:
Stderr from the command:
#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">Import-Certificate : A positional parameter cannot be found that accepts argument 'Computer\Trust
edDevices'._x000D__x000A_</S><S S="Error">At line:1 char:40_x000D__x000A_</S><S S="Error">+ ... lyContinue';Import-Certificate -Filepath C:\vagrant\Microcosm.cer -Ce ..._x000D__x000A_</S><S
S="Error">+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S><S S="Error"> + CategoryInfo : InvalidArgument: (:) [Import-Certificate], P
arameterBindingException_x000D__x000A_</S><S S="Error"> + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.CertificateServices.Commands.ImportCertificateComm _x000D__x000A_</
S><S S="Error"> and_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>
Cert:\Local Computer\TrustedDevices has a space in it. Try this with escaped quotes around your path:
vagrant.exe powershell -c "Import-Certificate -Filepath C:\vagrant\Microcosm.cer -CertStoreLocation `"Cert:\Local Computer\TrustedDevices`""

PowerShell windows 2008 missing modules

I apologize if this is a NOOB question but I wrote a PowerShell script on my windows 10 box and I am trying to run the script on a 2008 box. On the new install of the 2008 box I had to add the windows powershell feature. My end goal is to install the Web Server (IIS) Administration Cmdlets
PS C:\Users\Administrator> Get-Module -ListAvailable | Import-Module
PS C:\Users\Administrator> Get-Module -ListAvailable
ModuleType Name ExportedCommands
---------- ---- ----------------
Manifest BitsTransfer {}
Manifest PSDiagnostics {Enable-PSTrace, Enable-WSManTrace, Start-Trace, Disable-PSWSManCombined...
PS C:\Users\Administrator>
PS C:\Users\Administrator> add-pssnapin WebAdministration
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2.
At line:1 char:13
+ add-pssnapin <<<< WebAdministration
+ CategoryInfo : InvalidArgument: (WebAdministration:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
PS C:\Users\Administrator>
PS C:\Users\Administrator> Import-Module WebAdministration
Import-Module : The specified module 'WebAdministration' was not loaded because no valid module file was found in any module directory.
At line:1 char:14
+ Import-Module <<<< WebAdministration
+ CategoryInfo : ResourceUnavailable: (WebAdministration:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId :Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Any ideas?
You need to install the IIS managment tools before the WebAdministration-module is available. Try (tested on Win10):
Enable-WindowsOptionalFeature -Online -FeatureName "IIS-WebServerManagementTools" -All
Windows Server 2008 doesn't come with a PowerShell module for managing IIS. That feature was added with Windows Server 2008 R2. You need to download and install it first. See here for further information. See also this related question.

Powershell DSC xChrome Sample failing on AzureVM

I'm attempting to run the xChrome sample (https://gallery.technet.microsoft.com/scriptcenter/DSC-Resource-Kit-All-c449312d) on an Azure VM and it fails to run. Everything runs and executes, but I receive the error (larger log snippet below):
CategoryInfo : ObjectNotFound: (MSFT_xChrome\MSFT_xChrome:String) [Configuration]
AzureVM is Windows Server 2012 with Powershell Version 5:
$PSVersionTable.PSVersion
Major Minor Build Revision
5 0 9883 0
The steps I use to execute are:
Download xChrome extension (from above url) and inflate it into my modules directory
Publish-AzureVMDscConfiguration -ConfigurationPath
C:\Users\Documents\WindowsPowerShell\Modules\xChrome\Example\Sample_xChrome.ps1
-Force
Get-AzureVM -ServiceName '' -Name '' |
Set-AzureVMDscExtension -ConfigurationArchive Sample_xChrome.ps1.zip
-ConfigurationName Sample_InstallChromeBrowser -ConfigurationArgument #{Language='en';LocalPath='$env:SystemDrive\Windows\DtlDownloads\GoogleChromeStandaloneEnterprise.msi'} | Update-AzureVM
**The error snippet:*
[2015-04-17T23:35:06] Executing the configuration function to generate the MOF files.
PSDesiredStateConfiguration\Configuration : The module 'MSFT_xChrome' could not be loaded. For more information, run 'Import-Module MSFT_xChrome'.
At C:\Packages\Plugins\Microsoft.Powershell.DSC\1.7.0.0\DSCWork\Sample_xChrome.ps1.8\Sample_xChrome.ps1:3 char:1
Configuration Sample_InstallChromeBrowser
~~~~~~~~~~~~~
CategoryInfo : ObjectNotFound: (MSFT_xChrome\MSFT_xChrome:String) [Configuration], ParentContainsErrorRecordException
FullyQualifiedErrorId : CouldNotAutoLoadModule,Configuration
[2015-04-17T23:35:08] Removing file lock
C:\Packages\Plugins\Microsoft.Powershell.DSC\1.7.0.0\bin\DscExtensionHandler.ps1 : Error enabling the DSC Extension: Errors occurred while processing configuration 'Sample_InstallChromeBrowser'.
At line:7 char:2
+ C:\Packages\Plugins\Microsoft.Powershell.DSC\1.7.0.0\bin\DscExtensio ...
I fixed this error by changing how I was importing the module.
Import-DscResource -ModuleName xChrome -Name MSFT_xChrome
The error implies that a module could not be loaded. Can you connect to the VM using remote desktop and check if Get-DscResource -Module xChrome lists the resource correctly