Skip to content

Frequently Asked Questions

lucdekens edited this page Aug 2, 2016 · 21 revisions

#FAQ

How do I make sure my code runs with a specific PowerCLI build?

How do I write "pretty" PowerShell/PowerCLI code?

Q: How do I make sure my code runs with a specific PowerCLI build?

The preferred way to do is, is by adding a #Requires line at the top of your script

#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}

This line will check if the PowerCLI Core module is loaded, and if the loaded module version is at least 6.3 R1.

If the required module is not loaded, the script will fail with a message like this

Q: How do I write "pretty" PowerShell/PowerCLI code?

PowerShell allows a lot of freedom on how you write your code. From the dreadful "one-liners" all the way to "beautiful code", you'll find all kinds on the InterWeb.

In everyone's interest it would be useful to follow, as much as possible, the same, common sense guidelines. One great resource is the The PowerShell Best Practices and Style Guide