In below code, I need to check if version string is not empty then append its value to the request variable.
if ([string]::IsNullOrEmpty($version)) { $re
You don't necessarily have to use the [string]:: prefix. This works in the same way:
if ($version) { $request += "/" + $version }
A variable that is null or empty string evaluates to false.