I am attempting to create a custom PS object to then export to an Excel document. I think I’m overcomplicating the task. Here is the current script that just prints the information I need:
$Server = Get-WmiObject -ComputerName Fileserver01 win32_logicaldisk -Filter DriveType=3
$date = date
Write-Host $date
Write-Host "Free Space on FileServer01 Drives:"
Foreach($drive in $Server){
Write-Host $drive.Name ($drive.Freespace / 1GB)
}
My initial idea was to feed each drive into a different array, then for each object in the array feed it into the PS object:
$Server = Get-WmiObject -ComputerName Fileserver01 win32_logicaldisk -Filter DriveType=3
$DriveSpace = @()
$date = date
Write-Host $date
Write-Host "Free Space on FileServer01 Drives:"
Foreach($drive in $Server){
$drive.Freespace += $DriveSpace
}
The above code just doesn’t add anything to the arrays, and I’m not sure what I’m doing wrong. Overall I have pretty much no experience exporting data, so if there’s an easier way of doing this, I will take any recommendations. My idea for the PS object would look like this:
$TimeStamp = [PSCustomObject]@{
Time = $date
C Drive = $drive[0].Freespace
D Drive = $drive[1].Freespace
}