Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for iscdwriter.ps

(view source code of iscdwriter.ps as plain text)

  1. param( [string]$drive = "" )
  2.  
  3. [int]$Script:rc = 0
  4.  
  5.  
  6. function IsOpticalWriter {
  7. 	param( [string]$drive )
  8. 	$iscdrom = $false
  9. 	$isdrive = $false
  10. 	$iswriter = $false
  11. 	[int]$Local:rc = Get-Variable -Name rc -Scope Script -ValueOnly
  12. 	foreach ( $_ in Get-WmiObject -Query "SELECT * FROM Win32_LogicalDisk WHERE DeviceID='$drive'" ) {
  13. 		$isdrive = $true
  14. 	}
  15. 	foreach ( $cdromdrive in Get-WmiObject -Query "SELECT Capabilities FROM Win32_CDROMDrive WHERE Drive='$drive'" ) {
  16. 		$iscdrom = $true
  17. 		foreach ( $capability in $cdromdrive.Capabilities ) {
  18. 			if ( $capability -eq 4 ) {
  19. 				$iswriter = $true
  20. 				$Local:rc += 1
  21. 				Set-Variable -Name rc -Scope Script -Value $Local:rc
  22. 			}
  23. 		}
  24. 	}
  25. 	if ( $iswriter ) {
  26. 		Write-Host "Drive $drive is a CD/DVD writer"
  27. 	} elseif ( $iscdrom ) {
  28. 		Write-Host "Though drive $drive is an optical drive, it is NOT a CD/DVD writer"
  29. 	} elseif ( $isdrive ) {
  30. 		Write-Host "Drive $drive is NOT an optical drive, so it cannot be a CD/DVD writer"
  31. 	} else {
  32. 		Write-Host "$drive is NOT a valid drive letter for this computer"
  33. 		$Local:rc = -1
  34. 		Set-Variable -Name rc -Scope Script -Value $Local:rc
  35. 	}
  36. }
  37.  
  38.  
  39. if ( $drive -eq "" ) {
  40. 	Write-Host
  41. 	foreach ( $cdromdrive in Get-WmiObject -Query "SELECT Drive FROM Win32_CDROMDrive" ) {
  42. 		IsOpticalWriter ( $cdromdrive.Drive )
  43. 	}
  44. } elseif ( $drive -inotmatch "^[A-Z]:$" ) {
  45. 	Write-Host "`nIsCDWriter.ps1,  Version 1.00"
  46. 	Write-Host "Check whether specified drive is a CD/DVD writer or not`n"
  47. 	Write-Host "Usage:  IsCDWriter.ps1  [ drive ]`n"
  48. 	Write-Host "where:  `"drive`"         is the drive to test`n"
  49. 	Write-Host "Written by Rob van der Woude"
  50. 	Write-Host "http://www.robvanderwoude.com`n"
  51. 	exit -1
  52. } else {
  53. 	IsOpticalWriter $drive.ToUpper( )
  54. }
  55.  
  56. if ( $drive -eq "" ) {
  57. 	[string]$s = "s"
  58. 	Write-Host "`n$Script:rc" "CD/DVD writer" -NoNewline
  59. 	if ( $Script:rc -ne 1  ) { Write-Host "s" -NoNewline }
  60. 	Write-Host " found`n"
  61. }
  62.  
  63. exit $Script:rc
  64.  

page last modified: 2024-04-16; loaded in 0.0088 seconds