Here’s a simple scenario which I came across today. You would like to work with your vSphere environment using the latest PowerCLI but discover that v6.5.1 is the latest downloadable version on VMware’s website. Hearing that the distribution for this code has now moved to the PowerShell Gallery you open a PS prompt and enter:
PS:\> Install-Module VMware.PowerCLI
The modules are downloaded and installed successfully, and you are able to connect to your vCenter environment:
Connect-VIServer -server vcenterserver.com -user 'DOMAIN\username'
But when you attempt to use a simple command such as:
you receive an error similar to:
get-tag : 11/10/2018 21:06:20 Get-Tag Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file
At line:1 char:1
In my case I found that other system components on my VM were using an older version of the Newtonsoft.Json.dll (e.g. Citrix Virtual Desktop Agent) that were found in the file search path before the PowerShell module’s location.
Searching for the file conflict using ProcMon I noticed that the Connect-VIServer cmdlet does indeed find and load a version of this .dll during the connection process, e.g. the one located in:
However this version is 126.96.36.19908 on my Windows Server 2016 platform and we’re looking for 10.0.0.0 or newer.
Retrieve the newer version of the file (supplied with the PowerCLI modules), located for instance in:
and place a copy in somewhere PowerShell is likely to find it, e.g.:
This simple work-around proved successful for me, but you should check of course to verify all other functionality which might depend on this file before making a similar change in a production environment.