powershell - 将Windows服务登录名设置为GMSA帐户

标签 powershell powershell-3.0

我有一个由第三方供应商创建的服务,每次安装此软件的实例时,我都必须手动进入并将登录帐户更改为GMSA帐户。
默认情况下,使用登录帐户作为本地系统创建此服务。当我运行下面的Powershell代码时,我得到的返回值为21,其中包含无效的参数:
'''

$ServiceObject  = get-wmiobject -Class Win32_Service -filter "Name='$ServiceName'"
$ServiceObject.StopService() | out-null

# Change logon as settings
$ServiceObject.Change($null,$null,$null,$null,$null,$null,$GMSAServiceAccount,$null,$null,$null,$null) 
$ServiceObject.StartService()
'''
我在测试中确实找到了是否以与GMSA相同域中的其他用户身份手动登录服务帐户。然后运行上面的脚本,它运行成功。我还缺少其他步骤吗?

最佳答案

我们使用这段代码为gMSA帐户配置服务:

$serviceName = 'myService' 
$ServiceObject = Get-WmiObject -Class Win32_Service -Filter "Name='$serviceName'" 
$ServiceObject.StopService() | out-null

# Change logon as settings
$ServiceObject.Change($null, $null, $null, $null, $null, $null, "$env:USERDOMAIN\$gMSA_Name$", $null, $null, $null, $null)
$ServiceObject.StartService()
确保gMSA帐户名后面有一个$。这表明它是一个gMSA帐户。

关于powershell - 将Windows服务登录名设置为GMSA帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64010900/

相关文章:

powershell - 如何使 Install-Module 也安装任何必需的模块?

powershell - 使用 PowerShell 格式化磁盘而不提示确认

powershell - 如何区分未设置参数与 $false、0、空字符串?

powershell - 在Powershell中无需内置Get-FileHash cmdlet即可获取校验和

json - 尝试使用Powershell将复杂的JSON转换为CSV

powershell - 如何从 PowerShell 模块导出变量

powershell - 将哈希表值属性导出到 CSV 文件

string - 如何在PowerShell函数中进行字符串替换?

powershell-3.0 - 从组对象中选择最大值