PowerShell Add-WindowsFeature unrecognized
Asked Answered
S

7

37

Thanks first of all for reviewing this.

I've basically got a third-party agent software which allows me to execute PowerShell as LocalSystem. This allows me to easily run remote PowerShell commands without WinRM etc.

The problem that i'm running into is that on some servers i'm not able to perform get-WindowsFeature or Add-WindowsFeature.

An example of how i'm trying to achieve this is here:

Import-Module ServerManager;
Get-WindowsFeature;

The output is as such:

The term 'Get-WindowsFeature' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

If I type those same commands into a PowerShell window, or call PowerShell.exe directly, it returns. I'm trying to figure out what we're not doing right within the application, but i'm the most familiar person with PowerShell here.

Is there something special I need to do to load those cmdlets? Get-Module doesn't show anything, oddly.

Thank you!


In response to JBSmith:

Yessir - looks like 2.0. Here are the results of the commands you mentioned

>Name                           Value                                            
>----                           -----                                            
>CLRVersion                     2.0.50727.6407                                   
>BuildVersion                   6.1.7600.16385                                   
>PSVersion                      2.0                                              
>WSManStackVersion              2.0                                              
>PSCompatibleVersions           {1.0, 2.0}                                       
>SerializationVersion           1.1.0.1                                          
>PSRemotingProtocolVersion      2.1                                              
>
>Name : AppLocker
>Name : Appx
>Name : BestPractices
>Name : BitsTransfer
>Name : BranchCache
>Name : CimCmdlets
>Name : DirectAccessClientComponents
>Name : Dism
>Name : DnsClient
>Name : International
>Name : iSCSI
>Name : IscsiTarget
>Name : ISE
>Name : Kds
>Name : Microsoft.PowerShell.Diagnostics
>Name : Microsoft.PowerShell.Host
>Name : Microsoft.PowerShell.Management
>Name : Microsoft.PowerShell.Security
>Name : Microsoft.PowerShell.Utility
>Name : Microsoft.WSMan.Management
>Name : MMAgent
>Name : MsDtc
>Name : NetAdapter
>Name : NetConnection
>Name : NetLbfo
>Name : NetQos
>Name : NetSecurity
>Name : NetSwitchTeam
>Name : NetTCPIP
>Name : NetworkConnectivityStatus
>Name : NetworkTransition
>Name : MSFT_NfsMappedIdentity
>Name : NFS
>Name : PKI
>Name : PrintManagement
>Name : PSDiagnostics
>Name : PSScheduledJob
>Name : PSWorkflow
>Name : PSWorkflowUtility
>Name : RemoteDesktop
>Name : ScheduledTasks
>Name : SecureBoot
>Name : ServerCore
>Name : ServerManager
>Name : ServerManagerTasks
>Name : SmbShare
>Name : SmbWitness
>Name : Storage
>Name : TroubleshootingPack
>Name : TrustedPlatformModule
>Name : UserAccessLogging
>Name : VpnClient
>Name : Wdac
>Name : Whea
>Name : WindowsDeveloperLicense
>Name : WindowsErrorReporting
>Name : AWSPowerShell

I also noticed that GCM | ? { $_.ModuleName -eq 'ServerManager' } returns nothing when I run it through there, but through a normal PS window it returns a command list as expected.

Species answered 19/12, 2013 at 16:5 Comment(1)
Try 'Get-Module -ListAvailable' instead; that should show you that the ServerManager module is available. You can load the *-WindowsFeature cmdlets by running 'Import-Module ServerManager'. In PS version 3, needed modules are auto-loaded, but in version 2 you have to import the modules manually before those cmdlets are available. Maybe your 3rd party agent is running powershell version 2? (Try $psversiontable to see).Fotina
S
2

Issue ended up being that the metadata for ServerManager was 3.0 on these servers, yet the developed exe for calling PowerShell commands was only version 2.0. When it tried to import the modules, schema errors about the metadata were returned, but the EXE didn't redirect them to stdout, hence no response.

Import-Module : The 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Serveranager\ServerManager.psd1' module cannot be imported because its manifest contins one or more members that are not valid. The valid manifest members are ('ModuleToProcess', 'NestedModules', 'GUID', 'Author', 'CompanyName', 'Copyright', 'ModuleVersion', 'Description', 'PowerShellVersion', 'PowerShellHostName', 'PowerShellHostVersion', 'CLRVersion', 'DotNetFrameworkVersion', 'ProcessorArchitecture', 'RequiredModules', 'TypesToProcess', 'FormatsToProcess', 'ScriptsToProcess', 'PrivateData', 'RequiredAssemblies', 'ModuleList', 'FileList', 'FunctionsToExport', 'VariablesToExport', 'AliasesToExport', 'CmdletsToExport'). Remove the members that are not valid ('HelpInfoUri', 'RootModule'), then try to importthe module again.
    At line:1 char:14
    + Import-Module <<<<  ServerManager; Get-Module
        + CategoryInfo          : InvalidData: (C:\Windows\syst...verManager.psd1:String) [Import-Module], InvalidOperationException
        + FullyQualifiedErrorId : Modules_InvalidManifestMember,Microsoft.PowerShell.Commands.ImportModuleCommand
