![]() |
|
[Powershell Tutorial] PowerShell Basics - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: [Powershell Tutorial] PowerShell Basics (/Thread-Powershell-Tutorial-PowerShell-Basics) |
[Powershell Tutorial] PowerShell Basics - ArkPhaze - 12-03-2011 1) Writing To PowerShell Console Code: Write-host "This is a basic message"Code: Write-warning "This is a warning"A. Formatting colors* Code: Write-host "Hello" -foregroundcolor "magenta"B. Multiple colors on same line* Code: write-host "first words " -foregroundcolor "magenta" -nonewline; write-host "second set of words" -foregroundcolor "cyan"- Note: Usable Colors - • Black • DarkBlue • DarkGreen • DarkCyan • DarkRed • DarkMagenta • DarkYellow • Gray • DarkGray • Blue • Green • Cyan • Red • Magenta • Yellow • White 2) Pipelining Data to Text Files Code: $Proc = Get-Process | Out-File -Filepath Output_Proc_List.txtCreate Text File: Code: $Proc = Get-Process > Output_Proc_List.txtAppend to Text File: Code: $Proc = Get-Process >> Output_Proc_List.txt3) Getting data from files Code: Get-Content "C:\file.txt"4) Other Miscellaneous things to keep in mind A. I'm no good at making random tutorials. So suggest something for a future powershell tutorial by me after this B. Signs • @ - Array • % - Hash Array • $ - Variable • | - Pipeline • # - Comment all after this symbol • .. - Range C. Special Variables: • $_ – Contains the current pipeline object, used in script blocks, filters, and the where statement. • $Args – Contains an array of the parameters passed to a function. • $Error – Contains objects for which an error occurred while being processed in a cmdlet. • $Home – Specifies the users home directory. • $PsHome – The directory where Windows PowerShell is installed. |