rxjoseph
Enthusiast
Enthusiast

Collecting VM information for Migration

Jump to solution

Hi LucD

The below script works find however i am struggling to get the Tag information

Basically i need the script to filter tags related to category = Veeam but it dosent work can you help me please

These are the two lines which gives a issue

@{N="Tag-Catagory";E={(Get-Tagassignment -Entity $_.Name).Tag.Category |where {($_.Name).tag.catagory -eq "Veeam"} }},


@{N="Tag";E={(Get-Tagassignment -Entity $_.Name).Tag.Name}},

 

 

##### Full Script ######

 

$CollectVMlist = Get-Content -path "D:\Temp\vmlist.txt"

foreach ($VMlist in $CollectVMlist) {


get-cluster |get-vm $VMlist| Select-object @{N='VMName' ; E={$_.name}},


@{N='FQDN';E={$_.ExtensionData.Guest.Hostname }},

@{N='PowerState' ;E={$_.PowerState}},

@{N='MemoryGB' ; E={[math]::Round($_.MemoryGB)}},


@{N='NumCpu' ; E={$_.NumCpu}},


@{N='CoresPerSocket' ; E={$_.CoresPerSocket}},


@{N='Source-Cluster';E={(Get-Cluster -VM $_).Name}},


@{N="Source-vCenter"; E={$_.Uid.Split(':@')[1]}},


@{N='VM-Size';E={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},


@{N = ”Target-Cluster”; E = { '#' } },


@{N = ”Target-vCenter”; E = { '#' } },

@{N='Network' ;E={$_.ExtensionData.Guest.Net.network}},

@{N='OS_Version' ; E={$_.Guest.OSFullName}},

@{N='Hardware_version' ; E={$_.HardwareVersion}},

@{N='VM_Tools_Ver' ;E={$_.ExtensionData.Guest.ToolsVersion}},

@{N='VM_Tools_Status' ;E={$_.ExtensionData.Guest.ToolsStatus}},

@{N='Tools_Running' ;E={$_.ExtensionData.Guest.ToolsRunningStatus}},


@{N='vmhost' ; E={$_.vmhost}},

@{N='ResourcePool' ; E={$_.ResourcePool}},

@{N='moRefID' ;E={$_.id}},

 

@{N="Tag-Catagory";E={(Get-Tagassignment -Entity $_.Name).Tag.Category |where {($_.Name).tag.catagory -eq "Veeam"} }},


@{N="Tag";E={(Get-Tagassignment -Entity $_.Name).Tag.Name}},

 

# @{N='IP';E={$_.Guest.IPAddress -join '|'}},

@{N='IP';E={$_.Guest.IPAddress[0] }},

 

@{N='Gateway';E={$_.ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute.Gateway.IpAddress | where {$_ -ne $null}}},

@{N='DNS';E={$_.ExtensionData.Guest.IpStack.dnsconfig.ipaddress -join '|' }},


@{N='Network-Adapter' ; E={$_.Guest.nics.device}},

@{N='Adapter-Type';E={(Get-NetworkAdapter | Select-Object -ExpandProperty Type -VM $_).Name }},

@{N='Datastore-Cluster';E={(Get-datastorecluster -VM $_).Name}},

@{N='Datastore';E={(Get-Datastore -VM $_).Name}}

}

 

#### END #####

 

Many thanks

RXJ

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Did you already try with the Tag parameter on the Get-VM cmdlet?

Your code should probably be

@{N="Tag-Catagory";E={(Get-Tagassignment -Entity $_ |where {$_.Tag.Category.Name -eq "Veeam"}).Tag.Name }},


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

View solution in original post

2 Replies
LucD
Leadership
Leadership

Did you already try with the Tag parameter on the Get-VM cmdlet?

Your code should probably be

@{N="Tag-Catagory";E={(Get-Tagassignment -Entity $_ |where {$_.Tag.Category.Name -eq "Veeam"}).Tag.Name }},


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

rxjoseph
Enthusiast
Enthusiast

Thanks so much LucD

it works 🙂

 

 

 

0 Kudos