运行脚本时,我有一行来验证我们的应用程序的“服务帐户”(又名本地用户帐户)是否存在:
$svcAccountName = "TheAccountName"
$svcAccount = Get-LocalUser -Name $svcAccountName
服务器 (Windows Server 2008 R2) 在
Get-LocalUser
上犹豫不决。 cmdlet,说明:Get-LocalUser : The term 'Get-LocalUser' 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. At line:1 char:1 + Get-LocalUser + ~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-LocalUser:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
So I tried to import the LocalAccounts
module:
Import-Module Microsoft.Powershell.LocalAccounts
我得到了这个:
Import-Module:未加载指定的模块“LocalAccounts”,因为没有
在任何模块目录中都找到了有效的模块文件。
在行:1 字符:1
+ 导入模块
+ ~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (LocalAccounts:String)[Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
根据
$PSVersionTable
,服务器正在运行 PSVersion 4.0。多变的。为什么不是
LocalAccounts
模块加载和 Get-LocalUser
命令运行?我怎样才能解决这个问题?
最佳答案
Microsoft.Powershell.LocalAccounts 模块作为 Windows Management Framework (WMF) v5.1 的一部分提供,可从以下位置下载:https://www.microsoft.com/en-us/download/details.aspx?id=54616
安装后,您将能够在脚本中使用这些 cmdlet。
在这里,您还可以引用每个版本的 Powershell 包含哪些模块:https://msdn.microsoft.com/powershell/reference/readme
祝你好运! :)
关于powershell - 找不到 Microsoft.Powershell.LocalAccounts 模块(或运行 Get-LocalUser),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43989815/