PSVMware.psm1
function Get-VMConfig { <# .SYNOPSIS Function to retrieve Configuration info of a VM. .DESCRIPTION Function to retrieve Configuration info of a VM. .PARAMETER VM A vSphere VM object .INPUTS System.Management.Automation.PSObject. .OUTPUTS System.Management.Automation.PSObject. .EXAMPLE PS> Get-VMConfig -VM VM01, VM02 .EXAMPLE PS> Get-VM VM01, VM02 | Get-VMConfig .NOTES NAME: Get-VMConfig AUTHOR: CarlosDZRZ .LINK https://code.vmware.com/web/tool/11.5.0/vmware-powercli #> [CmdletBinding()] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] [string[]]$VM ) begin { $VMConfig_obj = @() } process { foreach ($VMName in $VM) { $VMName = Get-VM $VMName $VMDT = Get-Datastore -Id $VMName.DatastoreIdList $vSwitch = $VMName | Get-VirtualSwitch $vPortGroup = $VMName | Get-VirtualPortGroup $VMDisk_obj = @() $VMDisks = $VMName | Get-HardDisk | select Parent, Name, StorageFormat, CapacityGB, Filename $VMConfig_obj += [PSCustomObject]@{ Name = $VMName.Name PowerState = $VMName.PowerState NumCpu = $VMName.NumCpu MemoryGB = $VMName.MemoryGB VMHost = $VMName.VMHost UsedSpaceGB = [math]::Round($VMName.UsedSpaceGB, 2) ProvisionedSpaceGB = [math]::Round($VMName.ProvisionedSpaceGB, 2) CreateDate = $VMName.CreateDate OSFullName = $VMName.Guest.OSFullName IPAddress = $VMName.Guest.IPAddress Nics = $VMName.Guest.Nics Datastore_Name = $VMDT.Name VirtualSwitch = $vSwitch.Name vPortGroup = $vPortGroup.Name VLanId = $vPortGroup.VLanId Disks = $VMDisks }#EndPSCustomObject } } end { return $VMConfig_obj } }#End Function Get-VMConfig function Get-VMHostConfig { <# .SYNOPSIS Function to retrieve the Configuration info of a vSphere host. .DESCRIPTION Function to retrieve the Configuration info of a vSphere host. .PARAMETER VMHost A vSphere ESXi Host object .INPUTS System.Management.Automation.PSObject. .OUTPUTS System.Management.Automation.PSObject. .EXAMPLE PS> Get-VMHostConfig -VMHost ESXi01, ESXi02 .EXAMPLE PS> Get-VMHost ESXi01,ESXi02 | Get-VMHostConfig .NOTES NAME: Get-VMHostConfig AUTHOR: CarlosDZRZ .LINK https://code.vmware.com/web/tool/11.5.0/vmware-powercli #> [CmdletBinding()] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] [string[]]$VMHost ) begin { $VMHostConfig_obj = @() } process { foreach ($vHost in $VMHost) { $vHost = Get-VMHost $VMHost $HostDTlist = Get-Datastore -Id $vHost.DatastoreIdList $VMHostConfig_obj += [PSCustomObject]@{ Name = $vHost.Name ConnectionState = $vHost.ConnectionState PowerState = $vHost.PowerState Manufacturer = $vHost.Manufacturer Model = $vHost.Model NumCpu = $vHost.NumCpu CpuTotalMhz = $vHost.CpuTotalMhz CpuUsageMhz = $vHost.CpuUsageMhz MemoryTotalGB = [math]::Round($vHost.MemoryTotalGB, 2) MemoryUsageGB = [math]::Round($vHost.MemoryUsageGB, 2) ProcessorType = $vHost.ProcessorType HyperthreadingActive = $vHost.HyperthreadingActive MaxEVCMode = $vHost.MaxEVCMode Datastores = $HostDTlist }#EndPSCustomObject } } end { return $VMHostConfig_obj } }#End Function Get-VMHostConfig function Get-VMHostNetworkConfig { <# .SYNOPSIS Function to retrieve the Network Configuration info of a vSphere host. .DESCRIPTION Function to retrieve the Network Configuration info of a vSphere host. .PARAMETER VMHost A vSphere ESXi Host object .INPUTS System.Management.Automation.PSObject. .OUTPUTS System.Management.Automation.PSObject. .EXAMPLE PS> Get-VMHostNetworkConfig -VMHost ESXi01, ESXi02 .EXAMPLE PS> Get-VMHost ESXi01,ESXi02 | Get-VMHostNetworkConfig .NOTES NAME: Get-VMHostNetworkConfig AUTHOR: CarlosDZRZ .LINK https://code.vmware.com/web/tool/11.5.0/vmware-powercli #> [CmdletBinding()] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] [string[]]$VMHost ) begin { $VMHostNetworkConfig_obj = @() } process { $vSwitches = Get-VirtualSwitch -VMHost $vHost foreach ($vHost in $VMHost) { foreach ($vSwitch in $vSwitches) { $vPortGroups = $vSwitch | Get-VirtualPortGroup foreach ($vPortGroup in $vPortGroups){ $VMHostNetworkConfig_obj += [PSCustomObject]@{ VMHost = $vHost VirtualSwitch = $vSwitch.Name Nic = [string]$vSwitch.Nic vPortGroup = $vPortGroup.Name VLanId = $vPortGroup.VLanId }#EndPSCustomObject } } } } end { return $VMHostNetworkConfig_obj } } #End Function Get-VMHostNetworkConfig |