VMware Cloud Community
vradenkovic
Contributor
Contributor
Jump to solution

The 'State' property of VMHost type deprecated. Maintenance mode using PowerCLI

Hi All,

I'm trying to glue together a script to connect to an ESX host, gracefully shutdown all the running VMs and finally put the host into maintenance mode and then power it off.

This is the maintenance mode command: Set-VMhost -State Maintenance

I'm getting these "error" messages when this command executes:

WARNING: The 'State' property of VMHost type is deprecated. Use the 'ConnectionState' property instead.

WARNING: PowerCLI scripts should not use the 'Client' property. The property will be removed in a future release.

WARNING: PowerCLI scripts should not use the 'DatastoreIdList' property of VMHost type. The property will be removed in a future release.

The command still does the job, but I would like my script to be error/warning free.

If I use -ConnectionState instead of -State, it gives an invalid parameter error and doesn't work.

I'm no script expert as you can tell, I have pretty much borrowed the code from other topics/websites and modified the variables.

Am I missing something obvious? I tried researching this online, but couldn't find anything useful on how to use the new command instead.

And the two other warning messages really baffle me. I'm not even using those syntaxes in my script.

The weird thing is that if I fire up the PowerCLI console, connect to the host and JUST execute this command manually, it doesn't give me the warnings.

The complete ps1 script is attached.

Thanks a lot for any help!

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Those warnings are on the properties in the object that is returned by the Set-VMHost cmdlet, not the on the cmdlet's parameters.

You should be seeing the same warnings on the Get-VMHost cmdlet.

You can use the Set-PowerCLIConfiguration cmdlet with the DisplayDeprecationWarnings switch.

Note the role the Scope parameter plays.


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

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

Those warnings are on the properties in the object that is returned by the Set-VMHost cmdlet, not the on the cmdlet's parameters.

You should be seeing the same warnings on the Get-VMHost cmdlet.

You can use the Set-PowerCLIConfiguration cmdlet with the DisplayDeprecationWarnings switch.

Note the role the Scope parameter plays.


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

vradenkovic
Contributor
Contributor
Jump to solution

Thanks for the response, that was quick!

Now, do I want to suppress the warnings display or is it better to fix the code so that it doesn't give me the warnings? In other words, can (should) I use ConnectionState instead of State as the warning suggests?

And thanks for the Scope parameter tip. BTW, there's actually a typo on the page that explains the Set-PowerCLIConfiguration cmdlet, it says Sesstion in the description of the Scope parameter.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The warning is not about the cmdlet's parameters, there is no ConnectionState parameter!

It's only about the properties on the object that is returned.
Pipe the result of the cmdlet to the Get-Member cmdlet, and you will see all the properties.


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

vradenkovic
Contributor
Contributor
Jump to solution

Gotcha. I thought you were talking about the last two messages and not the State warning message.

A little bit off-topic question, if I may: Is there a way to color code the text in the script so that those $ESXSRV and $VM values show in a different color in the PowerShell CLI?



EDIT: Never mind, found a workaround on the Interwebz.

Thank you LucD!

0 Kudos
LucD
Leadership
Leadership
Jump to solution