首先感谢您对此进行审核.
我基本上有一个第三方代理软件,它允许我作为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-Module没有显示任何内容.
谢谢!
回应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脚本是从32位PowerShell实例启动的.ServerManager命令仅适用于64位版本的PowerShell.请参阅:无法通过PowerShell访问ServerManager模块
- 编辑 - 添加到jbsmith的评论---
额外的事情要尝试:
运行Get-Command cmdlt时:
gcm | ? { $_.ModuleName -eq 'ServerManager' }
它将不返回任何内容,因为尚未加载ServerManager模块.
尝试运行它.它将列出要加载的所有可用模块:
Get-Module -ListAvailable | ? { $_.Name -eq 'ServerManager' }
另一件要尝试的是使用"强制"选项(重新导入模块及其成员,即使模块或其成员具有只读访问模式):
Import-Module ServerManager -Force; Get-WindowsFeature;