Powershell Script Description:
Pass a number to a PowerShell script as an argument and validate whether it is a valid Binary. If the entered number is a valid binary, display its decimal value.
Script: isValidBinary.ps1
if ( $args[0] ){$num = $args[0]try {$value = [convert]::ToInt32(“$num”,2)Write-Host "'$num' is a valid Binary" -ForegroundColor GreenWrite-host "Decimal Value: $value"}catch{Write-Host "'$num' is not a valid Binary" -ForegroundColor Red}}else{Write-Host "You must pass a number to the script"}
Output:
No comments:
Post a Comment