Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
General PowerShell
How do you pass an argument to a function?
Last Post 07 May 2009 11:05 AM by
EBGreen
. 1 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
edm365f31
Basic Member
Posts:100
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.
EBGreen
Veteran Member
Posts:1092
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.
Using PowerShell
--General PowerShell
--Active Directory
--Exchange Server
--Lync Server
--SharePoint
--SQL Server
--System Center
--Non-Microsoft Products
--Books, Tools, and Videos
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
General PowerShell
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2