简体   繁体   English

Azure Powershell在远程系统中创建文件时权限被拒绝错误

[英]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.

相关问题 在 SYSTEM 上下文中运行 Powershell 脚本时 PsExec.exe 引发错误 - 在 {machineName} 上创建密钥文件时出错:访问被拒绝 - PsExec.exe throws error when running Powershell script in SYSTEM context - Error creating key file on {machineName}: Access is denied 读取 openssl.cnf 文件时权限被拒绝错误 - Permission denied error while reading openssl.cnf file 在Azure上使用Powershell为PipelineFailedRun创建警报时出现错误请求错误 - Bad Request error while creating Alerts for PipelineFailedRuns using Powershell on Azure (C#) 创建远程 powershell 会话时出现“拒绝访问”错误 - (C#) Getting "Access Denied" error when creating remote powershell session 在 azure 中为警报规则创建 PowerShell 脚本时出错 - getting error while creating PowerShell script for alert rules in azure 使用 PSSession(远程 powershell)执行 CMD 或 EXE 文件导致错误 1603 访问被拒绝 - Executing CMD or EXE file using PSSession (remote powershell) caused Error 1603 access denied 远程Powershell访问被拒绝 - Remote Powershell Access Denied Powershell远程访问被拒绝 - Powershell remote access denied 在远程计算机文件系统上执行Powershell脚本 - Executing a powershell script on a remote computer file system PowerShell 脚本中的 Get-ChildItem 权限被拒绝错误 - Permission Denied error with Get-ChildItem in PowerShell script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM