Posted On March 29, 2019

How to Call Functions or Pass Function as Argument

kimconnect 0 comments
blog.KimConnect.com >> Codes >> How to Call Functions or Pass Function as Argument
cls
 
function listClusters{
    # List all Clusters in this Domain
    $items=get-cluster -domain (get-addomain)
    $global:clusters=$items
}
 
function show{
    Param($callFunction)
    invoke-command (Get-Item “function:$callFunction”).ScriptBlock
    if ($clusters){$count=$clusters.count; $global:list=$clusters; $global:nodes=””}
    if ($nodes){$count=$nodes.count; $global:list=$nodes}
    
    $show=”`n————————————————–`n    There are $count items in this Collection: `n————————————————–`n”
        for ($row=0;$row -le $count-1;$row++){
            $server=$list[$row]
            $show += “$row”  + “: ” + “$server” + “`n”
            }                
    return $show
}
 
show -callFunction listClusters

Leave a Reply

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

Related Post

PowerShell: Gather Information About Windows Shutdown Reasons

Copy and Paste this to See Result(s): $computername=$env:computername $limitEventsCount=40000 $daysSearchLimit=30 function getWindowsShutdownReason{ param( $computername=$env:computername, $limitEventsCount=10000,…

PowerShell: Reset Password for All Users inside an OU

$ouName="Funky Dudes" $ouPath = "ou=$ouName,dc=intranet,dc=baam,dc=com" $plaintextPassword='WHATPASSWORD?' $users=Get-ADUser -Filter * -SearchBase $ouPath | Select-object Name,UserPrincipalName,DistinguishedName foreach…

Linux: How to Display the SSL Certificate of a Remote Server URL

Command: server=test.kimconnect.comecho | openssl s_client -showcerts -servername $server -connect $server:443 2>/dev/null | openssl x509 -inform…