Agenda:
Designed by |
Jeffrey Snover, Bruce Payette, James Truher (et al.) |
Developer |
Microsoft |
First appeared |
November 14, 2006 |
Stable release |
5.1.14393 / August 2, 2016; 8 months ago |
Preview release |
6.0.0 Alpha 17 / March 8, 2017; 35 days ago |
Typing discipline |
Strong, safe, implicit and dynamic |
Platform |
.NET Framework, .NET Core |
OS |
Windows 7 and later, macOS, CentOS, Ubuntu |
Filename extensions |
•.ps1 (Script)
•.ps1xml (XML Document)
•.psc1 (Console File)
•.psd1 (Data File)
•.psm1 (Script Module)
•.pssc (Session Configuration File)
•.cdxml (Cmdlet Definition XML Document)
|
What’s Need ?
Machine management:
ConvertTo-SecureString :- Convert any string into Encrypted form
-AsSecureString :- Take input from user in secure way
$var = Read-Host -AsSecureString
$var1 = ConvertTo-SecureString -SecureString $var
Filtering
Write-Host is having more attributes
Write-Host –NoNewLine “Counting from 1 to 9 (in seconds): “
foreach($element in 1..9){
Write-Host –NoNewLine “${element} “
Start-Sleep –Seconds 1
}
Write-Host “”
Output :- Counting from 1 to 9 (in seconds): 1 2 3 4 5 6 7 8 9
Write-Output
Write-Output should be used when you want to send data on in the pipe line, but not necessarily want to display it on screen.
PS C:\> Write-Output"test output" | Get-Member
This command pipes the "test output" string to the Get-Member cmdlet, which displays the members of the System.String class, demonstrating that the string was passed along the pipeline.
Loops
While/ Do-While Loop
While :- As long as the condition remains true, PowerShell reruns the {command_block} section.
while($val -ne 10) { $val++ Write-Host $val }
Do-While:- First the Command Block will run and then it will check condition
Do {
$val++ Write-Host $val
} while($val -ne 10)
Importing: