gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:48:04 25 4
gpt4 key购买 nike

我有一个由第三方供应商创建的服务,每次安装此软件的实例时,我都必须手动进入并将登录帐户更改为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/

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