Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

Powershell input parameter via command line

14 December,2017 by Tom Collins

Question: How do you use input parameters on Powershell via command line?  I need to pass a value

Answer: The easiest way to use input parameters on Powershell via command line is to use this method. This method will give you the flexibility to use multiple input parameters in your powershell scripts

First  , let's look inside the script:

 

param (
    [string]$myserver = "http://myserver"
    
)

write-output $myserver



 This script accepts an input parameter - which you'll call from the command line. In this case , you'll pass in a parameter call "myserver" and then it will output to the console. If you don't pass in a parameter - the default value "http://myserver" will be written.

 

.\parameters.ps1 -myserver http://www.sqlserver-dba.com.com

 

Read more on Powershell input parameter via command line 

Powershell - run script on all sql servers (SQL Server DBA)

Read a script file into Powershell CommandText with get-content ...

 

 


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on Powershell input parameter via command line


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer