Check deprecated PowerCLI CMDlets

Check deprecated PowerCLI CMDlets

I think most of you have a set of various PowerCLI Scripts that runs automatically day by day. Have you ever checked if your older scripts contain some deprecated commands? Here is a handy way to check …

If you read the Change Log from PowerCLI here you find some deprecated or even deleted commands. So that is the reason why you should check from time to time your daily running scripts.

At the last VMworld 2018 in Barcelona, I spoke to Kyle Ruddy after the Session “DEV3504BE” about a way to check on deprecated commands. I hope to get a list from him soon but in the meantime I looked at a easy way to check the content of a Script folder against a JSON-File. And this was much easier than I thought 😉

All we need is a JSON File filled and a few lines of PowerShell.

The JSON File could look like this:

{
  "deprecatedcmd": [
    "Get-DrmInfo",
    "Get-OrgNetwork",
	"Get-VMGuestNetworkInterface",
	"Set-VMGuestNetworkInterface",
	"Get-VMGuestRoute",
	"New-VMGuestRoute",
	"Remove-VMGuestRoute",
	"Get-VMHostPatch",
	"Test-VsanStoragePerformance"
      ],
  "delcmd": [
    "Get-DrmInfo",
    "Get-VMGuestNetworkInterface",
	"Set-VMGuestNetworkInterface",
	"Get-VMGuestRoute",
	"New-VMGuestRoute",
	"Remove-VMGuestRoute",
	"New-CustomField",
	"Remove-CustomField",
	"Set-CustomField"
  ]
}

To check your usage of deprecated or deleted commands you could use this:

$uri = "https://vblog.hochsticher.de/wp-content/uploads/2019/01/old-cmds.json"
$path = "C:\scripts"

Invoke-RestMethod -Uri $uri | Select -ExpandProperty deprecatedcmd
Invoke-RestMethod -Uri $uri | Select -ExpandProperty delcmd

$deprecatedcmd = Invoke-RestMethod -Uri $uri | Select -ExpandProperty deprecatedcmd
$delcmd = Invoke-RestMethod -Uri $uri | Select -ExpandProperty delcmd

Get-ChildItem -recurse -Path $path| Select-String -pattern $deprecatedcmd | select Path,LineNumber,Line

Get-ChildItem -recurse -Path $path| Select-String -pattern $delcmd | select Path,LineNumber,Line

The output tells you in which file and line you used one of those commands.

PS C:\Users\xyz> 
Get-ChildItem -recurse -Path $path| Select-String -pattern $deprecatedcmd | select Path,LineNumber,Line
Path                                    LineNumber Line       
----                                    ---------- ----       
C:\scripts\temp\Test-Deprecated-CMD.ps1         50 Get-DrmInfo

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.