PowerShell添加窗口功能无法识别

PowerShell添加窗口功能无法识别,powershell,powershell-3.0,windows-server-2012,Powershell,Powershell 3.0,Windows Server 2012,首先感谢您审阅此文档 我基本上有一个第三方代理软件,它允许我以LocalSystem的形式执行PowerShell。这使我能够在没有WinRM等的情况下轻松运行远程PowerShell命令 我遇到的问题是,在某些服务器上,我无法执行get-WindowsFeature或Add-WindowsFeature 我试图实现这一目标的示例如下: Import-Module ServerManager; Get-WindowsFeature; 输出如下: The term 'Get-WindowsFea

首先感谢您审阅此文档

我基本上有一个第三方代理软件,它允许我以LocalSystem的形式执行PowerShell。这使我能够在没有WinRM等的情况下轻松运行远程PowerShell命令

我遇到的问题是,在某些服务器上,我无法执行get-WindowsFeature或Add-WindowsFeature

我试图实现这一目标的示例如下:

Import-Module ServerManager;
Get-WindowsFeature;
输出如下:

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.
如果我在PowerShell窗口中键入相同的命令,或直接调用PowerShell.exe,它将返回。我正试图找出我们在应用程序中做得不好的地方,但我是这里最熟悉PowerShell的人

是否需要执行一些特殊操作来加载这些cmdlet?奇怪的是,Get模块没有显示任何内容

谢谢大家!


针对JBSmith:

Yessir-看起来像2.0。下面是您提到的命令的结果

>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

我还注意到GCM |?{$\.ModuleName-eq'ServerManager}在那里运行时不返回任何内容,但通过正常的PS窗口,它会按预期返回命令列表。

这可能是因为PowerShell脚本是从PowerShell的32位实例启动的。ServerManager命令仅在64位版本的PowerShell中可用。见:

--编辑-添加到jbsmith的评论中---

额外的尝试:

运行Get命令cmdlt时:

gcm | ? { $_.ModuleName -eq 'ServerManager' }
它将不返回任何内容,因为ServerManager模块尚未加载

试着运行这个。它将列出要加载的所有可用模块:

Get-Module -ListAvailable | ? { $_.Name -eq 'ServerManager' }
另一种尝试是使用“强制”选项(重新导入模块及其成员,即使模块或其成员的访问模式为只读):


最后的问题是,这些服务器上ServerManager的元数据是3.0,而开发的用于调用PowerShell命令的exe只有2.0版。当它尝试导入模块时,返回了关于元数据的模式错误,但是EXE没有将它们重定向到stdout,因此没有响应

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
导入模块:“C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ServerM” 无法导入anager\ServerManager.psd1模块,因为其清单包含 插入一个或多个无效的成员。有效的清单成员为('Mo duleToProcess“,”嵌套模块“,”GUID“,”作者“,”公司名称“,”版权“, 'ModuleVersion','Description','PowerShellVersion','PowerShellHostName','Pow erShellHostVersion、CLRVersion、DotNetFrameworkVersion、ProcessorArchitec “真”、“RequiredModules”、“TypeStopProcess”、“FormatStopProcess”、“ScriptsToProce” ss、PrivateData、RequiredAssembly、ModuleList、FileList、FunctionsT oExport“,”VariablesToExport“,”别名sToExport“,”CmdletsToExport“)。删除th 删除无效的成员('HelpInfoUri','RootModule'),然后尝试导入 再次打开模块。 第1行字符:14
+在Windows Server 2016上导入模块,在安装ADFS作为解决方法时,我将C:\Windows\system32\WindowsPowerShell\v1.0\Modules文件夹复制到C:\Users\vagrant\Documents\WindowsPowerShell\Modules,结果成功了

尝试“获取模块-列表可用”;这将向您显示ServerManager模块可用。您可以通过运行“导入模块ServerManager”来加载*-WindowsFeature cmdlet。在PS版本3中,所需的模块是自动加载的,但在版本2中,在这些cmdlet可用之前,必须手动导入模块。也许您的第三方代理正在运行powershell版本2?(请尝试$psversiontable查看)。根据开发人员的说法,它运行的是64位。当我试着运行下面的代码时,结果是空的<代码>导入模块ServerManager;get module此外,此命令返回,指示它正在运行64位:
[System.Runtime.InterOpServices.Marshal]::SizeOf([System.IntPtr])返回8
确定。有关尝试运行
Get Module-ListAvailable |的编辑,请参见上面的答案?{$\ Name-eq'ServerManager'}
insteadFor Windows 10我必须按照以下关于服务器故障的回答安装“Windows 10远程服务器管理工具”:
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