scripting to tell me if a disc is a VMWARE or Hyper-V disk

Welcome Forums General PowerShell Q&A scripting to tell me if a disc is a VMWARE or Hyper-V disk

  • This topic has 1 reply, 2 voices, and was last updated 1 year ago by
    Participant
    .
Viewing 1 reply thread
  • Author
    Posts
    • #159894
      Participant
      Topics: 4
      Replies: 1
      Points: 21
      Rank: Member

      I can’t find any help to tell me how to modify my script to report if a drive is a vMWare or Hyper-V drive.

      #---------- functions - Start.
      function Where-OpticalDrives
      {
      <#
      .SYNOPSIS
      Describe purpose of "Where-OpticalDrives" in 1-2 sentences.
      
      .DESCRIPTION
      Add a more complete description of what the function does.
      
      .PARAMETER InputObject
      Describe parameter -InputObject.
      
      .EXAMPLE
      Where-OpticalDrives -InputObject Value
      Describe what this call does
      
      .NOTES
      Place additional notes here.
      
      .LINK
      URLs to related sites
      The first link is opened by Get-Help -Online Where-OpticalDrives
      
      .INPUTS
      List of input types that are accepted by this function.
      
      .OUTPUTS
      List of output types produced by this function.
      #>
      
      param
      (
      [Parameter(Mandatory = $true, ValueFromPipeline = $true, HelpMessage = 'Data to filter')]
      [Object]$InputObject
      )
      
      process
      {
      if ($InputObject.DriveType -eq 5)
      {
      $InputObject
      }
      }
      }
      
      function Where-RemoteDrives
      {
      <#
      .SYNOPSIS
      Describe purpose of "Where-RemoteDrives" in 1-2 sentences.
      
      .DESCRIPTION
      Add a more complete description of what the function does.
      
      .PARAMETER InputObject
      Describe parameter -InputObject.
      
      .EXAMPLE
      Where-RemoteDrives -InputObject Value
      Describe what this call does
      
      .NOTES
      Place additional notes here.
      
      .LINK
      URLs to related sites
      The first link is opened by Get-Help -Online Where-RemoteDrives
      
      .INPUTS
      List of input types that are accepted by this function.
      
      .OUTPUTS
      List of output types produced by this function.
      #>
      
      param
      (
      [Parameter(Mandatory = $true, ValueFromPipeline = $true, HelpMessage = 'Data to filter')]
      [Object]$InputObject
      )
      process
      {
      if ($InputObject.DriveType -eq 4)
      {
      $InputObject
      }
      }
      }
      
      function Where-LocalHDisks
      {
      <#
      .SYNOPSIS
      Describe purpose of "Where-LocalHDisks" in 1-2 sentences.
      
      .DESCRIPTION
      Add a more complete description of what the function does.
      
      .PARAMETER InputObject
      Describe parameter -InputObject.
      
      .EXAMPLE
      Where-LocalHDisks -InputObject Value
      Describe what this call does
      
      .NOTES
      Place additional notes here.
      
      .LINK
      URLs to related sites
      The first link is opened by Get-Help -Online Where-LocalHDisks
      
      .INPUTS
      List of input types that are accepted by this function.
      
      .OUTPUTS
      List of output types produced by this function.
      #>
      
      param
      (
      [Parameter(Mandatory = $true, ValueFromPipeline = $true, HelpMessage = 'Data to filter')]
      [Object]$InputObject
      )
      process
      {
      if ($InputObject.DriveType -eq 3)
      {
      $InputObject
      }
      }
      }
      
      function Where-LocalDisks
      {
      <#
      .SYNOPSIS
      Describe purpose of "Where-LocalDisks" in 1-2 sentences.
      
      .DESCRIPTION
      Add a more complete description of what the function does.
      
      .PARAMETER InputObject
      Describe parameter -InputObject.
      
      .EXAMPLE
      Where-LocalDisks -InputObject Value
      Describe what this call does
      
      .NOTES
      Place additional notes here.
      
      .LINK
      URLs to related sites
      The first link is opened by Get-Help -Online Where-LocalDisks
      
      .INPUTS
      List of input types that are accepted by this function.
      
      .OUTPUTS
      List of output types produced by this function.
      #>
      
      param
      (
      [Parameter(Mandatory = $true, ValueFromPipeline = $true, HelpMessage = 'Data to filter')]
      [Object]$InputObject
      )
      process
      {
      if ($InputObject.DriveType -eq 2)
      {
      $InputObject
      }
      }
      }
      #---------- functions - End.
      
      #---------- Configurations - Start.
      # $cre = get-Credential # This user account should be Adminstrator.
      $Servers = Get-Content -Path 'list.txt' # Replace this with your TXT file containg Server names.
      # Do not change below this line.
      $OS = (Get-WmiObject -Class win32_operatingsystem).caption
      $MediaType = Get-WmiObject -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage
      # $HVDrive = Get-VMHardDiskDrive | Where-Object { $_.DriveType -eq 1 }
      $LogicalDisks = Get-WmiObject -Class Win32_LogicalDisk | Where-LocalDisks
      $LocalHDisks = $LogicalDisks | Where-LocalHDisks
      $RemoteDrives = Get-WmiObject -Class Win32_LogicalDisk | Where-RemoteDrives
      $OpticalDrives = Get-WmiObject -Class Win32_CDRomDrive | Where-OpticalDrives
      # $HVDrive = Get-VM | Select-Object -ExpandProperty VMID | Get-VHD | Select-Object -ExpandProperty VhdFormat
      # Do not change above this line.
      $Records = 1000 # Sets Max Records
      $CSV = "DiskSpaceReport_$(((Get-Date).ToUniversalTime()).ToString('yyyy-MM-dd')).csv" # File to export to.
      #---------- Configurations - End.
      #---------- The report - Start.
      Write-Verbose -Message " Your Report started at: $(((Get-Date).ToUniversalTime()).ToString('yyyy-MM-dd'))."
      #---------- Wright to File - Start.
      #Get-WmiObject Win32_LogicalDisk -filter 'DriveType=3' -computerName $servers | ## use this if you want to show only Drive Type 3 drives.
      Get-WmiObject -Class Win32_LogicalDisk -ComputerName $Servers | Select-Object ` -Property SystemName, DeviceID, VolumeName,
      @{N = 'Size(MB)' ;E = {'{0:N2}' -f ($_.Size/1MB)}},
      @{N = 'FreeSpace(MB)' ;E = {'{0:N2}' -f ($_.FreeSpace/1MB)}},
      @{N = 'Used(MB)' ;E = {'{0:N2}' -f (($_.Size-$_.FreeSpace)/1MB)}},
      @{N = 'PercentFree' ;E = {'{0:P2}' -f ($_.FreeSpace/$_.Size)}},
      @{N = 'PercentUsed' ;E = {'{0:P2}' -f (($_.Size-$_.FreeSpace)/$_.Size)}},
      @{N = 'Drive Type' ;E = {switch ($_.DriveType) { 0{'(unknown)'} 2{'USB/FD'} 3{'HDD'} 4{'SSD'} 5{'CD/DVD/BD'} 6{'RAM disk'}}}},
      @{N = 'VM Drv' ;E = {if($hvdrive) {$_VhdFormat} else{'no VM Disk'}}},
      @{N = 'Operating System' ;E = {$OS}},
      @{N = 'Free Space (Warning)' ;E = {if($_.FreeSpace/$_.Size -lt .10){'Below 10%'}else{'GOOD'}}} | Export-Csv -Path $CSV -NoTypeInformation -Encoding UTF8 | Format-Table -AutoSize
      #---------- Wright to File - END.
      
      #---------- Wright to Screen - Start.
      #Get-WmiObject Win32_LogicalDisk -filter 'DriveType=3' -computerName $servers | ## use this if you want to show only Drive Type 3 drives.
      Get-WmiObject -Class Win32_LogicalDisk -ComputerName $Servers | Select-Object ` -Property SystemName, DeviceID, VolumeName,
      @{N = 'Size(MB)' ;E = {'{0:N2}' -f ($_.Size/1MB)}},
      @{N = 'FreeSpace(MB)' ;E = {'{0:N2}' -f ($_.FreeSpace/1MB)}},
      @{N = 'Used(MB)' ;E = {'{0:N2}' -f (($_.Size-$_.FreeSpace)/1MB)}},
      @{N = 'PercentFree' ;E = {'{0:P2}' -f ($_.FreeSpace/$_.Size)}},
      @{N = 'PercentUsed' ;E = {'{0:P2}' -f (($_.Size-$_.FreeSpace)/$_.Size)}},
      @{N = 'Drive Type' ;E = {switch ($_.DriveType) { 0{'(unknown)'} 2{'USB/FD'} 3{'HDD'} 4{'SSD'} 5{'CD/DVD/BD'} 6{'RAM disk'}}}},
      @{N = 'VM Drv' ;E = {if($hvdrive) {$_VhdFormat} else{'no VM Disk'}}},
      @{N = 'Operating System' ;E = {$OS}},
      @{N = 'Free Space (Warning)' ;E = {if($_.FreeSpace/$_.Size -lt .10){'Below 10%'}else{'GOOD'}}} | Export-Csv -Path $CSV -NoTypeInformation -Encoding UTF8 | Format-Table -AutoSize Write-Output | Format-Table
      #---------- Wright to Screen - END.
      
    • #162290
      Participant
      Topics: 5
      Replies: 2368
      Points: 5,987
      Helping Hand
      Rank: Community MVP

      … script to report if a drive is a vMWare or Hyper-V drive.

      … didn’t you ask this already time ago? Could you please describe a little more detailed what you’re trying to do … what should be the result … not the way you think you should do to accomplish your assignment.

Viewing 1 reply thread
  • The topic ‘scripting to tell me if a disc is a VMWARE or Hyper-V disk’ is closed to new replies.