我試圖使用powershell來配置帳戶憑據,但我需要授予帳戶「作爲服務登錄」才能使其正常工作。我如何在PowerShell中做到這一點?使用powershell,我如何授予「登錄爲服務」帳戶?
回答
以下是您可以在PSH中執行的鏈接。 http://www.derkeiler.com/Newsgroups/microsoft.public.windowsxp.security_admin/2003-12/2865.html。
問題是沒有真正的公共API來管理這些設置,因此使用ResKits中提供的命令行工具有點困難。
謝謝。我結束了使用ntrights來做到這一點。 ntrights.exe + r SeServiceLogonRight -u <用戶名/組名> http://support.microsoft.com/?kbid=279664 – 2009-01-06 02:53:19
PowerShell沒有這樣做的本地方法,這意味着您可能會在看WMI或ADSI - 您更可能在VBScript中找到示例,儘管它本身已經更長不要以爲我已經想出瞭如何以編程方式分配用戶權限。儘管如此,這並不意味着它無法完成,但您可能會專注於PowerShell領域之外。
PowerShell腳本下面將授予SeServiceLogonRight通過COMPUTERNAME指定爲以用戶名指定的用戶的主機上(該腳本是從這裏的摘錄:https://gist.github.com/grenade/8519655):
<#
.Synopsis
Grant logon as a service right to the defined user.
.Parameter computerName
Defines the name of the computer where the user right should be granted.
Default is the local computer on which the script is run.
.Parameter username
Defines the username under which the service should run.
Use the form: domain\username.
Default is the user under which the script is run.
.Example
Usage:
.\GrantSeServiceLogonRight.ps1 -computerName hostname.domain.com -username "domain\username"
#>
param(
[string] $computerName = ("{0}.{1}" -f $env:COMPUTERNAME.ToLower(), $env:USERDNSDOMAIN.ToLower()),
[string] $username = ("{0}\{1}" -f $env:USERDOMAIN, $env:USERNAME)
)
Invoke-Command -ComputerName $computerName -Script {
param([string] $username)
$tempPath = [System.IO.Path]::GetTempPath()
$import = Join-Path -Path $tempPath -ChildPath "import.inf"
if(Test-Path $import) { Remove-Item -Path $import -Force }
$export = Join-Path -Path $tempPath -ChildPath "export.inf"
if(Test-Path $export) { Remove-Item -Path $export -Force }
$secedt = Join-Path -Path $tempPath -ChildPath "secedt.sdb"
if(Test-Path $secedt) { Remove-Item -Path $secedt -Force }
try {
Write-Host ("Granting SeServiceLogonRight to user account: {0} on host: {1}." -f $username, $computerName)
$sid = ((New-Object System.Security.Principal.NTAccount($username)).Translate([System.Security.Principal.SecurityIdentifier])).Value
secedit /export /cfg $export
$sids = (Select-String $export -Pattern "SeServiceLogonRight").Line
foreach ($line in @("[Unicode]", "Unicode=yes", "[System Access]", "[Event Audit]", "[Registry Values]", "[Version]", "signature=`"`$CHICAGO$`"", "Revision=1", "[Profile Description]", "Description=GrantLogOnAsAService security template", "[Privilege Rights]", "SeServiceLogonRight = *$sids,*$sid")){
Add-Content $import $line
}
secedit /import /db $secedt /cfg $import
secedit /configure /db $secedt
gpupdate /force
Remove-Item -Path $import -Force
Remove-Item -Path $export -Force
Remove-Item -Path $secedt -Force
} catch {
Write-Host ("Failed to grant SeServiceLogonRight to user account: {0} on host: {1}." -f $username, $computerName)
$error[0]
}
} -ArgumentList $username
這就是我解決它的方法:
根據:this article
可以按如下方式下載Carbon from here
首次進口碳模塊:
Import-Module -Name $Path_To_Carbon -Global -Prefix CA
[array]$UserPrivileges = Get-CAPrivileges -Identity $UserName;
[bool]$LogOnAsAServiceprivilegeFound = $false;
if ($UserPrivileges.Length > 0)
{
if ($UserPrivileges -contains "SeServiceLogonRight")
{
$LogOnAsAServiceprivilegeFound = $true;
}
}
if ($LogOnAsAServiceprivilegeFound -eq $false)
{
Grant-CAPrivilege -Identity $UserName "SeServiceLogonRight"
}
- 1. c#授予Windows用戶「登錄爲服務」權限
- 2. 當用戶登錄時授予授權
- 3. C#。如何以編程方式授予用戶作爲服務登錄
- 4. 授予Google服務帳戶訪問我所有的Google Analytics帳戶的權限
- 5. 授予ASP.NET網絡服務帳戶訪問Azman
- 6. 授予域範圍內的機關服務帳戶
- 7. 如何使用Powershell授予用戶註冊表項的權限?
- 8. 驗證服務帳戶Powershell
- 9. 從PowerShell向用戶授予SeServiceLogonRight
- 10. 授予來賓訪問服務器基於密鑰SSH登錄
- 11. 如何授予用戶帳戶訪問GCE雲存儲
- 12. 使用Google帳戶登錄
- 13. 我如何「授予創建用戶」作爲非root用戶?
- 14. 訪問谷歌我的業務API沒有登錄(使用服務帳戶)
- 15. Facebook的API:用戶登錄,但沒有授予任何權限
- 16. 查找其帳戶的服務被設置爲「登錄爲」
- 17. 如何使用Twitter帳戶登錄我的iPhone應用程序?
- 18. 用戶「服務帳戶名稱」的SQL異常登錄失敗
- 19. 火力地堡工具:登錄爲服務帳戶
- 20. 授予用戶授予其他用戶的授權
- 21. ANDROID - 創造用戶/帳戶的服務器/服務的登錄權限
- 22. 如何禁用帳戶的ssh登錄?
- 23. 在SQL Server中創建用戶,登錄名和授予權限
- 24. 授予非root用戶訪問權登錄到phpMyAdmin
- 25. Google Fit用戶登錄授予訪問永遠不會通過
- 26. 如何使用服務帳戶使用PHP訪問我的Google通訊錄?
- 27. 如何爲用戶授予遠程訪問mysql服務器的權限?
- 28. 如何用戶在我的網站的twitter帳戶登錄
- 29. C#如何禁用本地用戶帳戶的交互式登錄。類似於網絡服務帳戶
- 30. 如何使用Powershell列出服務器中使用服務帳戶運行的所有服務
我試圖做同樣的,在Windows Server 2008 R2的x64 * *的核心,它不出貨與ntrights.exe(在答案的鏈接文章中提到的工具)。還有什麼幫助? – 2012-01-06 16:40:45
另一個選項在這裏:https://code.msdn.microsoft.com/windowsapps/Add-log-on-as-a-service-a64dd63c – Rory 2015-12-07 15:50:27