powershell - 使用 Invoke-Command 执行 PowerShell 远程会话无效
问题描述
在 PowerShell 中,我正在与服务器进行远程会话。我想将文件添加到远程服务器并让它们实际存在于那里。运行以下代码时,不会向服务器添加任何内容。为什么会这样以及如何才能将文件实际添加到服务器?
Enable-PSRemoting -Force
$SomeComputer= "some-server.com"
$SomeUsername = "some-username"
$SomePassword = ConvertTo-SecureString "some-password" -AsPlainText -Force
$SomeCredentials = New-Object System.Management.Automation.PSCredential ($SomeUsername, $SomePassword)
$SomeSession = New-PSSession -ComputerName $SomeComputer -Credential $SomeCredentials
Invoke-Command -Session $SomeSession -ScriptBlock {
New-Item -Path "SomeFile.txt" -ItemType File
}
解决方案
推荐阅读
- javascript - 传递给函数的参数不起作用
- c# - 私有类的公共实例 - 在 C# 中永远不允许
- java - 使用 Java 登录 - 每次更改时自动转储变量值的任何方式
- android - 如何检查颤振应用程序的混淆结果?
- laravel - Laravel cookie 返回 null
- android - 在 Android 中使用 PagedList 时如何从 ViewModel 通知 Activity?
- android - 电报源代码构建失败
- c++ - 错误:从 'char' 到 'const char' 的无效转换 [-fpermissive] strcat(encrypted, key[i]);
- javascript - 未捕获的类型错误:从 wp 检索标签时无法读取 null 的属性“长度”
- numpy - 关于 Numpy 符号的困惑