Interactive Programming in PowerShell – Read-Host in SharePoint 2013

Sathish Nadarajan
SharePoint MVP
Published On :   13 Jan 2015
Visit Count
Today :  2    Total :   7879

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:


To ask for the Password columns,

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




Happy Coding.

Sathish Nadarajan.