Are you just noting that by adding more code to your script that it takes longer to complete?
Do you need the information from both legacy and virtual NICs? If not, be specific about the data you want to collect.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
following are two queries and its execution time:
[NOTE: In below script , ID_LIST is list of VM ides that is not included]
CASE 1: With IP address , it's require more time.
2020-10-07 18:43:19,340 DEBUG - START Executing powershell:
Executing PS 1484170718:
'
$vms=get-vm | Where-Object {$_.id -in ID_LIST} | select VMName,Path,Id,State,Status,Computername,ConfigurationLocation ;$FinalOuTPut = New-Object System.Collections.Generic.List[System.Object];
ForEach($vm in $vms) {
$NicIPaddresses = Get-VMNetworkAdapter -VmName $vm.VMName | Select IPaddresses ;
$vmObj=New-Object -TypeName PSObject -Property @{
'VMName' = $vm.VMName
'Path' = $vm.Path
'Id' = $vm.Id
'State' = $vm.State
'Status' = $vm.Status
'Computername' = $vm.Computername
'ConfigurationLocation' = $vm.ConfigurationLocation
'IpAddresses' = $NicIPaddresses.IPaddresses
}; $FinalOuTPut.Add($vmObj); };
$FinalOuTPut
'
2020-10-07 18:43:46,653 DEBUG - [Power Shell Response Trace Data] 1484170718
==========================================================================
CASE 2: without IP Address
2020-10-07 18:46:34,027 DEBUG -
Executing PS 1960823611:
'$vms=get-vm | Where-Object {$_.id -in ID_LIST} | select VMName,Path,Id,State,Status,Computername,ConfigurationLocation ;$FinalOuTPut = New-Object System.Collections.Generic.List[System.Object];
ForEach($vm in $vms) {
$vmObj=New-Object -TypeName PSObject -Property @{
'VMName' = $vm.VMName
'Path' = $vm.Path
'Id' = $vm.Id
'State' = $vm.State
'Status' = $vm.Status
'Computername' = $vm.Computername
'ConfigurationLocation' = $vm.ConfigurationLocation
}; $FinalOuTPut.Add($vmObj); };
$FinalOuTPut '
2020-10-07 18:46:35,433 DEBUG - [Power Shell Trace Data] 1960823611
Are you just noting that by adding more code to your script that it takes longer to complete?
Do you need the information from both legacy and virtual NICs? If not, be specific about the data you want to collect.
You add code to a script for it to perform more functions. It makes sense that it will take more time.
Did you know that you can extract the IP address information from your first Get-VM cmdlet? In essence, by issuing the Get-VMNetworkAdapter you are accessing the VM a second time for information that is available from your original Get-VM command, so of course the script will take longer to execute.
http://techgenix.com/vm-ip-address/ shows how to use PowerShell to get the IP address from the Get-VM command by using an -ExpandProperty switch on the Select-Object command.