【问题标题】:Objects methods missing with import-pssession but working with enter-pssession使用 import-pssession 但使用 enter-pssession 时缺少对象方法
【发布时间】:2020-04-03 20:24:48
【问题描述】:

我有一个小的 powershell 脚本可以远程运行备份软件 veeam,但生成的对象不同。

我以两种不同的方式连接:

  1. 导入-PSSession
$cred = Get-Credential -m "Backupserver" -UserName XY
$session = new-PSSession -ComputerName Backupserver -Credential $cred
Invoke-Command -Session $session {add-pssnapin VeeamPSSnapin}
Import-PSSession -Session $session -module VeeamPSSnapin
# but I tried the following too
Import-PSSession -Session $session -DisableNameChecking -AllowClobber
  1. 进入会话
$cred = Get-Credential -m "Backupserver" -UserName XY
enter-pssession -Credential $cred Backupserver
add-pssnapin VeeamPSSnapin

之后我可以使用 Veeam Snapin,但以下内容:

Get-VBRJob -name "Backup Job BITS-SERVER" | Get-Member

不给我结果对象的所有方法,也不给我相同的对象类型。

使用 enter-pssession 我得到了:

   TypeName: Veeam.Backup.Core.CBackupJob

Name                          MemberType Definition
----                          ---------- ----------
CanRunByScheduler             Method     bool ISchedulableJob.CanRunByScheduler()
CheckDeleteAllowed            Method     void CheckDeleteAllowed()
...

通过 import-pssession 我得到了:

   TypeName: Deserialized.Veeam.Backup.Core.CBackupJob

Name                         MemberType   Definition
----                         ----------   ----------
GetType                      Method       type GetType()
ToString                     Method       string ToString(), string ToString(string format, System.IFormatProvider formatProvider), string IFormattable.ToString(string format, ...
PSComputerName               NoteProperty string PSComputerName=cpa-backup.itservice.de
...

它应该是不同类型的结果对象 (Deserialized.Veeam.Backup.Core.CBackupJob)。

但是我怎样才能远程连接(没有 enter-pssession 的非交互)以使用所有方法获取相同的对象???

提前谢谢...

【问题讨论】:

  • Import-Module -PSSession $session -module VeeamPSSnapin 试试这个命令看看结果如何
  • 出现错误,字符串 VeeamPSSnapin 无法转换为 System.Management.Automation.PSModuleInfo。

标签: powershell veeam


【解决方案1】:

由于 PowerShell 在通过网络发送给您之前会序列化这些对象,因此您最好使用 Connect-VBRServer cmdlet

Connect-VBRServer -Server "Backupserver"
Get-VBRJob -Name "Backup Job BITS-SERVER" | Get-Member

【讨论】:

  • 这一点的缺点是现代版本的 Veeam 需要安装整个 VBR 控制台及其所有依赖项,以便在任何人希望运行管理单元的地方安装。
猜你喜欢
  • 2014-04-18
  • 2019-01-09
  • 1970-01-01
  • 1970-01-01
  • 2021-08-25
  • 2014-07-09
  • 1970-01-01
  • 2015-11-11
  • 1970-01-01
相关资源
最近更新 更多