我使用以下脚本在远程机器上运行一些基本命令,并将输出记录到共享中。我在共享上收到访问被拒绝的异常,即使共享对执行脚本的每个人都具有完全控制访问权限,
脚本:
invoke-command -session $s -ScriptBlock {
param($log)
cd 'c:\temp' | out-file $log -NoClobber
cmd /c 'dir' | out-file $log -NoClobber
} -argumentList '\\share_location\log_file_path.log'仅供参考,在上面的脚本中,会话$s是使用我的凭据生成的。
例外:
Access to the path '\\share_location\log_file_path.log' is denied.
+ CategoryInfo : OpenError: (:) [Out-File], UnauthorizedAccessException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand有人能给我提个建议吗?
发布于 2019-10-29 00:26:38
启用PSRemoting服务以自动启动
在主机和远程计算机上
Set-Service winrm -StartupType Automatic
Start-Service winrm启用PSREmoting
在主机和远程计算机上
EnablePSRemoting -Force将计算机添加到受信任主机
在远程机器上
Set-Item wsman:\localhost\Client\TrustedHosts -Value "$(hostname),*$((Get-WmiObject Win32_ComputerSystem).Domain)"在Powershell Remoting中启用多跳
确定允许通过凭证的主机
Enable-WSManCredSSP –Role Client –DelegateComputer "$(hostname),*$((Get-WmiObject Win32_ComputerSystem).Domain)"在源机器上。
Enable-WSManCredSSP –Role Server您必须指定身份验证和凭据
在主机上
$Cred = [System.Management.Automation.PSCredential]::new("<username>",$("<Password>" | ConvertTo-SecureString -AsPlainText -Force))
invoke-command -ComputerName localhost -ScriptBlock {Write-Host $args[0]} -ArgumentList "Hello!, It Works" -Authentication Credssp -Credential $cred参考文献
https://stackoverflow.com/questions/45022998
复制相似问题