githubEdit

πŸƒβ€β™‚οΈExample Excerises

PowerShell Practice Notes


πŸ”Ή Basic Notes

  • ISE (Integrated Scripting Environment): A GUI for writing and debugging PowerShell scripts.

  • Everything in PowerShell is an OBJECT βœ…

  • Check PowerShell version:

    $PSVersionTable.PSVersion
  • Ping a website:

    ping spacex.com

πŸŽ“ Learning Tools


πŸ”Ή About Cmdlets

  • Cmdlet format: Verb-Noun (unless it's a custom function).

  • Check execution policy:

    Get-ExecutionPolicy
  • Change execution policy:

    Set-ExecutionPolicy RemoteSigned
  • RemoteSigned allows custom scripts to run.


πŸ“ Basic Cmdlets

  • Print text:

  • Find commands:

  • Get help for a command:


πŸ”— Piping Cmdlets

  • Write to a file:

  • View file content:


πŸ”Ή Variables

  • Create a variable:

  • Output a variable:

  • Save variable to a file:

  • Find variable type:

  • List all properties:

  • List all methods:


πŸ”Ή Arrays

  • Define an array:

  • Get first element:

  • Add an element:


πŸ”Ή HashTables

  • Define a hashtable:

  • Add an entry:


πŸ—οΈ Collecting User Input

  • Prompt for user input:


πŸ”Ή Conditional Statements

  • If-Else Example:

  • ElseIf Example:


πŸ”Ή Loops

  • For Loop:

  • ForEach Loop:

  • While Loop:


πŸ”Ή Functions

  • Define a function:


πŸ”Ή Error Handling

  • Using Try-Catch:


πŸ”Ή File Operations

  • Create a file:

  • Move a file:

  • Delete a file:


πŸ”Ή Active Directory (Admin Mode)

  • Import Active Directory Module:

  • Get a user:

  • Create a new AD user:


⚑ Quick Tip

  • Use Clear-Host to clear the console screen.

  • Use Get-Process | Sort-Object WorkingSet64 -Descending | Select-Object -First 10 to find top 10 memory-consuming processes.


Last updated