Script to check all(?) CLI-tools versioning

Oct 24, 2019 13:43 · 248 words · 2 minute read #Powershell #Bash #Script


So, Today I’m so lazy to check 1 by 1 CLI-tools that has been installed on my machine. I’m using Windows 10 Pro, and sometimes I forgot what is CLI-Tools that has been installed on my machine with it’s version.

So I try to make a simple script to check them all once. I’m using Powershell script since it easier for me. Lets see my code.

The concept of this script is just to check a command version of CLI-tool that we’ve defined in the script. If there are no CLI command run/success, then it will return message like “Packages does not exists”.

First, we need a function to do that. We called it Test-Method.

Function Test-Command {
    Param ($command)
    $oldPreference = $ErrorActionPreference
    $ErrorActionPreference = "stop"    
    
    try {        
        if( Get-Command $command ){ RETURN $true }     
    }Catch {        
        Write-Host "packages does not exist on this machine"; 
        RETURN $false    
    }Finally {        
        $ErrorActionPreference = $oldPreference    
    }
}

Then, For check every single CLi-tool that available on our machine, we need to define it’s Command

Write-Host 'Go : ' -ForegroundColor yellow; if(Test-Command go version){go version}

Script above, will call our Method with Params as our Command. Then, just add another CLI-tool that we want to check or available right now.

This is, how it works:

cli37c31f2db06a714f.gif

I’ve created a repository to make another open sourcerer to add another CLI-tools line. I hope someone create a bash script version too. If you interest on this, let me know with fork this Repository

Happy coding!