![](/img/trans.png)
[英]How to run a Powershell script from the command line and pass a directory as a parameter
[英]Active Directory Powershell insufficient access inside of a script, but able to run the command from the command line
我似乎對活動目錄有一個奇怪的權限問題。 運行此腳本的用戶有權更改活動目錄屬性,並且能夠從命令行執行此操作,但無法在腳本內運行命令。
我試圖運行的命令是這樣的:
Set-ADUser -identity $user.DistinguishedName -replace @{info="1"}
此命令在 Powershell 命令行內運行並執行良好。 命令行也以運行腳本的用戶身份運行。 因此用戶擁有更改活動目錄屬性的權限。 但是,當我將此命令放入腳本時,出現權限問題。
在我的腳本內部,這是出現錯誤的塊:
try{
Set-ADUser -identity $user.DistinguishedName -replace @{info="1"}
Set-ADUser -identity $username -replace @{employeeID="<not set>"}
Logwrite "Employee ID: Cleared!"
}
catch{
#Update Log Of Error
$errorcountforemail = $errorcountforemail + 1
logwrite "Employee ID:******* [FAILED] *******"
$errortest = $_
Write-Output $_
Out-File -FilePath $logfile2 -Append -InputObject "`n" -Encoding ascii -Width 50
Out-File -FilePath $logfile2 -Append -InputObject "Problem setting ad user for $username" -Encoding ascii -Width 50
Out-File -FilePath $logfile2 -Append -InputObject $_ -Encoding ascii -Width 50
Out-File -FilePath $logfile2 -Append -InputObject "`n" -Encoding ascii -Width 50
}
這是為保密而更改名稱的錯誤。
*---------------------* Errors for: ############## *---------------------*
Problem setting ad user for ################
Set-ADUser : Insufficient access rights to
perform the operation
At C:\##################.ps1:199 char:13
+ Set-ADUser -identity
$user.DistinguishedName -replace @{ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified:
(#########################:ADUser)
[Set-ADUse r], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServe
r:8344,Microsoft.ActiveDirectory.Management.Com
mands.SetADUser
我嘗試過的事情:
-以管理員身份運行並具有最高權限。
- 在以管理員身份運行的批處理文件中啟動腳本
- 強制使用這樣的憑據: Set-ADUser -identity $user.DistinguishedName -credentials $domaincredential -replace @{info="1"}
使用此用戶的憑據,因為它確實有權進行這些更改。
有什么想法嗎?
我的問題是禁用用戶 OU 的權限問題。我授予用戶編輯禁用用戶的權限,它現在按預期工作; 這不是我的代碼的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.