PowerShell Add-WindowsFeature Unrecognized

Thanks first of all for this.

I basically got third-party agent software that allows me to run PowerShell as LocalSystem. This allows me to easily run remote PowerShell commands without WinRM, etc.

The problem I am facing is that on some servers I cannot get-WindowsFeature or Add-WindowsFeature.

An example of how I am trying to achieve this is given below:

Import-Module ServerManager; Get-WindowsFeature; 

The output is the same:

 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 enter the same commands into the PowerShell window or call PowerShell.exe directly, it will return. I'm trying to understand what we are not doing within the application, but I'm the most familiar person with PowerShell here.

Is there anything special that needs to be done to load these cmdlets? Get-Module shows nothing, strange.

Thanks!


In response to JBSmith:

Yessir - Looks like 2.0. Below 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 there, but through a regular PS window it returns a list of commands as expected.

+7
powershell windows-server-2012
source share
2 answers

The problem ended up with the metadata for ServerManager being 3.0 on these servers, but the exe designed to invoke PowerShell commands was only version 2.0. When he tried to import modules, metadata schema errors were returned, but the EXE did not redirect them to stdout, therefore, there was no answer.

 Import-Module : The 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ServerM anager\ServerManager.psd1' module cannot be imported because its manifest conta ins one or more members that are not valid. The valid manifest members are ('Mo duleToProcess', 'NestedModules', 'GUID', 'Author', 'CompanyName', 'Copyright', 'ModuleVersion', 'Description', 'PowerShellVersion', 'PowerShellHostName', 'Pow erShellHostVersion', 'CLRVersion', 'DotNetFrameworkVersion', 'ProcessorArchitec ture', 'RequiredModules', 'TypesToProcess', 'FormatsToProcess', 'ScriptsToProce ss', 'PrivateData', 'RequiredAssemblies', 'ModuleList', 'FileList', 'FunctionsT oExport', 'VariablesToExport', 'AliasesToExport', 'CmdletsToExport'). Remove th e members that are not valid ('HelpInfoUri', 'RootModule'), then try to import the 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.PowerShe ll.Commands.ImportModuleCommand 
-one
source share

Perhaps this is because the PowerShell script runs from a 32-bit PowerShell instance. ServerManager commands are available only from the 64-bit version of PowerShell. See: Unable to access ServerManager module through PowerShell

- Edit - Add jbsmith comments ---

Additional things to try:

When you started Get-Command cmdlt:

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

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

Try running this. It will list all available modules for download:

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

Another thing is to use the Strength parameter (Re-import module and its members, even if the module or its members have read-only access mode):

 Import-Module ServerManager -Force; Get-WindowsFeature; 
+5
source share

All Articles