Forked from jasongaylord/Get-ADComputerCDRomInfo.ps1
Last active
August 29, 2015 13:57
-
-
Save elovelan/9900582 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function PrintDetails | |
{ | |
Param ( | |
$ComputerName, | |
$DriveLetter = "", | |
$VolumeName = "", | |
$Error = "" | |
) | |
$obj = New-Object PSObject | |
$obj | Add-Member -MemberType NoteProperty -Name Computer ($ComputerName) | |
$obj | Add-Member -MemberType NoteProperty -Name DriveLetter ($DriveLetter) | |
$obj | Add-Member -MemberType NoteProperty -Name VolumeName ($VolumeName) | |
$obj | Add-Member -MemberType NoteProperty -Name Error ($Error) | |
Write-Output $obj | |
} | |
Function PrintDriveDetails | |
{ | |
Param ( $ComputerName = 'localhost' ) | |
# Get all removable (2) or cd-rom (5) drives | |
Get-WmiObject ` | |
-ComputerName $computerName ` | |
-Class Win32_LogicalDisk ` | |
-Filter "DriveType = 2 or DriveType = 5" ` | |
-ErrorAction Stop ` | |
| ForEach-Object { | |
# Populate the properties | |
$driveLetter = $_.DeviceID | |
$volumeName = $_.VolumeName | |
$err = "" | |
if (!$driveLetter) | |
{ | |
$err = "No drive found." | |
} | |
PrintDetails ` | |
-ComputerName $computerName ` | |
-DriveLetter $driveLetter ` | |
-VolumeName $volumeName ` | |
-Error $err | |
} | |
} | |
Function Get-ADComputerCDRomInfo | |
{ | |
# Search Active Directory for computers | |
([adsisearcher]"objectcategory=computer").findall() | ForEach-Object { | |
$computerName = ([adsi]$_.path).Name; | |
Try { | |
PrintDriveDetails -ComputerName $computerName | |
} | |
Catch | |
{ | |
PrintDetails ` | |
-ComputerName $computerName ` | |
-Error $Error[0].ToString() | |
} | |
} | |
} | |
# Execute this function | |
Get-ADComputerCDRomInfo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DRYed up a bit