-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindDrives.ps1
48 lines (40 loc) · 1.59 KB
/
FindDrives.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
36
37
38
39
40
41
42
43
44
45
46
47
48
# Define the output file path
$outputFile = "C:\CSVReports\DiskDrives.csv"
# Remove the existing output file if it exists
if (Test-Path $outputFile) {
Remove-Item $outputFile
}
# Use a StreamReader to read the servers file
$reader = [System.IO.StreamReader]::new("C:\scripts\servers.txt")
# Process servers in batches
$batchSize = 10
$batch = @()
while ($true) {
$server = $reader.ReadLine()
if ($server -eq $null) {
# Process remaining servers in the last batch
if ($batch.Count -gt 0) {
$results = Invoke-Command -ComputerName $batch -ScriptBlock {
Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3" |
Select-Object @{Name='SystemName';Expression={$env:COMPUTERNAME}},
DeviceID,
@{Name='Size(GB)';Expression={[int]($_.Size / 1GB)}}
}
$results | Export-Csv $outputFile -Append -NoTypeInformation
}
break
}
$batch += $server
if ($batch.Count -eq $batchSize) {
$results = Invoke-Command -ComputerName $batch -ScriptBlock {
Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3" |
Select-Object @{Name='SystemName';Expression={$env:COMPUTERNAME}},
DeviceID,
@{Name='Size(GB)';Expression={[int]($_.Size / 1GB)}}
}
$results | Export-Csv $outputFile -Append -NoTypeInformation
$batch = @()
}
}
$reader.Close()
Write-Host "Disk information has been exported to $outputFile"