Power Shell 스크립트를 사용하여 AS 배치 로그온 부여 - Windows Server 2016에서 수동으로 실행하면 제대로 작동하지만 oneops에서 트리거되면 실패합니다.

Power Shell 스크립트를 사용하여 AS 배치 로그온 부여 - Windows Server 2016에서 수동으로 실행하면 제대로 작동하지만 oneops에서 트리거되면 실패합니다.

tmp11.inf를 생성하지만 사용자 권한을 tmp11.inf 0kb로 내보내지 않습니다. tmp11.inf가 비어 있으므로 $currentConfig = Get-Content -Path $tempConfigFile에서 스크립트가 실패합니다.

  1. 관리자 권한으로 실행하기 위해 아래 줄을 추가했지만 여전히 동일한 문제가 발생합니다.

Start-Process -FilePath "powershell" -ArgumentList "$('-File ""')$(Get-Location)$('\')$($MyInvocation.MyCommand.Name)$('""')" -Verb runAs**

2) OneOps execution both failed same issue,
   Method 1. ```powershell.exe -file E:\apps-packages\GrantLogonRights.ps1```
   Method 2. ```PowerShell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process PowerShell -ArgumentList '-ExecutionPolicy Unrestricted','-File E:\apps-packages\GrantLogonRights.ps1' -Verb RunAs" ```

$username = "domain\account"

$rightBatch = "SeBatchLogonRight"

$tempConfigFile = "C:\Users\admin\AppData\Local\Temp\tmp11.inf"

$tempDbFile = "C:\Users\admin\AppData\Local\Temp\tmp11.sdb"

secedit /export /cfg $tempConfigFile /areas USER_RIGHTS 

$currentConfig = Get-Content -Path $tempConfigFile

$sid = ((New-Object System.Security.Principal.NTAccount($username)).Translate([System.Security.Principal.SecurityIdentifier])).Value

    $newConfig = $currentConfig -replace "^$right .+", "`$0,*$sid"
    Set-Content -Path $tempConfigFile -Encoding ascii -Value $newConfig
    secedit /import /cfg $tempConfigFile /db $tempDbFile
    secedit /configure /db $tempDbFile /cfg $tempConfigFile /areas USER_RIGHTS
    gpupdate /force

관련 정보