PowerShell Script - Scan Domain and List Drives
PowerShell script to scan all domain computers and list the drives connected to them. The script exports the results to CSV file.
- See the PowerShell script to see list the local drives:
Listing Drives with Powershell - superuser (kbsuperuser.com)
- This script scan the domain get the results for all domain computers. Quick Link to PowerShell Script:
powershell/list_drives.ps1 at main · kbsuperuser/powershell (github.com)
-------*******-------
<#
.SYNOPSIS
List Drives
.DESCRIPTION
This PowerShell script scan the domain and list drives connected to computers. Scripts export the results to CSV file. Update the target path before running. The execution time of the scripts depends on range of network and speed. Priviligied account is needed to use the script.
.EXAMPLE
PS> ./list drives
.LINK
https://github.com/kbsuperuser/powershell
.NOTES
Author: kbsuperuser.com | License: CC0
#>
$computers = Get-ADComputer -Filter * | Select-Object -ExpandProperty Name
$output = @()
foreach ($computer in $computers) {
try {
$drives = Get-WmiObject -Class Win32_LogicalDisk -ComputerName $computer
foreach ($drive in $drives) {
$driveInfo = [PSCustomObject]@{
ComputerName = $computer
DeviceID = $drive.DeviceID
VolumeName = $drive.VolumeName
FreeSpace = $drive.FreeSpace
Size = $drive.Size
}
$output += $driveInfo
}
} catch {
Write-Error "Unable to retrieve drive information from $computer"
}
}
$output | Export-Csv -Path "C:\path\to\drives.csv" -NoTypeInformation
-------*******-------
What's Your Reaction?