header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
How do you pass an argument to a function?
Last Post 07 May 2009 11:05 AM by EBGreen. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
edm365f31User is Offline
Basic Member
Basic Member
Posts:100
Avatar

--
07 May 2009 07:38 AM
    I created a  Reboot verification from  previous post, I want this script to accept an argument to run local on the box or remote.

    ./verifyreboot.ps1 (local)
    ./verifyreboot.ps1 (remote) (strcomputer)

    if no arg passed script will write-host and exit.  If Local only one argument needed and it will pull a (function local).  If its remote it will pull a (function remote) and will pass arsg1 and args2 to the function.
    EBGreenUser is Online
    Veteran Member
    Veteran Member
    Posts:1092
    Avatar

    --
    07 May 2009 11:05 AM
    In your script, you would use a parameter block. So something like:

    param(
            [switch]$Local,
            [string]$Remote = ''
         )

    if ($Local)
    {
        'LOCAL PARAM PRESENT'
        # CALL LOCAL FUNCTION HERE
        return
    }
    if ($Remote -ne '')
    {
        "Remote set to $Remote"
        # CALL REMOTE FUNCTION HERE
        return
    }

    'No Params present'
    "Look Ma...no strings!"
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer