# Stuck and not working

**URL:** <https://forums.powershell.org/t/stuck-and-not-working/12664>\
**Category:** PowerShell Help\
**Created:** [June 3, 2019, 8:23pm UTC](https://forums.powershell.org/t/stuck-and-not-working/12664 "2019-06-03T20:23:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![docrst](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@docrst](https://forums.powershell.org/u/docrst)\
**Post date:** [June 3, 2019, 8:23pm UTC](https://forums.powershell.org/t/stuck-and-not-working/12664/1 "2019-06-03T20:23:37Z")

</div>

I can not get the Hyper-V / vMWare drive type part to work and gave my self a migrain looking at it, PLEASE HELP!.

```
##==============================================================================
## START
##==============================================================================
#>
clear
#---------- Configurations - Start.
# $cre = get-Credential # This user account should be Adminstrator.
$Servers = get-Content "list.txt" # Replace this with your TXT file containg Server names.
# Do not change below this line.
$OS = (gwmi win32_operatingsystem).caption
$MediaType = gwmi -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage
$HVDrive = Get-VMHardDiskDrive | Where-Object { $_.DriveType -eq 1 }
$LogicalDisks = gwmi Win32_LogicalDisk | Where-Object { $_.DriveType -eq 2 }
$LocalHDisks = $LogicalDisks | Where-Object { $_.DriveType -eq 3 }
$RemoteDrives = gwmi Win32_LogicalDisk | Where-Object { $_.DriveType -eq 4 }
$OpticalDrives = gwmi Win32_CDRomDrive | Where-Object { $_.DriveType -eq 5 }
$HVDrive = Get-VM | Select-Object VMID | Get-VHD | Select-Object 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.
Clear-Host
#---------- The report - Start.
Write-Host " 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 Win32_LogicalDisk -computerName $servers |
Select-Object `
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 $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 Win32_LogicalDisk -computerName $servers |
Select-Object `
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='Above 10%';E={if($_.FreeSpace/$_.Size -lt .10){'Below 10%'}else{'GOOD'}}} | Write-Output | Format-Table
#---------- Wright to Screen - END.
# Show Progress Bar - START
for($i = 1; $i -lt 101; $i++ ) {write-progress Updating progress-> -perc $i} for($i = 1; $i -lt 101; $i++ ) { write-progress Updating progress -percentcomplete $i -id 1}
# Show Progress Bar - END
Write-Host " Your Report finished at: $(((get-date).ToUniversalTime()).ToString("yyyy-MM-dd"))."
#---------- The Report - End.
```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 20, 2019, 5:35pm UTC](https://forums.powershell.org/t/stuck-and-not-working/12664/2 "2019-06-20T17:35:39Z")

</div>

You have a lot of useless code in your script and your script is really badly formatted. You should read the [The Unofficial PowerShell Best Practices and Style Guide](https://poshcode.gitbooks.io/powershell-practice-and-style/).

You should split your script into smaller pieces. This way it would be easier to read and to debug.

---

<div class="post-metadata">

**Author:** ![bdevogt](https://avatars.discourse-cdn.com/v4/letter/b/eada6e/32.png) [@bdevogt](https://forums.powershell.org/u/bdevogt)\
**Post date:** [June 24, 2019, 8:31am UTC](https://forums.powershell.org/t/stuck-and-not-working/12664/3 "2019-06-24T08:31:56Z")

</div>

First thing my PSSharper sees is a {$\_VhdFormat} not divined on row 36 and 66

and please read the suggestions that Olaf pointed out

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:32pm UTC](https://forums.powershell.org/t/stuck-and-not-working/12664/4 "2024-05-16T20:32:04Z")

</div>

Closed on May 16, 2024, 8:32pm UTC


