Unable to run Get-WindowsOptionalFeature command on Windows 2012 R2 machine - powershell

Receive the following error message when I run the Get-WindowsOptionalFeature command.
PS C:\Windows\system32> Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol
Get-WindowsOptionalFeature : An error occured. No operation was performed.
Verify that DISM is installed properly in the image, and then try the operation again.
At line:1 char:1
+ Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-WindowsOptionalFeature], COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.GetWindowsOptionalFeatureCommand

Make sure your DISM is actually working with:
dism /online /Get-FeatureInfo /FeatureName:SMB1Protocol
Double-check that you have the correct version for your build of windows as well. Sometimes this can be caused if you have some other version of the WAIK installed for example:
gwmi win32_operatingsystem | fl *
caption : Microsoft Windows Server 2012 R2 Standard
BuildNumber : 9600
Version : 6.3.9600
dism /online /get-feature
Deployment Image Servicing and Management tool
Version: 6.3.9600.19408 # Version of dism
Image Version: 6.3.9600.19397 # Version of windows

Related

Multicast MSMQ inside Docker Windows Container

We have a legacy windows project, that we would like to containerize.
This uses MSMQ multicasting (part of Telerik's obsolete ORM).
Inside my Windows Container, If I attempt
Enable-WindowsOptionalFeature -Oneline -FeatureName MSMQ-Multicast -All
This fails:
Enable-WindowsOptionalFeature : One or several parent features are disabled so current feature can not be enabled.
At line:1 char:1
+ Enable-WindowsOptionalFeature -Online -FeatureName MSMQ-Multicast -Al ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand
Also:
PS C:\scripts> netcfg -c p -i ms_rmcast
Trying to install ms_rmcast ...
... failed. Error code: 0x800106d9.
The container is connected via a 'transparent' network type, so is bridged to the local network.
Is there any solution to this, or is this just not (yet) supported?
Is version 1809 likely to help?
Any other clever ideas?
MSMQ was added in 1803 SAC channel. It does not exist in LTSC channel.
https://blogs.technet.microsoft.com/virtualization/2018/07/25/hello-world-msmq-from-windows-containers/

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

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

Get-WindowsOptionalFeature Failing to Work

I'm playing around with IIS and Windows PowerShell, and based on this this Microsoft TechNet link I should be able to view all optional features for my OS with the PowerShell command:
PS C:\> Get-WindowsOptionalFeature –Online
When I try to use this command, I get this error message:
get-windowsoptionalfeature : An attempt was made to load a program with an incorrect format.
At line:1 char:1
+ get-windowsoptionalfeature -Online
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-WindowsOptionalFeature], COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.GetWindowsOptionalFeatureCommand
I've been reading around and most issues seem to be based on problems between 64-bit and 32-bit OS's, I've tried running it in both my standard PowerShell and PowerShell (x86), same error in both. Any ideas on why this is happening?
The Get-WindowsOptionalFeature cmdlet requires PowerShell 3.0.
This cmdlet must run with elevated rights. Right-click the Windows PowerShell 3.0 console while holding the CTRL key, and select Run As Administrator from the action menu (per: https://blogs.technet.microsoft.com/heyscriptingguy/2012/08/24/use-powershell-3-0-to-find-enabled-windows-8-features/).
The RSAT must be installed in order to use it. I don't think it has anything at all to do with 32-bit vs 64-bit.

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.

Install hyperv cmdlet on workstation

I have a script that starts new HyperV VM's on a remote server using powershell
New-VM
Get-VM
I want to run this script on my desktop, however I get the following error.
the term 'new-vm' is not recognized as the name of a cmdlet
I can't figure out how to install the new-vm cmdlet on my workstation
Get-WindowsFeature
the target of the specified cmdlet cannot be a windows client-based operating system
Install-windowsFeature hyperv-
the target of the specified cmdlet cannot be a windows client-based operating system
I am very new to powershell, and don't do much with windows.
How can I install the cmdlet New-VM on a Windows 8 machine?
Update
Also tried the following.
Enable-WindowsOptionalFeature -Online -FeatureName Hyper-V-Tools
Enable-WindowsOptionalFeature -Online -FeatureName Hyper-V-PowerShell
I see hyperv tools in the following command
Get-WindowsOptionalFeature -Online | sort state
Microsoft-Hyper-V
Microsoft-Hyper-V-Tools-All
Microsoft-Hyper-V-Management-Powershell
Update 2
I almost got it installed, but it gives this error:
PS C:\Windows\system32> Enable-WindowsOptionalFeature -online -FeatureName Microsoft-Hyper-V-Management-Powershell
Enable-WindowsOptionalFeature : One or several parent features are disabled so current feature can not be enabled.
At line:1 char:1
+ Enable-WindowsOptionalFeature -online -FeatureName Microsoft-Hyper-V-Management- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand
PS C:\Windows\system32>
Got it installed. The powershell cmdlet has parents that can be installed by adding -all.
Enable-WindowsOptionalFeature -online -FeatureName Microsoft-Hyper-V-Management-Powershell -all
You will need to reboot before the cmdlet is available.