我已經編寫了下面的代碼,以通過域憑據在遠程系統中創建文件。 當我執行此代碼時,我得到權限被拒絕的錯誤。Azure powershell在遠程系統中創建文件時,權限被拒絕錯誤
代碼:
$username = "domain\username"
$password = "Welcome1234$"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
Invoke-Command -Credential $cred -Computer VM1{
New-Item \\VM2\sapmnt\SID\SYS\profile\test.txt -ItemType file
}
錯誤:
Access to the path '\\VM2\sapmnt\SID\SYS\profile\test.txt' is denied.
+ CategoryInfo : PermissionDenied: (\\VM2\s...rofile\test.txt:String) [New-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : NewItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand
您可以使用該帳戶訪問'\\ VM2 \ sapmnt \ SID \ SYS \ profile'嗎?該帳戶是否有權限(讀/寫)? –