ChristianG
Contributor
Contributor

Get-Vm : Value cannot be null

With PowerCli 11, I got Value cannot be null

Get-Vm : Value cannot be null.

Parameter name: format

At line:1 char:1

+ Get-Vm *

+ ~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-VM], ArgumentNullException

    + FullyQualifiedErrorId : System.ArgumentNullException,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

I got this error on almost all commands.

After some digging, I got this error only if I change windows display language (in my case from french to english). Currently running Windows 10 1709

Could anyone can confirm this a bug with PowerCLI?

19 Replies
ChristianG
Contributor
Contributor

Full error is

PSMessageDetails      :

Exception             : System.ArgumentNullException: Value cannot be null.

                        Parameter name: format

                           at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)

                           at

                        VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.MessageHelper.ThrowTerminatingError(Exception ex,

                        String connectionId)

                           at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()

                           at VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM.ProcessRecordErrorHandled()

                           at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ErrorCallbackCmdletBase.ProcessRecord()

                           at System.Management.Automation.CommandProcessor.ProcessRecord()

TargetObject          :

CategoryInfo          : NotSpecified: (:) [Get-VM], ArgumentNullException

FullyQualifiedErrorId : System.ArgumentNullException,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

ErrorDetails          :

InvocationInfo        : System.Management.Automation.InvocationInfo

ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

PipelineIterationInfo : {}

MyCommand             : Get-VM

BoundParameters       : {}

UnboundArguments      : {}

ScriptLineNumber      : 1

OffsetInLine          : 1

HistoryId             : 11

ScriptName            :

Line                  : Get-Vm *

PositionMessage       : At line:1 char:1

                        + Get-Vm *

                        + ~~~~~~~~

PSScriptRoot          :

PSCommandPath         :

InvocationName        : Get-Vm

PipelineLength        : 0

PipelinePosition      : 0

ExpectingInput        : False

CommandOrigin         : Internal

DisplayScriptPosition :

00000000000000000000000000000000000000000000000000000000000000000000000000000000

Message        : Value cannot be null.

                 Parameter name: format

ParamName      : format

Data           : {}

InnerException :

TargetSite     : System.String FormatHelper(System.IFormatProvider, System.String, System.ParamsArray)

StackTrace     :    at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)

                    at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.MessageHelper.ThrowTerminatingError(Exception ex,

                 String connectionId)

                    at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()

                    at VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM.ProcessRecordErrorHandled()

                    at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ErrorCallbackCmdletBase.ProcessRecord()

                    at System.Management.Automation.CommandProcessor.ProcessRecord()

HelpLink       :

Source         : mscorlib

HResult        : -2147467261

0 Kudos
LucD
Leadership
Leadership

Are you running this in PowerShell v5.1 or v6.*?

Could it be that you have some 'unknown' VMs in your environment?

See Get-VM Error after PowerCLI Upgrade

Does this return correctly?

Get-VM -Name *


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ChristianG
Contributor
Contributor

Hello,

Using PowerShell 5.1.

Get-VM -Name * print correctly then I got the error

Get-Vm : Value cannot be null.

Parameter name: format

At line:1 char:1

If I do $vms = Get-VM -Name *

$vms is null

If I switch Windows display language to french (original install language), command Get-VM -Name * run without error.

I did not have the issue on Windows 2016 FR with English display language.

0 Kudos
LucD
Leadership
Leadership

Can you check if there are any "funny" VMs in the environment?

Check with

$sView = @{

    ViewType = 'VirtualMachine'

    Property = 'Name','Runtime.ConnectionState'

    Filter = @{'Runtime.ConnectionState' = "$((1..4 | %{[VMware.Vim.VirtualMachineconnectionstate]$_}) -join '|')"}

}

