$func = { #Add to Local Security Policy function Add-ServiceLogonRight([string] $Username) { Write-Host "Enable ServiceLogonRight for $Username" $tmp = New-TemporaryFile secedit /export /cfg "$tmp.inf" | Out-Null (Get-Content -Encoding ascii "$tmp.inf") -replace '^SeServiceLogonRight .+', "`$0,$Username" | sc -Encoding ascii "$tmp.inf" secedit /import /cfg "$tmp.inf" /db "$tmp.sdb" | Out-Null secedit /configure /db "$tmp.sdb" /cfg "$tmp.inf" | Out-Null Remove-Item $tmp* -ea 0 } Add-ServiceLogonRight -Username svccohesityadm # Set Service to Run as Service Account Stop-Service -Name CohesityAgent sc.exe config "CohesityAgent" obj="NDGOV\svccohesityadm" password="memo-fUpHMMgXnv" Start-Service -Name CohesityAgent # Add to Local Administrators group Add-LocalGroupMember -Group Administrators -Member "ndgov\svccohesityadm" } Invoke-Command -ComputerName itddhssql19p1.nd.gov -Credential $PrvCred -ScriptBlock $func