首先,感谢您对此进行回顾。
我基本上有一个第三方代理软件,它允许我以LocalSystem的形式执行LocalSystem。这使我可以轻松地运行远程PowerShell命令,而不需要WinRM等。
我遇到的问题是,在某些服务器上,我无法执行或。
我正在努力实现这一目标的一个例子是:
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:
是的,先生-看起来像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窗口,它会像预期的那样返回命令列表。
发布于 2014-01-03 19:44:23
问题是,这些服务器上的ServerManager元数据为3.0,而用于调用PowerShell命令的已开发的exe仅为2.0版本。当它试图导入模块时,会返回有关元数据的模式错误,但是EXE没有将它们重定向到stdout,因此没有响应。
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发布于 2013-12-19 19:23:32
这可能是因为PowerShell脚本是从PowerShell的32位实例启动的。ServerManager命令只能从PowerShell的64位版本中获得。请参阅:无法通过ServerManager访问PowerShell模块
-编辑-加上jbsmith的评论--
额外的尝试:
运行Get-Command cmdlt时:
gcm | ? { $_.ModuleName -eq 'ServerManager' }它将不返回任何内容,因为ServerManager模块尚未加载。
试着用这个代替。它将列出要加载的所有可用模块:
Get-Module -ListAvailable | ? { $_.Name -eq 'ServerManager' }要尝试的另一件事是使用"Force“选项(重新导入模块及其成员,即使模块或其成员具有只读的访问模式):
Import-Module ServerManager -Force;
Get-WindowsFeature;发布于 2020-05-20 14:34:56
在Windows 2016上,当安装ADFS作为解决方法时,我将C:\Windows\system32\WindowsPowerShell\v1.0\Modules文件夹复制到C:\Users\vagrant\Documents\WindowsPowerShell\Modules中,它工作了!
https://stackoverflow.com/questions/20686302
复制相似问题