[英]Permission denied error while creating file in remote system by Azure powershell
I have written below code to create file in remote system by domain credentials. 我写了下面的代码来通过域凭据在远程系统中创建文件。 When i execute this code I get permission denied error.
当我执行此代码时,出现权限被拒绝错误。
Code: 码:
$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
}
error: 错误:
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
Can you use that account to access that path \\\\VM2\\sapmnt\\SID\\SYS\\profile
? 您可以使用该帐户访问该路径
\\\\VM2\\sapmnt\\SID\\SYS\\profile
吗? Do you have permission to read or write ? 你有权读或写 ?
I had test in my lab, it works for me. 我在实验室进行了测试,它对我有用。
Grant permission (Read/Write)to that account: 向该帐户授予权限(读/写):
Here is the script: 这是脚本:
$username = 'jason'
$pass = ConvertTo-SecureString -string 'password' -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $pass
$s = New-PSSession -ConnectionUri 'http://13.73.23.129:5985' -Credential $cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
Invoke-Command -Session $s -ScriptBlock {new-item \\jasonvm\profile\jasontest3.txt}
Update : 更新 :
changing the ip-address
to HOSTNAME
resolve this issue: 将
ip-address
更改为HOSTNAME
可解决此问题:
$username = 'jason'
$pass = ConvertTo-SecureString -string 'password' -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $pass
$s = New-PSSession -ConnectionUri 'VM2hostname:5985'; -Credential $cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
Invoke-Command -Session $s -ScriptBlock {new-item \\jasonvm\profile\jasontest3.txt}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.