Skip to content

NKCODE TECH GEEK ZONE

  • RSS - Posts
Menu
  • Home
  • Cloud
    • Azure
    • Alibaba
    • AWS
  • Hardware
  • Linux
  • Network
  • Security
  • Windows Client / Servers
    • SQL
    • Windows Client OS
      • Windows 10
    • Windows Servers
      • Windows 2008R2
      • Windows Server 2012R2
      • Windows Server 2016
      • Windows Server 2019
  • VMWARE
  • Free Tools
  • About Me
    • Disclaimer
Menu

Find VMs with unwanted devices in VMWare

Posted on May 1, 2021

Introduction:

As an administrator for a vSphere environment, you may come across situations where you have a lot of  VMs configured with unnecessary hardware like a USB device, a Floppy disk or a serial device.

The presence of such devices can impact the efficiency of DRS leading to the imbalanced cluster. In a large-scale environment, it can be difficult to find and fix such VMs. The code below provides an ability to create a CSV report for the device specified ($hwtype)

Code:

Start-Transcript -Append -Path “$env:USERPROFILE\Documents\usbfinder.log”

$vCenterIP = Read-Host “Enter vCenter IP or Name where the operation needs to be executed”

Connect-VIServer $vCenterIP

echo “VM Name,HW Label,HW Summary” | out-file “$env:USERPROFILE\Documents\VMsWithUsb.csv”

$VMs = Get-VM

#update this variable to change the type of hardware “floppy” or “serial” or “usb”

$hwtype = “usb”

foreach ($VM in $vms)

{

$VMname = $VM.Name

$hardware=(Get-VM $VMname | Get-View).Config.Hardware.Device | Select -Expand DeviceInfo | Select Label, Summary | where {$_.Label –match $hwtype}

$Lable = $hardware.Label

$Summary = $hardware.Summary

if ($Lable -and $Summary){

echo “$VMname,$Lable,$Summary” | out-file -Append “$env:USERPROFILE\Documents\VMsWithUsb.csv”

}

}

Disconnect-VIServer -Server $vCenterIP -Confirm:$false

stop-Transcript

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

Welcome to Teck Geek Zone

Alibaba & Azure Cloud with a free trial worth $200-1200 USD Click below Cloud Providers

  • Securing Your Cloud Environment with Alibaba Cloud Firewall
  • 🚢 Sailing into the Data Age: How Cloud and IoT are Revolutionizing the Marine Industry
  • What is Azure Grafana? A Comprehensive Guide to Monitoring and Visualization
  • 🔐 How to Enable Virtualization-Based Security (VBS) for Windows Workloads in VMware Cloud Foundation and vSphere
  • Microsoft’s Azure SRE Agent: AI-Powered Reliability Engineering

Categories

  • Cloud (186)
    • Alibaba (39)
    • AWS (39)
    • Azure (114)
  • Free Tools (5)
  • Hardware (17)
  • Linux (13)
  • Network (28)
  • Security (21)
  • VMWARE (54)
  • Windows OS (44)
    • Windows 10 (7)
  • Windows Servers (69)
    • SQL (3)
    • Windows 2008R2 (7)
    • Windows Server 2012R2 (15)
    • Windows Server 2016 (20)
    • Windows Server 2019 (10)

Subscribe to our newsletter

©2025 NKCODE TECH GEEK ZONE | Design: Newspaperly WordPress Theme
%d