Ginolard
 New Member Posts:46

 |
| 26 Apr 2011 11:42 PM |
|
Maybe I haven't explained it very well in the title, so here's an example
foreach ( $csv in $csvs )
{
Echo "Processing Cluster Shared Volume $n"
$Signature = ( $csv | Get-ClusterParameter DiskSignature ).Value.substring(2)
$obj = New-Object PSObject -Property @{
Name = $csv.Name
CSVPath = ( $csv | select -Property Name -ExpandProperty SharedVolumeInfo).FriendlyVolumeName
LUN = ( Get-WmiObject Win32_DiskDrive | Where { "{0:x}" -f $_.Signature -eq $Signature } ).SCSILogicalUnit
PhysicalDisk = ( Get-WmiObject Win32_DiskDrive | Where { "{0:x}" -f $_.Signature -eq $Signature } ).DeviceID.substring(4)
}
($obj).PhysicalDisk = ($obj).PhysicalDisk -Replace "PHYSICALDRIVE", "Physical Disk "
$objs += $obj
$n++
}
What I want to do is add another property called LUNPath with the following code
LUNPath = (get-nalun | where {(get-nalunmap $_).lunid -eq LUN} |select path)
However, my experience with the PSObject is limited so I'm not sure if you can create a new property that references a previous one
|
|
|
|
|
Jonathan
 Basic Member Posts:109

 |
| 27 Apr 2011 01:03 PM |
|
If I am reading what you want to do correctly, you would access it by the following by "this.LUN". The "this" object refers back to the current PSObject, and then the .LUN property of "this". Hope that helps. |
|
Jonathan Tyler
http://powershellreflections.wordpress.com Follow Me On Twitter |
|
|
Ginolard
 New Member Posts:46

 |
| 27 Apr 2011 10:04 PM |
|
I just tried trhe following variations, none of which worked. I guess I've misunderstood ;) LUNPath = (get-nalun | where {(get-nalunmap $_).lunid -eq "this.lun"} |select path) LUNPath = (get-nalun | where {(get-nalunmap $_).lunid -eq this.lun} |select path) LUNPath = (get-nalun | where {(get-nalunmap $_).lunid -eq "$this.lun"} |select path) LUNPath = (get-nalun | where {(get-nalunmap $_).lunid -eq $this.lun} |select path) |
|
|
|
|
Ginolard
 New Member Posts:46

 |
| 29 Apr 2011 06:23 AM |
|
Quick bump in the hope someone can help |
|
|
|
|
Poshoholic PowerShell MVP, Community Director
 Basic Member Posts:111

 |
| 29 Apr 2011 07:48 AM |
|
To add a property that references another property, you need to use Add-Member to add a member of type ScriptProperty. ScriptProperty members are evaluated when they are referenced, so they can use information in other members or methods. For example, assuming that the LUN property had a child property called Path, you could expose it like this:
$obj = New-Object PSObject -Property @{ Name = $csv.Name CSVPath = ( $csv | select -Property Name -ExpandProperty SharedVolumeInfo).FriendlyVolumeName LUN = ( Get-WmiObject Win32_DiskDrive | Where { "{0:x}" -f $_.Signature -eq $Signature } ).SCSILogicalUnit PhysicalDisk = ( Get-WmiObject Win32_DiskDrive | Where { "{0:x}" -f $_.Signature -eq $Signature } ).DeviceID.substring(4) } $obj | Add-Member -MemberType ScriptProperty -Name LUNPath -Value {$this.LUN.Path}
Just make sure you use $this inside the script block that defines the ScriptProperty member when you want to refer to the object itself.
Does that help? |
|
Kirk Munro [MVP]
Poshoholic
My blog: http://poshoholic.com
Follow me on Twitter: http://twitter.com/poshoholic |
|
|
Ginolard
 New Member Posts:46

 |
| 02 May 2011 12:55 AM |
|
Kirk, OK. I can see how using the Add-Member cmdlet is the right approach. However, that line gives me a "Missing '=' operator after key in hash literal." if I put it inside the PSObject scriptblock |
|
|
|
|