You should work with a for-each loop to get this done. First get the computers from AD and get the disk details for each computer.
But be aware for the 'Get-PhysicalDisk' you have to connect to each machine remotely to get the disk details (https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/new-pssession?view=powershell-7.1). Instead of New-PSSession
maybe Invoke-Command
is an option as well (https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-7.1)
Also you have to deal with computers that are not reachable (not connected to the network, offline, ....) when the script is running. Otherwise New-PSSession
or Invoke-Command
will maybe throw an error.
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten