VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Help with Custom Name Row adding

Hi,

Need help with adding the name of the dept head for the below, how can I achieve this ?

Example : get-vm | select @{N="Folder";E={$_.Folder.Name}}, Name

Current Output :

Folder            VMName

Marketing      App1

HR                 App2

Learning        App3

Sales             App4

But I would like to add one more column with Department head

Steve for Marketing and Sales Folder

Tom for HR

Lisa for Learning

Department_Head      Folder       VMName

Steve                          Marketing   App1

Tom                             HR             App2

Lisa                             Learning    App3

Steve                          Sales          App4

Please help!!!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If you have the information in a table, you could use a hash table as a lookup table.

Something like this

$dept = @'

Dept,Head

Marketing,Steve

HR,Tom

Learning,Lisa

Sales,Stev

'@

$deptTab = @{}

ConvertFrom-Csv -InputObject $dept -UseCulture |

ForEach-Object -Process {

   $deptTab.Add($_.Dept,$_.Head)

}


Get-VM |

select Name,

   @{N="Folder";E={$_.Folder.Name}},

   @{N='DeptHead';E={$deptTab[$_.Folder.Name]}}

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

From where do you get the Department Head?

Is that a separate file?

How do decide which Department Head goes to which VM?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I am not sure, how can I do the mapping, I want to do the department head`s name mapping based on the Folder name.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you have the information in a table, you could use a hash table as a lookup table.

Something like this

$dept = @'

Dept,Head

Marketing,Steve

HR,Tom

Learning,Lisa

Sales,Stev

'@

$deptTab = @{}

ConvertFrom-Csv -InputObject $dept -UseCulture |

ForEach-Object -Process {

   $deptTab.Add($_.Dept,$_.Head)

}


Get-VM |

select Name,

   @{N="Folder";E={$_.Folder.Name}},

   @{N='DeptHead';E={$deptTab[$_.Folder.Name]}}

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

BullsEye, that worked.....Thanks a lot LucD Smiley Happy

0 Kudos