Public/Get-VMDetails.ps1
<#
.SYNOPSIS Retrieves details about VMs within a specified Citrix catalog. .DESCRIPTION This function fetches and displays the MAC address and IP address for each VM associated with a given Citrix catalog, excluding temporary (template) VMs. .PARAMETER AdminAddress The address of the Citrix administration server. .PARAMETER CatalogName The name of the Citrix catalog from which to retrieve VM details. If not specified, details for all VMs managed by the admin address will be attempted. .EXAMPLE Get-VMDetails -AdminAddress "vdurctxddc001" -CatalogName "vdurcxa10" Retrieves and displays the VM details for the 'vdurcxa10' catalog on the 'vdurctxddc001' admin server. .EXAMPLE Get-VMDetails -AdminAddress "vdurctxddc001" Retrieves and displays the VM details for all catalogs managed by the 'vdurctxddc001' admin server. .NOTES This function requires Citrix PowerShell snap-ins to be installed and available on the machine where the script is run. #> function Get-VMDetails { Param( [Parameter(Mandatory = $true)] [string]$AdminAddress, [Parameter(Mandatory = $false)] [string]$CatalogName ) # Load Citrix snap-ins try { Add-PSSnapin citrix* -ErrorAction Stop } catch { Write-Error "Citrix PowerShell snap-ins are not loaded or not available." return } $allVMs = @() # Retrieve the provisioning scheme $provName = (Get-ProvScheme -ProvisioningSchemeName $CatalogName -AdminAddress $AdminAddress).MasterImageVM $vmName = $provName.Split("\")[3] $trimmedVmName = $vmName.Split(".")[0] $allVMs += $trimmedVmName.Substring(0, $trimmedVmName.IndexOf("TMP") + 3) # Retrieve all VMs from the catalog $allVMs += Get-BrokerMachine -AdminAddress $AdminAddress -DesktopGroupName $CatalogName | Select-Object -ExpandProperty HostedMachineName foreach ($VM in $allVMs) { # Check if the VM name contains '-tmp', mark as template if ($VM -match "-tmp") { Write-Host "$VM is a template." continue } try { $hostIp = [System.Net.Dns]::GetHostEntry($VM).AddressList[0].IpAddressToString } catch { Write-Warning "Failed to resolve IP for $VM." continue } try { $wmi = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $VM -ErrorAction Stop | Where-Object { $_.IPAddress -contains $hostIp } $mac = $wmi.MACAddress Write-Host "$VM -> $mac -> $hostIp" } catch { Write-Warning "Failed to get WMI object for $VM." } } } |