Why the script is getting the following error?
Get-VM *jump01 | D:\SM\8VMConfig\BIOSForce.ps1 -PassThru
param(
[switch]$Disable,
[switch]$PassThru
)
if($_ -is [VMware.VimAutomation.Types.VirtualMachine])
{
trap { throw $_ }
$vmbo = New-Object VMware.Vim.VirtualMachineBootOptions
$vmbo.EnterBIOSSetup = $true
if($Disable)
{
$vmbo.EnterBIOSSetup = $false
}
$vmcs = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmcs.BootOptions = $vmbo
($_ | Get-View).ReconfigVM($vmcs)
if($PassThru)
{
Get-VM $_
}
}
else
{
Write-Error "Wrong object type. Only virtual machine objects are allowed."
}
D:\SM\8VMConfig\BIOSForce.ps1 : Wrong object type. Only virtual machine objects are allowed.
At line:1 char:53
+ Get-VM tajump01 | D:\BIOSForce.ps1 <<<< -PassThru
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,BIOSForce.ps1
This seems to be working
param( [switch]$Disable, [switch]$PassThru ) foreach($vm in $input){ if($vm -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl]) { trap { throw $_ } $vmbo = New-Object VMware.Vim.VirtualMachineBootOptions $vmbo.EnterBIOSSetup = $true if($Disable) { $vmbo.EnterBIOSSetup = $false } $vmcs = New-Object VMware.Vim.VirtualMachineConfigSpec $vmcs.BootOptions = $vmbo $vm.ExtensionData.ReconfigVM($vmcs) if($PassThru) { $vm } } else { Write-Error "Wrong object type. Only virtual machine objects are allowed." } }
I called it like this
Get-VM MyVM | D:\force-bios.ps1 -PassThru
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The script tests for the type of the parameter in
if($_ -is [VMware.VimAutomation.Types.VirtualMachine])
In the newer builds of PowerCLI that is not the correct name of the VirtualMachine type.
It should be
VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl
Try changing the line where the test is done into
if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl])
Which PowerCLI version are you running ? Do a
Get-PowerCLIVersion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Get-VM slwsavcjump01 | D:\BIOSForce.ps1 -PassThru
param(
[switch]$Disable,
[switch]$PassThru
)
if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl])
{
trap { throw $_ }
$vmbo = New-Object VMware.Vim.VirtualMachineBootOptions
$vmbo.EnterBIOSSetup = $true
if($Disable)
{
$vmbo.EnterBIOSSetup = $false
}
$vmcs = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmcs.BootOptions = $vmbo
($_ | Get-View).ReconfigVM($vmcs)
if($PassThru)
{
Get-VM $_
}
}
else
{
Write-Error "Wrong object type. Only virtual machine objects are allowed."
}
D:\SM\8VMConfig\BIOSForce.ps1 : Wrong object type. Only virtual machine objects are allowed.
At line:1 char:53
+ Get-VM slwsavcjump01 | D:\SM\8VMConfig\BIOSForce.ps1 <<<< -PassThru
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,BIOSForce.ps1
Just noticed, if you don't declare a parameter that is accepted through the pipeline, you have to use the $input variable.
So that line should be
if($input -is [VMware.VimAutomation.Types.VirtualMachine])
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What's the variable $input ? Sorry I'm not good with Powershell.
The $input variable is an automatic PowerShell variable, that contains the object you passed through the pipeline ('|').
In your script it will contain the object returned by the Get-VM cmdlet
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am getting this error message.
PowerCLI D:\> Get-VM test | D:\BIOSForce.ps1 -PassThru
D:\BIOSForce.ps1 : Wrong object type. Only virtual machine objects are allowed.
At line:1 char:31
+ Get-VM test | D:\BIOSForce.ps1 <<<< -PassThru
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,BIOSForce.ps1
Here is the script
param(
[switch]$Disable,
[switch]$PassThru
)
if($input -is [VMware.VimAutomation.Types.VirtualMachine])
{
trap { throw $_ }
$vmbo = New-Object VMware.Vim.VirtualMachineBootOptions
$vmbo.EnterBIOSSetup = $true
if($Disable)
{
$vmbo.EnterBIOSSetup = $false
}
$vmcs = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmcs.BootOptions = $vmbo
($_ | Get-View).ReconfigVM($vmcs)
if($PassThru)
{
Get-VM $_
}
}
else
{
Write-Error "Wrong object type. Only virtual machine objects are allowed."
}
There could be several reasons.
Is there a VM with that name . Is there an object that is returned ?
Is
Get-VM test
returning only 1 object ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes, there is only one object called test
I tried other virtual machines names, the error message is the same.
Let's check if the type is correct. Do a
Get-VM test | %{$_.GetType().FullName}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PowerCLI D:\> Get-VM test | %{$_.GetType().FullName}
VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl
Change the line
if($input -is [VMware.VimAutomation.Types.VirtualMachine])
to
if($input -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl])
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry, that doesn't work. I am still getting the same error message >.<
param(
[switch]$Disable,
[switch]$PassThru
)
if($input -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl])
{
trap { throw $_ }
$vmbo = New-Object VMware.Vim.VirtualMachineBootOptions
$vmbo.EnterBIOSSetup = $true
if($Disable)
{
$vmbo.EnterBIOSSetup = $false
}
$vmcs = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmcs.BootOptions = $vmbo
($_ | Get-View).ReconfigVM($vmcs)
if($PassThru)
{
Get-VM $_
}
}
else
{
Write-Error "Wrong object type. Only virtual machine objects are allowed."
}
Can you include a screenshot of what you actually entered at the PowerCLI prompt, and attach that .ps1 file ?
The error says there is an error in a position that is way beyond the length of the first line in that .ps1 file.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That is another error message than the first one you mentioned.
Can you remove the PassThru parameter from the line ?
And attach the current version of the script should there still be an error after that ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for you help
The attached is the script and error message
PowerCLI D:\> Get-VM slwsavcjump01 | D:\temp.ps1
D:\temp.ps1 : Wrong object type. Only virtual machine objects are allowed.
At line:1 char:35
+ Get-VM slwsavcjump01 | D:\temp.ps1 <<<<
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,temp.ps1
PowerCLI D:\> Get-VM slwsavcjump01 | %{$_.GetType().FullName}
VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl
This seems to be working
param( [switch]$Disable, [switch]$PassThru ) foreach($vm in $input){ if($vm -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl]) { trap { throw $_ } $vmbo = New-Object VMware.Vim.VirtualMachineBootOptions $vmbo.EnterBIOSSetup = $true if($Disable) { $vmbo.EnterBIOSSetup = $false } $vmcs = New-Object VMware.Vim.VirtualMachineConfigSpec $vmcs.BootOptions = $vmbo $vm.ExtensionData.ReconfigVM($vmcs) if($PassThru) { $vm } } else { Write-Error "Wrong object type. Only virtual machine objects are allowed." } }
I called it like this
Get-VM MyVM | D:\force-bios.ps1 -PassThru
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Brilliant, thank you