Notes of a scripter

When Get-ContentLibraryItem Fails

In my work environment we have made strives to simply our VMware environment. One of them is using the content library for templates and ISO files. We do this so we make sure the everyone is using the most current golden image. Also with the content library you can sync them from primary site to secondary site without issues. So when a disaster hits we will have the templates so we can build new VMs if needed.

So today, I heard from some of the other team members that use a script that I wrote to build VMs, that it stopped working. Mind you, I have a laptop that I rarely reboot because of all of the apps that I keep open so I know where I left off from the day before. I know, its bad practice, but I’ll live with it. The team members that were having the issues with the build script are in the same boat. Laptops with infrequent reboots.

So I got the copy of the script that they are using and start investigating what the problem is with it. The build script wouldn’t complete. This isn’t just a script that turns out a VM that needs extra work, but a turn key script that builds, IPs, Tags, annotates, and joins the domain. We have plans to add more, but work keeps getting in the way. So the script doesn’t complete. I starting to run the script from my workstation, and almost immediately I get an error.

Get-ContentLibraryItem : 10/7/2019 2:29:16 PM	Get-ContentLibraryItem		Server session is not established.	
At line:76 char:33
+     else {$ContentLibraryItem = Get-ContentLibraryItem | ? {$_.Name - ...
+                                 ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [Get-ContentLibraryItem], CisException
    + FullyQualifiedErrorId : VMware.VimAutomation.Cis.Core.Util10.Service.AssertConnected,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetContentLibraryItem

Its hard to build VMs when you can’t get the template from the content library. I read the error message, and got fixated on the “Server session is not established“. I know I’m connected to vCenter, because I reconnect every morning before I start to do anything. So I know that isn’t the session its looking for. Besides, I did disconnect and reconnect to vCenter as a step in troubleshooting this madness.

what session?

As I read the error in more detail, I found the last line intriguing. I read it several times, “VMware.VimAutomation.Cis.Core.Util10.Service.AssertConnected“. This got me to thinking about the SDK server, or using Connect-CisServer command. Which I tried many times, and disconnecting from vCenter and reconnecting some more while still using the same powershell ISE window. I unloaded the PowerCLI modules, and force loaded different versions. I was about to go mad. I then thought to myself, what would be the first thing I would told someone else to try…

No, should it?

So I started a fresh PowerShell session, and then loaded the build script. I ran it and it worked without any issues. Its just baffles me that the error message doesn’t have more meaning. I could have been troubleshooting this issue for a lot longer if I would have stopped and thought about it.

-Stuart

Exit mobile version