powershell - 带有文件共享的 Powershell Invoke-Command
问题描述
我有一个这样的 Powershell 脚本:
param([string]$zipFileLocation)
if([string]::IsNullOrEmpty($zipFileLocation))
{
write-host "No location provided"
return $false
}
write-host "Location of zip: $zipFileLocation"
write-host "Test-path result: $(test-path($zipFileLocation))"
write-host "END OF SCRIPT"
当我在本地运行此脚本时,使用参数 '\Server\Share',Test-Path 返回 true 并且一切正常。即当我运行'.\TestScript.ps1 -zipFileLocation '\\Server\Share'
它按预期工作。
但是,如果我像这样运行命令:
$remsession1 = New-PSSession -credential $credential -ComputerName $ServerName
$UnzipPackageResult= Invoke-Command -session $remsession1 -FilePath C:\Test\TestScript.ps1 -ArgumentList '\\Server\Share'
然后脚本中的“测试路径”返回$false
并出现UnauthorizedAccessException
错误。我不明白为什么。
提供的凭据在服务器上确实具有管理员权限。有什么想法吗?
解决方案
推荐阅读
- android - 试图在 android 中创建 spinner.OnItemSelectedListener 事件
- sed - sed 替换或删除字符串
- laravel - 如何自定义重置密码链接
- javascript - WordPress 编辑器在复制和粘贴时如何保留文本格式?
- angular - 处理多个 Observable 和函数
- unity3d - 我的点击事件,鼠标点击事件无法识别正确的游戏对象
- node.js - 带有 Lambda 的 Dialogflow - Webhook 调用失败。错误:502 错误网关
- c++ - 我对模板和链接器有一些疑问
- c++ - 在 C++ 中从 3D 向量中擦除元素
- javascript - 错误类型错误:未定义。何时从服务中提供数据