powershell - 找不到 Microsoft.Powershell.LocalAccounts 模块(或运行 Get-LocalUser)

标签 powershell module windows-server-2008-r2

运行脚本时,我有一行来验证我们的应用程序的“服务帐户”(又名本地用户帐户)是否存在:

$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/

相关文章:

powershell - 如何确保脚本或模块依赖的所有模块都已显式导入?

dotnetnuke - 正如 DotNetNuke 文档中所建议的那样,从 UNC 共享运行 IIS Web 应用程序有什么不好?

powershell 脚本太慢(文件枚举)

javascript - Angular js分离到不同js文件中的不同模块

powershell - 通过powershell向Azure RM AD应用程序添加权限

perl - 为什么即使在安装模块后,我仍会收到 "Can' t 定位模块的可加载对象?

windows - 无法在 Windows Server 2008 R2 上启动 Apache

powershell - 术语 'Get-WebBinding' 未被识别为 cmdlet、函数、脚本文件或可操作程序的名称

Azure 开发运营 : How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline?

powershell - 控制台输出到Powershell中的电子邮件