Species answered 3/1, 2014 at 19:44 Comment(0)
T
23

This is probably because the PowerShell script is being launched from a 32 bit instance of PowerShell. The ServerManager commands are only available from 64 bit version of PowerShell. See: Can't access ServerManager module via PowerShell

--Edit - To add to jbsmith's comments---

Extra things to try:

When you ran the Get-Command cmdlt:

gcm | ? { $_.ModuleName -eq 'ServerManager' }

It will return nothing because the ServerManager module has not been loaded.

Try running this instead. It will list all available modules to load:

Get-Module -ListAvailable | ? { $_.Name -eq 'ServerManager' }

The other thing to try is to use the "Force" option (Re-imports a module and its members, even if the module or its members have an access mode of read-only):

Import-Module ServerManager -Force;
Get-WindowsFeature;
Tart answered 19/12, 2013 at 19:23 Comment(4)
According to the developers, it's running 64-bit. When I tried running the following code, it just came back blank. import-module ServerManager; get-module Also, this command came back indicating it is running 64-bit bit: [System.Runtime.InterOpServices.Marshal]::SizeOf([System.IntPtr]) returned 8Species
Ok. See answer above for edits to try running Get-Module -ListAvailable | ? { $_.Name -eq 'ServerManager' } insteadTart
For Windows 10 I had to install "Remote Server Administration Tools for Windows 10" as per this answer on Server Fault: serverfault.com/a/831836/420795Indohittite
@Tart The ServerManager module is not found : Import-Module : The specified module 'ServerManager' was not loaded because no valid module file was found in any module directory. I need the ServerManager module to use Add-WindowsFeature to install the RSAT tools for W10 but this answer says the ServerManager module is now installed by the RSAT tools ! I feel like Microsoft is laughing at me :(.Temper
E
9

Get-WindowsFeature is no longer shipped with Windows or Windows Server and must be installed separately by installing the Windows Server Remote Administration Tools.

Here is the download link, this has downloads for Client and Server OS, so just chose the right package for your OS.

https://www.microsoft.com/en-us/download/details.aspx?id=45520

Exalt answered 13/9, 2021 at 12:49 Comment(1)
Windows 11 information can be found in techcommunity.microsoft.com/t5/windows-11/…Whipstall
S
2

Issue ended up being that the metadata for ServerManager was 3.0 on these servers, yet the developed exe for calling PowerShell commands was only version 2.0. When it tried to import the modules, schema errors about the metadata were returned, but the EXE didn't redirect them to stdout, hence no response.

Import-Module : The 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Serveranager\ServerManager.psd1' module cannot be imported because its manifest contins one or more members that are not valid. The valid manifest members are ('ModuleToProcess', 'NestedModules', 'GUID', 'Author', 'CompanyName', 'Copyright', 'ModuleVersion', 'Description', 'PowerShellVersion', 'PowerShellHostName', 'PowerShellHostVersion', 'CLRVersion', 'DotNetFrameworkVersion', 'ProcessorArchitecture', 'RequiredModules', 'TypesToProcess', 'FormatsToProcess', 'ScriptsToProcess', 'PrivateData', 'RequiredAssemblies', 'ModuleList', 'FileList', 'FunctionsToExport', 'VariablesToExport', 'AliasesToExport', 'CmdletsToExport'). Remove the members that are not valid ('HelpInfoUri', 'RootModule'), then try to importthe module again.
    At line:1 char:14
    + Import-Module <<<<  ServerManager; Get-Module
        + CategoryInfo          : InvalidData: (C:\Windows\syst...verManager.psd1:String) [Import-Module], InvalidOperationException
        + FullyQualifiedErrorId : Modules_InvalidManifestMember,Microsoft.PowerShell.Commands.ImportModuleCommand
Species answered 3/1, 2014 at 19:44 Comment(0)
H
1

On Windows Server 2016, while installing ADFS as a workaround I copied the C:\Windows\system32\WindowsPowerShell\v1.0\Modules folders to C:\Users\vagrant\Documents\WindowsPowerShell\Modules and it worked!

Harmonia answered 20/5, 2020 at 14:34 Comment(0)
L
0

I had the same issue and my problem was that my PowerShell was running on 32 bit instead of 64 bit PowerShell

Running it on 64 bit PowerShell worked fine.

Linda answered 5/1, 2022 at 12:26 Comment(0)
F
0

This is probably because the PowerShell script is being launched from a 32 bit instance of PowerShell. The ServerManager commands are only available from the 64 bit version of PowerShell.

Fossa answered 10/3, 2022 at 9:41 Comment(0)
P
0

I ran into a similar problem (couldn't find or install the ServerManager module), and the problem ended up being that the installed version of PowerShell, while it was 64-bit, was PowerShell 6 Core, and the full PowerShell desktop version needed to be installed. Once I installed PowerShell 7.4.1 I was able to continue.

Prothrombin answered 26/2 at 22:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.