Skip to content

Retrieves the used and unused drive-letters from a computer (a Windows PowerShell script).

License

Notifications You must be signed in to change notification settings

auberginehill/get-unused-drive-letters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Get-UnusedDriveLetters.ps1

OS: Windows
Type: A Windows PowerShell script
Language: Windows PowerShell
Description: Get-UnusedDriveLetters uses Windows Management Instrumentation (WMI) to retrieve basic computer information and .NET Framework to determine which drive-letters are unused by the system. This script is based on ps1's PowerShell Tip "Enumerating Drive Letters".
Homepage: https://github.com/auberginehill/get-unused-drive-letters
Short URL: http://tinyurl.com/zuejxph
Version: 1.3
Sources:
Emojis: Emoji Table
ps1 and Sylvain LESIRE: Enumerating Drive Letters
clayman2: Disk Space
Downloads: For instance Get-UnusedDriveLetters.ps1. Or everything as a .zip-file.

Screenshot

        screenshot

Outputs

➡️
  • Displays general computer information (such as Computer Name, Manufacturer, Computer Model, System Type, Domain Role, Product Type, Chassis, PC Type, whether the machine is a laptop or not (based on the chassis information), CPU, Operating System, Architecture, SP Version, Build Number, Memory, Processors, Cores, Country Code, Install Date, Last BootUp, UpTime, Date, Daylight Bias, Time Offset (Current), Time Offset (Normal), Time (Current), Time (Normal), Daylight In Effect, Time Zone, OS Version, BIOS Version, Serial Number (BIOS), Serial Number (Mother Board), Serial Number (OS), UUID), a list of optical drives, a partition table, volumes list and the used and unused drive letters in console. In addition to that...

  • Four pop-up windows (Out-GridView):
    1. Name Description
      $partition_table_selection A partition table, which doesn't include the optical drives
      $used_selection Lists all the used drive letters, but doesn't include the boot sector
      $volumes_selection Lists all the used drive letters (including the boot sector)
      $unused A list of all unused drive letters

  • And also one txt-file and one CSV-file at $path.
    1. Path Type Name
      $env:temp\unused_drive_letters.txt txt-file unused_drive_letters.txt
      $env:temp\used_drive_letters.csv CSV-file used_drive_letters.csv

Notes

⚠️
  • Please note that the two files are created in a directory, which is specified with the $path variable (at line 10).

  • The $env:temp variable points to the current temp folder. The default value of the $env:temp variable is C:\Users\<username>\AppData\Local\Temp (i.e. each user account has their own separate temp folder at path %USERPROFILE%\AppData\Local\Temp). To see the current temp path, for instance a command

    [System.IO.Path]::GetTempPath()

    may be used at the PowerShell prompt window [PS>]. To change the temp folder for instance to C:\Temp, please, for example, follow the instructions at Temporary Files Folder - Change Location in Windows, which in essence are something along the lines:
    1. Right click on Computer and click on Properties (or select Start → Control Panel → System). In the resulting window with the basic information about the computer...
    2. Click on Advanced system settings on the left panel and select Advanced tab on the resulting pop-up window.
    3. Click on the button near the bottom labeled Environment Variables.
    4. In the topmost section labeled User variables both TMP and TEMP may be seen. Each different login account is assigned its own temporary locations. These values can be changed by double clicking a value or by highlighting a value and selecting Edit. The specified path will be used by Windows and many other programs for temporary files. It's advisable to set the same value (a directory path) for both TMP and TEMP.
    5. Any running programs need to be restarted for the new values to take effect. In fact, probably also Windows itself needs to be restarted for it to begin using the new values for its own temporary files.

Examples

📖 To open this code in Windows PowerShell, for instance:

  1. ./Get-UnusedDriveLetters
    Run the script. Please notice to insert ./ or .\ before the script name.
  2. help ./Get-UnusedDriveLetters -Full
    Display the help file.
  3. Set-ExecutionPolicy remotesigned
    This command is altering the Windows PowerShell rights to enable script execution. Windows PowerShell has to be run with elevated rights (run as an administrator) to actually be able to change the script execution properties. The default value is "Set-ExecutionPolicy restricted".

    Parameters:

      Restricted Does not load configuration files or run scripts. Restricted is the default execution policy.
      AllSigned Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
      RemoteSigned Requires that all scripts and configuration files downloaded from the Internet be signed by a trusted publisher.
      Unrestricted Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.
      Bypass Nothing is blocked and there are no warnings or prompts.
      Undefined Removes the currently assigned execution policy from the current scope. This parameter will not remove an execution policy that is set in a Group Policy scope.

    For more information, please type "help Set-ExecutionPolicy -Full" or visit Set-ExecutionPolicy.

  4. New-Item -ItemType File -Path C:\Temp\Get-UnusedDriveLetters.ps1
    Creates an empty ps1-file to the C:\Temp directory. The New-Item cmdlet has an inherent -NoClobber mode built into it, so that the procedure will halt, if overwriting (replacing the contents) of an existing file is about to happen. Overwriting a file with the New-Item cmdlet requires using the Force.
    For more information, please type "help New-Item -Full".

Contributing

Find a bug? Have a feature request? Here is how you can contribute to this project:

contributing Bugs: Submit bugs and help us verify fixes.
Feature Requests: Feature request can be submitted by creating an Issue.
Edit Source Files: Submit pull requests for bug fixes and features and discuss existing proposals.

www

www Script Homepage
ps1 and Sylvain LESIRE: Enumerating Drive Letters
clayman2: Disk Space
Powershell - Get-WmiObject and ASSOCIATORS OF Statement
How to link the output from win32_diskdrive and win32_volume
Windows PowerShell Tip of the Week: More Fun with Dates (and Times)
Mapping VolumeID to Disk partition Using the DeviceIOControl API
Converting the FileSystemObject's GetDrive Method
Win32_SystemEnclosure class
Win32_ComputerSystem class
Win32_OperatingSystem class
ASCII Art: http://www.figlet.org/ and ASCII Art Text Generator

Related scripts

www Firefox Customization Files
Get-AsciiTable
Get-BatteryInfo
Get-ComputerInfo
Get-DirectorySize
Get-InstalledPrograms
Get-InstalledWindowsUpdates
Get-RAMInfo
Get-TimeDifference
Get-TimeZoneTable
Emoji Table
Java-Update
Rock-Paper-Scissors
Toss-a-Coin
Update-AdobeFlashPlayer

About

Retrieves the used and unused drive-letters from a computer (a Windows PowerShell script).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published