Interactive Programming in PowerShell – Read-Host in SharePoint 2013

Sathish Nadarajan
 
Solution Architect
January 13, 2015
 
Rate this article
[Total: 0    Average: 0/5]
 
Views
8738

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.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
[Total: 0    Average: 0/5]
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 13+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment