當我使用 AddAccessRule 時,我的腳本中出現此錯誤:
例外設定“AddAccessRule”:“無法設定型別為“System.Management.Automation.PSMethod”的 PSMemberInfo 物件的 Value 屬性。
我研究了很多類似的腳本,但我沒有運氣搜索這個錯誤。任何幫助將不勝感激!謝謝!
腳本如下:
'''
$folders = get-childitem -path "C:\Users\spewingadmin\Documents\reports_bak2\" -Recurse
Foreach($folder in $folders){
$foldacl = get-acl -Path $folder.FullName
$InheritanceFlag = $foldacl.Access.InheritanceFlags
$PropagationFlag = $foldacl.Access.PropagationFlags
$objType = $foldacl.Access.AccessControlType
$Permissions = $foldacl.Access.FileSystemRights
For ($x=0;$x -lt $foldacl.Access.Count;$x ){
$user = $foldacl.Access.IdentityReference[$x]
$domainresult = $user.Value.substring(0,($user.Value.indexof("\")))
If(($domainresult -eq "WORKGROUP")) {
$username = $user.Value.substring((($user.Value.indexof("\")) 1),($user.Value.length - $user.Value.indexof("\") - 1))
$DomainUser = "NEWWORKGROUP\" $username
$NewPerms = ($domainuser,$Permissions,$InheritanceFlag,$PropagationFlag,$objType)
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList $NewPerms
$Ar
$foldacl.SetAccessRule=($Ar)
}
}
##Set-acl -Path $folder.FullName -AclObject $foldacl
##$foldacl
}
'''
uj5u.com熱心網友回復:
是的,您可以毫無問題地回傳一個字串,但是設定它非常挑剔。如果不查看引數、腳本、變數等,很難判斷發生了什么。
powershell 腳本本身是否設定為輸出字串?仔細檢查 PowerShellVariables 彈出視窗中的名稱是否正確,方向是否設定為正確out,型別是否string正確,并且您正在將值設定為正確的 UiPath 變數
uj5u.com熱心網友回復:
透輝石在對該問題的評論中提供了關鍵指標:
正如您所確認的,您在以下方法呼叫嘗試中遇到了無關緊要=的問題,洗掉它可以解決您的問題:
# Note the extraneous "="
$foldacl.SetAccessRule=($Ar) # !! WRONG
應該:
# OK - syntactically correct method call.
$foldacl.SetAccessRule($Ar)
因此,您的問題符合標準原因“不可重現或由拼寫錯誤引起”的關閉條件。
不過,考慮到有些錯誤資訊的晦澀本質- Cannot set the Value property for PSMemberInfo object of type "System.Management.Automation.PSMethod".-也許是一個解釋是有幫助的:
- PowerShell 允許您通過簡單地省略來獲取 .NET 方法的簽名 (多載)
(...),它回傳一個或多個System.Management.Automation.PSMethod實體:
PS> 'foo'.ToString # Note: *No* () to actually *call* the .ToString() method.
OverloadDefinitions
-------------------
string ToString()
string ToString(System.IFormatProvider provider)
string IConvertible.ToString(System.IFormatProvider provider)
- 嘗試分配給這樣的方法簽名物件(組) - 這沒有任何意義 - 然后導致上述錯誤訊息:
PS> 'foo'.ToString = 'whatever' # !! Predictably fails.
[...] Exception setting "ToString": "Cannot set the Value property for PSMemberInfo object [...]"
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/345241.html
