Hi Friends
I would like to compare the power shell script output with import csv file and get the output as pass for matched values and fail for non matched values
Thanks in advance.
$vmhost = Read-Host "Enter Esxi IP" Connect-VIServer $vmhost Add-PSSnapin VMware.VimAutomation.Core -ErrorAction 'SilentlyContinue' $VmHostresult = @() foreach ($vmhost in Get-VMHost) { $vmhostname = Get-VMHost |Sort Name |Get-View | Select Name $esxcli = $vmhost | Get-EsxCli $details = $esxcli.hardware.platform.get.Invoke() | Select @{N='VMHost';E={$esxcli.VMHost.Name}},VendorName,ProductName,SerialNumber #$serviceTag = $esxcli.hardware.platform.get().SerialNumber $Managementinfo = $vmhost | Get-VMHostNetworkAdapter | Where-Object {$_.ManagementTrafficEnabled -eq $true} $VirtualPortGroup = $vmhost | Get-VirtualPortGroup $IPinfo = $Managementinfo | select-object -ExpandProperty ip $ManagementPortGroup = $Managementinfo.extensiondata.spec $ManagementIP = $IPinfo -join ", " $HostCPU = $vmhost.ExtensionData.Summary.Hardware.NumCpuPkgs $HostCPUcore = $vmhost.ExtensionData.Summary.Hardware.NumCpuCores/$HostCPU $TotalMemory = [math]::round($vmhost.MemoryTotalGB) $SSHservice = $vmhost | Get-VMHostService | Where-object {$_.key -eq "Tsm-ssh"} | Select-Object -ExpandProperty running $UPtime = (Get-Date) - ($vmhost.ExtensionData.Runtime.BootTime) | Select-Object -ExpandProperty days $ntpServerList = $vmhost | Get-VMHostNtpServer | Out-String $NTPservice = $vmhost | Get-VMHostService | Where-Object {$_.key -eq "ntpd"} | Select-Object -ExpandProperty running $Scratch = Get-VMhost | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation" $ATSValue = Get-VMhost | Get-AdvancedSetting -Name "VMFS3.UseATSForHBOnVMFS5" $ATSValueonVMFS3 = Get-VMhost | Get-AdvancedSetting -Name "VMFS3.UseATSForHBOnVMFS3" $HALocking = Get-VMhost | Get-AdvancedSetting -Name "VMFS3.HardwareAcceleratedLocking" $HAMove = Get-VMhost | Get-AdvancedSetting -Name "DataMover.HardwareAcceleratedMove" $HAInIt = Get-VMhost | Get-AdvancedSetting -Name "DataMover.HardwareAcceleratedInit" $DisabledProtcols = Get-VMhost | Get-AdvancedSetting -Name "UserVars.ESXiVPsDisabledProtocols" $TSO = Get-VMHost | Get-AdvancedSetting -Name "Net.UseHwTSO6" $LRO = Get-VMHost | Get-AdvancedSetting -Name "Net.TcpipDefLROEnabled" $vmotion = Get-VMHost * | sort | Get-VMHostNetworkAdapter -VMKernel | select VMotionEnabled | where VMotionEnabled -eq $True $Users = Get-VMHostAccount | Select Name | Out-String $syslog = ($vmhost | Get-AdvancedSetting -Name Syslog.global.logHost).value $powerpolicy = Get-VMHost | Select @{N="PowerPolicy";E={$powSys = Get-View $_.ExtensionData.ConfigManager.PowerSystem $powSys.Info.CurrentPolicy.ShortName}} $user = Read-Host "ESXi Host SSH User" $rootpword = Read-Host "ESXi Host SSH Password" -AsSecureString $rootbstr = [System.Runtime.InteropServices.marshal]::SecureStringToBSTR($rootpword) $rootpword = [System.Runtime.InteropServices.marshal]::PtrToStringAuto($rootbstr) echo y | &("plink.exe") -ssh $vmhost -l $user -pw $rootpword exit | Out-Null $biosfwv = echo y | &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "smbiosDump | grep -i Version:" | Select-Object -first 1 | Out-String $biosfwd = echo y | &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "smbiosDump | grep -i Date:" $lpfcQdepth = echo y | &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "esxcli --formatter=csv system module parameters list -m lpfc | grep 254" $lpfcretry = echo y | &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "esxcli --formatter=csv system module parameters list -m lpfc | grep 60" $qlogicqdepth = echo y | &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "esxcli --formatter=csv system module parameters list -m qlnativefc | grep 255" $qlogicretry = echo y | &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "esxcli --formatter=csv system module parameters list -m qlnativefc | grep 60" | Out-String $sshfirewall = &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "esxcli network firewall ruleset allowedip list | grep sshServer" $vsphereFirewall = &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "esxcli network firewall ruleset allowedip list | grep vSphereClient" $ntp = echo y | &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "ntpq -p" | Out-String $Raidcontroller = echo y | &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "/usr/lib/vmware/vmkmgmt_keyval/vmkmgmt_keyval -a | grep -i -e 'MR-DriverVersion' -A 15" | Out-String $hbaadapter = echo y | &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "esxcli storage san fc list | grep Adapter: " | Out-String $hbafirmware = echo y | &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "esxcli storage san fc list | grep Firmware " | Out-String $hbadriver = echo y | &("plink.exe") -ssh $vmhost -l $user -pw $rootpword -batch "esxcli storage san fc list | grep DriverVersion " | Out-String #$hbainfo = Write-Output $esxcli.storage.san.fc.list.invoke() | Select Adapter,DriverName,DriverVersion,FirmwareVersion,PortState $VMHostNetworkAdapters = Get-VMHostNetworkAdapter | Where-Object { $_.Name -like "vmnic*" } foreach ($VMNic in $VMHostNetworkAdapters) { $NicInfo = ($esxcli.network.nic.get($VMNic.Name)).DriverInfo $NicInfo.Driver + "," + $NicInfo.Version + "," + $NicInfo.FirmWareVersion } #$Nics = $esxcli.network.nic.list.invoke() #foreach ($Nic in $Nics) # { # $NicInfo = $esxcli.network.nic.get.invoke($Nic.Name).driverinfo # $NicInfo.Driver + "," + $NicInfo.Version + "," + $NicInfo.FirmWareVersion # } $VmHostresult = New-Object PSObject $VmHostresult | add-member -MemberType NoteProperty -Name "Name" -Value $vmhostname $VmHostresult | add-member -MemberType NoteProperty -Name "Management IP" -Value $ManagementIP $VmHostresult | add-member -MemberType NoteProperty -Name "PowerState" -Value $vmhost.PowerState $VmHostresult | add-member -MemberType NoteProperty -Name "Manufacturer" -Value $details.VendorName $VmHostresult | add-member -MemberType NoteProperty -Name "Model" -Value $details.ProductName $VmHostresult | add-member -MemberType NoteProperty -Name "Service_Tag" -Value $details.SerialNumber $VmHostresult | add-member -MemberType NoteProperty -Name "BiosVersion" -Value $biosfwv $VmHostresult | add-member -MemberType NoteProperty -Name "BiosDate" -Value $biosfwd $VmHostresult | add-member -MemberType NoteProperty -Name "ProcessorType" -Value $VMHost.ProcessorType $VmHostresult | add-member -MemberType NoteProperty -Name "CPU_Sockets" -Value $HostCPU $VmHostresult | add-member -MemberType NoteProperty -Name "CPU_core_per_socket" -Value $HostCPUcore $VmHostresult | add-member -MemberType NoteProperty -Name "Logical_CPUs" -Value $vmhost.Numcpu $VmHostresult | add-member -MemberType NoteProperty -Name "TotalHost_Mhz" -Value $vmhost.CPUTotalMhz $VmHostresult | add-member -MemberType NoteProperty -Name "Memory(GB)" -Value $TotalMemory $VmHostresult | add-member -MemberType NoteProperty -Name "Esxi-Version" -Value $vmhost.Version $VmHostresult | add-member -MemberType NoteProperty -Name "Build-Number" -Value $vmhost.Build $VMHostresult | add-member -MemberType NoteProperty -Name "Physical-Nics" -Value $vmhost.ExtensionData.summary.hardware.NumNics $VMHostresult | add-member -MemberType NoteProperty -Name "SSH-Enabled" -Value $SSHservice $VMHostresult | add-member -MemberType NoteProperty -Name "Uptime" -Value $UPtime $VMHostresult | add-member -MemberType NoteProperty -Name "Syslog-Server" -Value $syslog $VmHostresult | Add-Member -MemberType NoteProperty -Name "NTP-Server" -Value $ntpServerList $VmHostresult | Add-Member -MemberType NoteProperty -Name "NTP-Service" -Value $NTPservice $VmHostresult | Add-Member -MemberType NoteProperty -Name "Scratch-Config" -Value $Scratch $VmHostresult | Add-Member -MemberType NoteProperty -Name "ATSValue" -Value $ATSValue $VmHostresult | Add-Member -MemberType NoteProperty -Name "ATSValueonVMFS3" -Value $ATSValueonVMFS3 $VmHostresult | Add-Member -MemberType NoteProperty -Name "HardwareAccelratedLock" -Value $HALocking $VmHostresult | Add-Member -MemberType NoteProperty -Name "Datamover-HAMove" -Value $HAMove $VmHostresult | Add-Member -MemberType NoteProperty -Name "Datamover-HAInIt" -Value $HAInIt $VmHostresult | Add-Member -MemberType NoteProperty -Name "DisabledProtocols" -Value $DisabledProtcols $VmHostresult | Add-Member -MemberType NoteProperty -Name "LRO-Value" -Value $LRO $VmHostresult | Add-Member -MemberType NoteProperty -Name "TSO-Value" -Value $TSO $VmHostresult | Add-Member -MemberType NoteProperty -Name "vMotionStatus" -Value $vmotion #$objOneNic | Add-Member -type NoteProperty -name Host_Name -Value $VMHost.Name #$objOneNic | Add-Member -type NoteProperty -name VMNic_Name -Value $VMNic.Name #$objOneNic | Add-Member -type NoteProperty -name DriverName -Value $objDriverInfo.Driver #$objOneNic | Add-Member -type NoteProperty -name DriverVersion -Value $objDriverInfo.Version #$objOneNic | Add-Member -type NoteProperty -name FirmwareVersion -Value $objDriverInfo.FirmwareVersion $VmHostresult | Add-Member -MemberType NoteProperty -Name "NIC-Driver" -Value $NicInfo.Driver $VmHostresult | Add-Member -MemberType NoteProperty -Name "NIC-Driver-Version" -Value $NicInfo.Version $VmHostresult | Add-Member -MemberType NoteProperty -Name "NIC-Firmware-Version" -Value $NicInfo.FirmwareVersion $VmHostresult | Add-Member -MemberType NoteProperty -Name "HBA-Adapter" -Value $hbaadapter $VmHostresult | Add-Member -MemberType NoteProperty -Name "HBA-Driver" -Value $hbafirmware $VmHostresult | Add-Member -MemberType NoteProperty -Name "HBA-Driver-Version" -Value $hbadriver #$VmHostresult | Add-Member -MemberType NoteProperty -Name "HBA-Firmware-Version" -Value $hbainfo.FirmWareVersion #$VmHostresult | Add-Member -MemberType NoteProperty -Name "HBA-PortState" -Value $hbaportState #$VmHostresult | Add-Member -MemberType NoteProperty -Name "LUN-ID" -Value $datastore.DeviceDisplayName #$VmHostresult | Add-Member -MemberType NoteProperty -Name "MultipathPolicy" -Value $datastore.PathSelectionPolicy $VmHostresult | Add-Member -MemberType NoteProperty -Name "userslist" -Value $Users $VmHostresult | Add-Member -MemberType NoteProperty -Name "Firewall-ssh" -Value $sshfirewall $VmHostresult | Add-Member -MemberType NoteProperty -Name "Firewall-Vsphere" -Value $vsphereFirewall $VmHostresult | Add-Member -MemberType NoteProperty -Name "Raidcontroller" -Value $Raidcontroller $VmHostresult | Add-Member -MemberType NoteProperty -Name "ntp" -Value $ntp $VmHostresult | Add-Member -MemberType NoteProperty -Name "powerpolicy" -Value $powerpolicy $VmHostresult | Add-Member -MemberType NoteProperty -Name "lpfcQdepth" -Value $lpfcQdepth $VmHostresult | Add-Member -MemberType NoteProperty -Name "lpfcloginretry" -Value $lpfcretry $VmHostresult | Add-Member -MemberType NoteProperty -Name "qlogicqdepth" -Value $qlogicqdepth $VmHostresult | Add-Member -MemberType NoteProperty -Name "qlogicloginretry" -Value $qlogicretry $VmHostresult } $VmHostresult | Export-Csv C:\Users\bhanu.61120\Desktop\test.csv #$VmHostresult | Out-File -FilePath C:\Users\bhanu.61120\Desktop\$vmhostname.txt | Out-String Disconnect-VIServer -Confirm:$False -ErrorAction SilentlyContinue Function Read-OpenFileDialog([string]$WindowTitle, [string]$InitialDirectory, [string]$Filter = "All files (*.*)|*.*", [switch]$AllowMultiSelect) { Add-Type -AssemblyName System.Windows.Forms $openFileDialog = New-Object System.Windows.Forms.OpenFileDialog $openFileDialog.Title = $WindowTitle if (![string]::IsNullOrWhiteSpace($InitialDirectory)) { $openFileDialog.InitialDirectory = $InitialDirectory } $openFileDialog.Filter = $Filter if ($AllowMultiSelect) { $openFileDialog.MultiSelect = $true } $openFileDialog.ShowHelp = $true # Without this line the ShowDialog() function may hang depending on system configuration and running from console vs. ISE. $openFileDialog.ShowDialog() > $null if ($AllowMultiSelect) { return $openFileDialog.Filenames } else { return $openFileDialog.Filename } } $master = Read-OpenFileDialog $output = Read-OpenFileDialog Compare-Object -ReferenceObject $master -DifferenceObject $output -IncludeEqual -PassThru | Where { $_.SideIndicator -ne "==" } | Export-csv C:\users\bhanu.61120\Desktop\diff.csv -NoTypeInformation