gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:53:09 29 4
gpt4 key购买 nike

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

$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 acmdlet, function, script file, or operable program. Check the spelling of thename, 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com