为什么将 pscustomobject 传递到启动作业脚本块时会丢失脚本属性?
在 Windows XP x64(我假设是 win2k3)powershell 2.0 上,将 pscustomobjects 的数组列表传递给 start-job 作为 argumentlist 参数传递对象,但 scriptproperties 只是从对象中消失(由 get-member 确认)。注意 pscustomobject 的属性确实返回得很好
有人知道为什么吗?和/或有解决方案吗?
$dbs 是带有 pscustomobjects 的数组列表,具有各种 noteproperties 和 scriptproperties。
一旦传递到启动作业,所有脚本属性都会消失,而注释属性则可以正常工作。
下面在启动作业之外执行
$dbs | get-member
返回
ConnectionString NoteProperty System.String ConnectionString=server=...
DbType NoteProperty System.String DbType=Staging
CreateBackup ScriptMethod System.Object CreateBackup ();
GetBackup ScriptMethod System.Object GetBackup();
...
同时
start-job -name $server -argumentlist $dbs,$server -scriptblock {
param($dbs, $server)
$dbs | get-member
}
返回
bool Equals(System.Object obj)
int GetHashCode()
type GetType()
string ToString()
System.String ConnectionString=server=...
System.String DbType=Staging
On windows XP x64 (and I assume win2k3) powershell 2.0, passing an arraylist of pscustomobjects to start-job as argumentlist parameter passes the object in but scriptproperties just disappear from the object (confirmed by get-member). Note properties of the pscustomobject do return just fine
Anyone know why? and/or have a solution for a work around?
$dbs is arraylist with pscustomobjects that have various noteproperties and scriptproperties.
All of the script properties disappear once passed into start-job, while note properties work just fine.
Below executed outside of start-job
$dbs | get-member
returns
ConnectionString NoteProperty System.String ConnectionString=server=...
DbType NoteProperty System.String DbType=Staging
CreateBackup ScriptMethod System.Object CreateBackup ();
GetBackup ScriptMethod System.Object GetBackup();
...
while
start-job -name $server -argumentlist $dbs,$server -scriptblock {
param($dbs, $server)
$dbs | get-member
}
Returns
bool Equals(System.Object obj)
int GetHashCode()
type GetType()
string ToString()
System.String ConnectionString=server=...
System.String DbType=Staging
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看自定义 PowerShell 主机并将 PSObject 转换回基本类型我前段时间回答过。这是同样的情况。
Look at Custom PowerShell Host and Converting PSObject back to base type I answered some time ago. It is the same case.
后台作业使用远程处理。远程处理序列化对象,然后将它们发送到目标运行空间,在那里它们被反序列化。当对象被序列化时,对象方法不包含在序列化对象中。
Background jobs use remoting. Remoting serializes the objects and then sends them to the target runspace, where they are de-serialized. When an object is serialized, object methods are not included in the serialized object.