Get-View @sView | Select Name,@{N='ConnectionState';E={$_.Runtime.ConnectionState}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

ChristianG
Contributor
Contributor

It return no result. Good?

0 Kudos
LucD
Leadership
Leadership

Yes, that means that are no VMs in a funny state in the environment.

You could try to update your PowerCLI version to 11.0.0.
This issue was reported some time ago, and the latest version might contain a fix.

If not, i would advise to a open a SR for the issue.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ChristianG
Contributor
Contributor

I am already using PowerCLI 11

0 Kudos
LucD
Leadership
Leadership

Then I would suggest to open a SR, because this looks like a possible "bug".

And yes, PowerCLI is supported and does not require you to have a Developer Support contract.

See PowerCLI Support Breakdown


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Jrt1general
Enthusiast
Enthusiast

I can confirm I'm also having this issue specifically with vCenter 6.7x. I've tested the same code on 6.0 and earlier without fail. When I target 6.7 - I get the dreaded Value cannot be Null.

It breaks all sorts of scripts in my environment. Mostly stuff automated to make my life easier not my customers. Nothing like slamming the brakes on a upgrade plan...

0 Kudos
LucD
Leadership
Leadership

Just tried again against 6.7 U1b with PowerCLI 11.2.0, no problem.
Which PowerCLI version are you using?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Jrt1general
Enthusiast
Enthusiast

PowerCLI 11.2.0 with 6.7U1b

I'm going to spin up a Win10 VM with no domain GPos or customizations and try again - I need to find the cause of this! Smiley Happy

Thanks again for testing and reporting back. It gives me hope.

0 Kudos
JeanFrancoisT
Contributor
Contributor

We have the same "language problem" here, using the latest PowerCLI. We are using Windows 10 French and we customize the OS as French (Canada). But (just like the SQL installers), unless we change the region/language to French (France), it doesnt work and we get the "Value cannot be null." error message.

0 Kudos
Ukusic
Enthusiast
Enthusiast

I have something similar but with New-VM

PowerCLI 11.2.0 with 6.7U1b

Simple test: (i have replaced the true values in this text)

PS> Connect-VIServer <vcenter>

PS> New-VM -Name <servername> -Datastore <datastore-clustername> -ResourcePool <clustername>

New-VM : 2019-03-12 10:10:19    New-VM        Value cannot be null.

Parameter name: source

At line:1 char:1

+ New-VM -Name <servername> -Datastore <datastore-clustername> -ResourcePool <clustername>

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [New-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

Same command with PowerCLI 11.1.0 with 6.7U1b works and creates a virtual machine without problem.


In my tests i have downloaded the zips for both 11.1 and 11.2 from here VMware PowerCLI - VMware {code}  and unpacked in C:\Program Files\WindowsPowerShell\Modules\ bc we are offline, one at a time during the tests.

0 Kudos
zik
Enthusiast
Enthusiast

I solved this by adding "-Portgroup $pg".  A network seems to be required now.

Ukusic
Enthusiast
Enthusiast

My similar issue but with New-VM was a bug only affecting 11.2, it's confirmed by gss.

Fix coming in 11.3. Workaround: Use "-NetworkName [PortGroup]".

0 Kudos
ddmunhoz
Contributor
Contributor

Is this ever going to be fixed ? Same problem here, changed windows language from French to Englush and now I cannot used pretty much any command.

I'm running  PowerCLI version 11.3.0 (latest) and PowerShell 5.1

0 Kudos
NelsonCandela
Enthusiast
Enthusiast

Hey LucD​,

how on earth do you come up with statements like these? :smileycool:

I was totally unaware that "broken" VMs can lead to a malfunction of a PowerCLI statement.

Following your script I identified two VMs being in a "inaccessible" state (which you referred to as funny :smileylaugh:) in the vCenter inventory.

I removed the two faulty ones from the inventory and suddenly Get-VM started working again.

Thanks a ton!

BR

NC

0 Kudos
LucD
Leadership
Leadership

Experience :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

MatDesj
Contributor
Contributor

On my part, I am also getting that error message when throwing Get-VMHost:

I have my host list then the error Value cannot be null.

VMware.VimAutomation.Core

Major  Minor  Build  Revision

-----  -----  -----  --------

11     5      0      14899560

PowerShell Version

Major  Minor  Build  Revision

-----  -----  -----  --------

5      1      19587  1000

When running inside ISE (editing my script), I do not have the error but running it in a PowerShell Windows return the error. Either Admin or not.

get-vmhost : Value cannot be null.

Parameter name: format

I was getting a similar error with Set-PowerCLIConfiguration but after updating to the latest version (11.5 vs 11.3), I am not getting it anymore.

Anyone having an idea about that?

Mathieu

0 Kudos