The term 'Get-OrElse' is not recognized as a name of a cmdlet, function, script file, or executable program

Viewed 223

The term 'Get-OrElse' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a | path was included, verify that the path is correct and try again.

enter image description here

Powershell is installed in my system . The version that is installed is 5.1.19041.1645 . Please help me how can I fix this ?

1 Answers

As I state in my comment - I believe you are trying to call a function in a script. You must either declare the entire function or it's path before you can call it.

Write-Host "Before calling Function."

## all my functions go here
function Get-OrElse {
    [CmdletBinding()]
    Param(
        [Parameter(ValueFromPipeline = $True)]
        [Object]$Value,
        [Parameter(Mandatory = $True)]
        [Object]$Default
    )
    if ($null -eq $Value) {
        return $Default
    }
    switch ($Value.GetType().Name) {
        "String" {
            if ([string]::IsNullOrEmpty($Value)) {
                return $Default
            }
            else {
                return $Value
            }
        }
        "Hashtable" {
            if ($Value.count -eq 0) {
                return $Default
            }
            else {
                return $Value
            }
        }
        "Object[]" {
            if ($Value.count -eq 0) {
                return $Default
            }
            else {
                return $Value
            }
        }
        Default {
            return $Value
        }
    }
}

##now i can call my delcared function
Get-OrElse
Related