-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_drives.ps1
36 lines (32 loc) · 1.17 KB
/
list_drives.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<#
.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