Basics of Input and Output in Windows PowerShell
Last Updated :
27 Sep, 2019
Windows PowerShell is a command-line and scripting language designed for system administration. It helps IT professionals, to control and automate the administration of the Windows Operating System and Windows Server Environment. There are cmdlet for console input and output using PowerShell.
Example 1: Showing the Output to console
Function to print a string.
Input : 'Geeks for Geeks'
Output : Hello Geeks for Geeks
Input : 'PowerShell Beginner'
Output : Hello PowerShell Beginner
function show {
param ( $str2 )
Write-Host "Hello $str2"
}
$str = "Geeks for Geeks"
show ( $str )
|
In Windows Powershell, the input and output are given through the Host. It uses ‘Write-Host’ to print and ‘Read-Host’ to get input from console.
Example 2: Taking the User input through console
Function to get user input.
Input : 'Geeks for Geeks'
Output : Hello Geeks for Geeks
Input : 'PowerShell Beginner'
Output : Hello PowerShell Beginner
function show {
param ( $str2 )
Write-Host "Hello $str2"
}
$str = Read-Host -Prompt 'Enter a String'
show ( $str )
|
Note: If your script show error “script is Disabled” while running program then try to change the execution policy with administrative privilege by using the command ‘set-executionpolicy remotesigned‘
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...