psobject

Passing “native” object to background jobs

青春壹個敷衍的年華 提交于 2019-11-29 10:08:56
Here is what I'd like to achieve in one way or another. I have a custom assembly defining some objects. In my script, I create a custom object that I'd like to pass to a script block, keeping that object behavior. Add-Type -AssemblyName MyCustomDLL $global:object = new-object MyCustomDLL.MyCustomObject() $object | gm $jobWork = { param ($object) $object | gm } # I'd like to keep my object behavior in that block $job = Start-Job -ScriptBlock $jobWork -ArgumentList $object Wait-Job $job Receive-Job $job How can I do that or achieve the same effect? Thanks for your help Instead of background jobs

PowerShell type accelerators: PSObject vs PSCustomObject

北慕城南 提交于 2019-11-28 13:20:02
In PowerShell v3.0 PSCustomObject was introduced. It's like PSObject , but better. Among other improvements (e.g. property order being preserved), creating object from hashtable is simplified: [PSCustomObject]@{one=1; two=2;} Now it seems obvious that this statement: [System.Management.Automation.PSCustomObject]@{one=1; two=2;} would work the same way, because PSCustomObject is an "alias" for full namespace + class name. Instead I get an error: Cannot convert the "System.Collections.Hashtable" value of type "System.Collections.Hashtable" to type "System.Management.Automation.PSCustomObject". I

Passing “native” object to background jobs

吃可爱长大的小学妹 提交于 2019-11-28 03:22:27
问题 Here is what I'd like to achieve in one way or another. I have a custom assembly defining some objects. In my script, I create a custom object that I'd like to pass to a script block, keeping that object behavior. Add-Type -AssemblyName MyCustomDLL $global:object = new-object MyCustomDLL.MyCustomObject() $object | gm $jobWork = { param ($object) $object | gm } # I'd like to keep my object behavior in that block $job = Start-Job -ScriptBlock $jobWork -ArgumentList $object Wait-Job $job Receive

Deep copying a PSObject

扶醉桌前 提交于 2019-11-27 15:51:33
I have a powershell script in which I do the following $somePSObjectHashtables = New-Object Hashtable[] $somePSObject.Length; $somePSObjects = Import-CSV $csvPath 0..($somePSObject.Length - 1) | ForEach-Object { $i = $_; $somePSObjectHashtables[$i] = @{}; $somePSObject[$_].PSObject.Properties | ForEach-Object { $somePSObjectHashtables[$i][$_.Name] = $_.Value; } } I need to do this because I want to make several distinct copies of the data in the CSV to perform several distinct manipulations. In a sense I'm performing an "INNER JOIN" on the resulting array of PSObject . I can easily iterate

PowerShell type accelerators: PSObject vs PSCustomObject

為{幸葍}努か 提交于 2019-11-27 07:37:13
问题 In PowerShell v3.0 PSCustomObject was introduced. It's like PSObject , but better. Among other improvements (e.g. property order being preserved), creating object from hashtable is simplified: [PSCustomObject]@{one=1; two=2;} Now it seems obvious that this statement: [System.Management.Automation.PSCustomObject]@{one=1; two=2;} would work the same way, because PSCustomObject is an "alias" for full namespace + class name. Instead I get an error: Cannot convert the "System.Collections.Hashtable

Deep copying a PSObject

坚强是说给别人听的谎言 提交于 2019-11-26 14:46:15
问题 I have a powershell script in which I do the following $somePSObjectHashtables = New-Object Hashtable[] $somePSObject.Length; $somePSObjects = Import-CSV $csvPath 0..($somePSObject.Length - 1) | ForEach-Object { $i = $_; $somePSObjectHashtables[$i] = @{}; $somePSObject[$_].PSObject.Properties | ForEach-Object { $somePSObjectHashtables[$i][$_.Name] = $_.Value; } } I need to do this because I want to make several distinct copies of the data in the CSV to perform several distinct manipulations.