首页 > 解决方案 > 使用 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
}

标签: powershelldeploymentscriptingdevopspowershell-remoting

解决方案


推荐阅读