Interactive Programming in PowerShell – Read-Host in SharePoint 2013

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

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial

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.

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

SharePoint Analytics