Import-Module ActiveDirectory
$Servers = Get-ADcomputer -Filter {OperatingSystem -like "Server"} -Properties Name, OperatingSystem | Select Name
$diskReport = Foreach($Server in $Servers)
{
#$Status = "Offline"
$Name = $Server.Name
#Make sure server is online
if(Test-Connection -ComputerName $Name -ErrorAction SilentlyContinue)
{
#Get only 10%
Get-WMIObject win32_logicaldisk -ComputerName $Name -Filter "DriveType=3" -ErrorAction SilentlyContinue
}
else
{
Write-Output $Name + "Offline/Unreachable"
}
}
$servers = $diskreport | Select-Object @{Label = "Server Name";Expression = {$.SystemName}},@{Label = "Drive Letter";Expression = {$.DeviceID}}
I'm looking to use export-csv on $servers so that I will get the below output:
Server Name OS Drives
xyz Windows Server 2019 C,D,E
TIA