尝试进入PSS会话时出现Powershell错误

尝试进入PSS会话时出现Powershell错误,powershell,Powershell,我正在尝试进入一个新的会话。如果我手动运行每一行,它就会工作,但是当我作为脚本的一部分运行它时,我会得到一个错误。creds是有效的,似乎会话已经创建,我只是不能在脚本中输入它。引用的行号是写入主机。即使我只是给一个变量赋值,它也会出错 $cred = New-Object Management.Automation.PSCredential ($username, $pw) New-PSSession -ComputerName App02 -Credential $cred Get-PSSe

我正在尝试进入一个新的会话。如果我手动运行每一行,它就会工作,但是当我作为脚本的一部分运行它时,我会得到一个错误。creds是有效的,似乎会话已经创建,我只是不能在脚本中输入它。引用的行号是写入主机。即使我只是给一个变量赋值,它也会出错

$cred = New-Object Management.Automation.PSCredential ($username, $pw)
New-PSSession -ComputerName App02 -Credential $cred
Get-PSSession | Enter-PSSession

Write-Host "ERROR: Partial Service Deployment. See error log file(s)"
我认为这是一个错误:

无法执行操作,因为操作“NewNotImplementedException” 在文件:行:列:0:0“的偏移量63处 执行。在C:\DEV\Sandbox\Sandbox.ps1:29 char:14 +写入主机“错误:部分服务部署。请参阅错误日志文件。。。 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:NotImplemented:(:)[],运行时异常 +FullyQualifiedErrorId:未实现


您不能在脚本中使用
Enter PSSession
。原因:它用于交互目的。您可以使用
Invoke Command
和相应的
-Session
参数远程执行命令

另见此

调用命令的示例

$cred = New-Object Management.Automation.PSCredential ($username, $pw)
$session = New-PSSession -ComputerName App02 -Credential $cred
Invoke-Command -Session $session -ScriptBlock { Get-Service * } #Return all services from the remote machine

您不能在脚本中使用
Enter PSSession
。原因:它用于交互目的。您可以使用
Invoke Command
和相应的
-Session
参数远程执行命令

另见此

调用命令的示例

$cred = New-Object Management.Automation.PSCredential ($username, $pw)
$session = New-PSSession -ComputerName App02 -Credential $cred
Invoke-Command -Session $session -ScriptBlock { Get-Service * } #Return all services from the remote machine

Enter-PSSession
只能以交互方式使用。对于脚本编写,请使用
Invoke-Command
,并将其指向要运行命令或脚本块的计算机。

Enter-PSSession
只能以交互方式使用。对于脚本编写,请使用
Invoke-Command
,并将其指向要运行的计算机上的命令或脚本块