Hi,
I have the following script :
$dc = New-Datacenter -location (Get-Folder -NoRecursion) -Name vDatacenter
New-Cluster -Name iSCSI_Cluster -Location $dc
New-Cluster -Name vSAN_Cluster -Location $dc
$csvFile = Import-CSV -Path C:\Users\Administrator\Desktop\esxiHostsDeployment.csv
foreach ($val in $csvFile)
{
$esxiHosts = $val.Hosts
$clusterName = $val.Cluster
$virtualSwitch = $val.Switch
$nic = $val.NIC
$vmK = $val.VMK
$ip = $val.IP
Add-vmhost $esxiHosts -User root -Password "" -Location $clusterName -Force -ErrorAction SilentlyContinue
try
{
$gSwitch = Get-VirtualSwitch -Name $virtualSwitch -VMHost $esxiHosts -ErrorAction Stop
}
catch
{
$gSwitch = New-VirtualSwitch -Name $virtualSwitch -VMHost $esxiHosts
}
$nAdapter = Get-VMHostNetworkAdapter -VMHost $esxiHosts -Physical -Name $nic
$gSwitch | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $nAdapter -Confirm:$false
New-VMHostNetworkAdapter -VMhost $esxiHosts -PortGroup $vmK -IP $ip -subnetmask 255.255.255.0 -VirtualSwitch $gSwitch -confirm:$false
}
When the script executes the get statements in both $gSwitch and $nAdapter both during runtime display information (shown below) which is not needed to be displayed as this slows down processing
Name ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz MemoryUsageGB MemoryTotalGB Version
---- --------------- ---------- ------ ----------- ----------- ------------- ------------- -------
esxi21.v.lab Connected PoweredOn 2 0 5184 0.000 5.995 6.7.0
VMotionEnabled : False
FaultToleranceLoggingEnabled : False
ManagementTrafficEnabled : False
IPv6 :
AutomaticIPv6 :
IPv6ThroughDhcp :
IPv6Enabled :
Mtu : 1500
VsanTrafficEnabled : False
PortGroupName : ManagementNetwork2
Id : key-vim.host.VirtualNic-vmk1
VMHostId : HostSystem-host-31
VMHost : esxi21.v.lab
VMHostUid : /VIServer=vsphere.lab\administrator@vcsa.v.lab:443/VMHost=HostSystem-host-31/
DeviceName : vmk1
Mac : 00:50:56:6e:2f:cd
DhcpEnabled : False
IP : 192.168.2.31
SubnetMask : 255.255.255.0
Uid : /VIServer=vsphere.lab\administrator@vcsa.v.lab:443/VMHost=HostSystem-host-31/HostVMKernelVirtualNic=key-vim.host.VirtualNic-vmk1/
Name : vmk1
ExtensionData : VMware.Vim.HostVirtualNic
When I try Out-Null or > $null I get errors since the variable values are already discarded by the Out-Null and > $null.
How do I discard screen output yet keep the values as I could not find anything in Powershell that does this.
Thank You