Hi,
I am trying to unmount ISO from all the VMs, some of the VMs are asking for question to unmount, I tried the below and getting below error
Please help
Get-CDDrive App123 | Set-CDDrive -NoMedia -Confirm:$false | Set-VMQuestion -Option "Yes" -Confirm:$false
Error:
Set-VMQuestion : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the
parameters that take pipeline input.
At line:1 char:70
+ ... oMedia -Confirm:$false | Set-VMQuestion -Option "Yes" -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (CD/DVD drive 1:PSObject) [Set-VMQuestion], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVMQuestion
You should use the function like this
Get-VM mysftp | where { Get-CDDrive | where { $_.IsoPath -ne $null } } | Set-CDDriveAndAnswer
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That is not how Set-VMQuestion works, it expect an object that is returned by Get-VMQuestion.
See Example 3 on the Set-VMQuestion help.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I tried as below and getting the error
Get-VM App23| Get-CDDrive | Where {$_.ISOPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false | Get-VMQuestion | Set-VMQuestion -DefaultOption
Set-CDDrive : 07/09/2019 1:46:33 AM | Set-CDDrive | Operation is not valid due to the current state of the object. |
At line:1 char:69
+ ... {$_.ISOPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false | Get-V ...
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
+ CategoryInfo | : NotSpecified: (:) [Set-CDDrive], VimException | |
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetCDDrive |
You first have to answer the question before changing any settings on the CDDrive.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Only after issue this command, it asks for the question till then, I dont see question asked
Get-VM App23| Get-CDDrive | Where {$_.ISOPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false
I see, in that case you might want to give my Answer The Question! a try.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
When I used the script, it works, it changes to client device but getting the error
Set-CDDrive : 07/09/2019 4:27:57 AM | Set-CDDrive | Operation is not valid due to the current state of the object. |
At D:\myreports\Unmount_CD.ps1:53 char:1
+ Set-CDDrive -CD $cd -NoMedia -Confirm:$false -ErrorAction Stop
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo | : NotSpecified: (:) [Set-CDDrive], VimException | |
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetCDDrive |
Can you try changing that -ErrorAction Stop into -ErrorAction SilentlyContinue?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Below command works fine for one VM. But If I had to perform on multiple VMs, it is not working
Working :: Set-CDDriveAndAnswer -Name mytestvm
Not Working :: Get-VM mysftp | Get-CDDrive | where {$_.IsoPath -ne $null} | Set-CDDriveAndAnswer
Get-VM : 09-07-2019 17:32:22 | Get-VM | VM with name 'CD/DVD drive 1' was not found using the specified filter(s). |
At D:\Unmount_ISO.ps1:49 char:7
+ $vm = Get-VM -Name $_
+ | ~~~~~~~~~~~~~~~ | |
+ CategoryInfo | : ObjectNotFound: (:) [Get-VM], VimException | |
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM |
Get-CDDrive : Cannot validate argument on parameter 'VM'. The argument is null. Provide a valid value for the
argument, and then try running the command again.
At D:\Unmount_ISO.ps1:50 char:23
+ $cd = Get-CDDrive -VM $vm
+ | ~~~ | |
+ CategoryInfo | : InvalidData: (:) [Get-CDDrive], ParameterBindingValidationException | |
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDev |
ice.GetCDDrive
Set-CDDrive : Cannot validate argument on parameter 'CD'. The argument is null. Provide a valid value for the
argument, and then try running the command again.
At D:\Unmount_ISO.ps1:53 char:17
+ Set-CDDrive -CD $cd -NoMedia -Confirm:$false -ErrorAction SilentlyCon ...
+ | ~~~ | |
+ CategoryInfo | : InvalidData: (:) [Set-CDDrive], ParameterBindingValidationException | |
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDev |
ice.SetCDDrive
You are piping the output of a Get-CDDrive to the function, that will not work.
You can pipe objects from Get-VM to the function.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD, could you please help me on this, I didnt get.
You should use the function like this
Get-VM mysftp | where { Get-CDDrive | where { $_.IsoPath -ne $null } } | Set-CDDriveAndAnswer
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
getting the below error
Get-VM mysftp | where { Get-CDDrive | where { $_.IsoPath -ne $null } } | Set-CDDriveAndAnswer
Get-CDDrive : 09-07-2019 18:54:01 | Get-CDDrive | Please specify at least one of the following: VirtualMachine, Template |
or Snapshot.
At D:\Unmount_ISO.ps1:62 char:27
+ Get-VM jivasftp | where { Get-CDDrive | where { $_.IsoPath -ne $null ...
+ | ~~~~~~~~~~~ | |
+ CategoryInfo | : InvalidArgument: (:) [Get-CDDrive], ViError | |
+ FullyQualifiedErrorId : Core_VirtualDeviceGetter_GetMoListFromCmdletParameter_InsufficientParameters,VMware.VimA |
utomation.ViCore.Cmdlets.Commands.VirtualDevice.GetCDDrive
Thanks a lot LucD,
I was able to fix the issue
Get-VM | where { Get-CDDrive $_ | where { $_.IsoPath -ne $null } } | Set-CDDriveAndAnswer
As always, you are simply superb