For a few years now I have been pulling data from the vCenter SQL Server database about my SQL Server virtual machines and storing that data into my own database. After systems did the last upgrade, vCenter no longer stores the information in a SQL database. I asked them how to connect and they suggested that I use the PowerShell library that VMware provides. This is how I got it to work.
NOTE: I am only going to be using Get commands when I connect. You can change settings or start and stop VMs and even hosts from the tools if you have the proper permissions so know what a command does before you run it. I don't believe you can use the -whatif parameter with any of the commands so be extra careful.
Installation
First I need to install the library, also known as VMware PowerCLI. I tried downloading the install package but it is an older version. After some web searching, I found that you can get it from PowerShell Gallery.
You can get the most current pre-release version using this code. NOTE: I ran into some issues using pre-release versions.
If you want to install a specific version, you can specify the version number. Check this PowerShell Gallery page for version numbers. I am going to install the current version listed on that page
If you find you need to remove the module you can do so with this command. I had to use this to uninstall an older version and install a newer one
Getting Connected
Now that I have it installed I want to see what I have available and then I will connect to a vCenter server. To list the modules that were installed use this command
On my machine I get this list back.
You could then use Get-Command -Module [Module Name] to list out all the function and CmdLets for each module. Feel free to test that out but we are going to be using the VMware.VimAutomation.Core module today to get some information.
First we are going to connect to a vCenter server. We need to import the module first then we can connect (Remember to change the parameters for your environnment)
In my environment I got the following error message:
Connect-VIServer : 6/25/2019 2:18:48 PM Connect-VIServer Error: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you'd like
to connect once or to add a permanent exception for this server.
Connect-VIServer : 6/25/2019 2:18:48 PM Connect-VIServer Error: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you'd like
to connect once or to add a permanent exception for this server.
This is because we use a self-signed certificate. You need to execute this command once to fix this:
After I executed this command, I was able to use the Connect-VIServer command.
Basic Commands
Now that we are connected we can use some basic commands to get inventory information. First I am going to list all of the hosts with some of their properties
If you want to see all the properties of just one host you can do it like this
Now lets do the same thing for virtual machines. First we will list them
Then we can dig in and see all the available properties of a particular virtual machine
These are just some basic commands to get started but they give me the data that I need to collect the inventory information I used to be able to collect directly from the old SQL Server database.
No comments:
Post a Comment