Interactive Programming in PowerShell – Read-Host in SharePoint 2013


Sathish Nadarajan
SharePoint MVP
Published On :   13 Jan 2015
Visit Count
Today :  1    Total :   6981
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

Sharegate: Kick-Ass Tool
Think Your SharePoint & Office 365 Are Secure ? Find Out Now!


Sometimes we may require to get some information from the end user during the execution of our PowerShell Scripts. i.e., I faced this one to get the Service Account Name and Password. As it contains some Password, we may not be able to write it on the Config file. To achieve that, let us see the below commands.

 $ServiceAccountName = Read-Host "Please enter the Service Account Name "

No need to add a colon at the end of the prompt (e.g., “Please enter the Service Account Name:”); Windows PowerShell will add the colon to the end of the prompt for you.

Within the Windows PowerShell console, that looks like this:

image

To ask for the Password columns,

 $ServiceAccountName = Read-Host "Please enter the Password " –assecurestring

 

image

 

Happy Coding.

Sathish Nadarajan.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

Migratiin Tools for SharePoint