Last active
October 11, 2018 22:08
-
-
Save chaderoth/bb162f90a415cd43d48f4926f716ad9a 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
############################################ | |
# Get User Credentials To Pass To Guest OS # | |
############################################ | |
$Creds = Get-Credential | |
###################################################################### | |
# Get All CentOS Linux VMs With A Configured ISO Path # | |
# Use Invoke-VMScript To Eject The Mounted Media Inside The Guest OS # | |
# Disconnect The ISO From The VM # | |
###################################################################### | |
Foreach ($VM in (Get-VM | Where-Object {$_.Guest.OSFullName -like "*CentOS*"} | Get-CDDrive | Where-Object {$_.IsoPath -ne $null} | Select-Object *)){ | |
Write-Host "Ejecting CD-ROM In Guest For "$VM.Parent.Name"" | |
Invoke-VMScript -ScriptText "eject" -ScriptType Bash -VM $VM.Parent.Name -GuestCredential $Creds | |
Write-Host "Disconnecting The ISO From "$VM.Parent.Name"" | |
Get-CDDrive -VM $VM.Parent.Name | Set-CDDrive -NoMedia -Confirm:$false > $null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment