Working with PowerShell - Paiet/Windows-Server-Wiki GitHub Wiki

  • Working with PowerShell?
    • Starting Powershell
      • Primary technology built into Windows OS
      • It is a command shell and it is a scripting language
      • Purpose: Focus is for IT Administration
        • automating administrative task
        • manage remote computers
      • Open Powershell console
        • great for running the commands.
      • Powershell ISE (advanced environment for running commands and writing scripts)
        • auto completion, color coding, list of commands
        • write multi-lined scripts (top half)
        • output window displayed belowed
        • great for development
    • Windows Powershell Syntax
      • cmdlet: single function that performs single task. i.e. fetching data, changing a configuration in a verb-noun format.
        • get-aduser -identity joey
        • get-aduser -Filter *
        • get-aduser -filter * | FT name
      • tab completion: get-ad and use tab
      • modules: can be imported to give additional commands to manage different technology
        • Demonstrate adding a module
    • Commands vs. cmdlets
      • e.g. get-mailbox
      • e.g. get-mailbox -identity lance
    • Stringing commands together
      • multiple commands can be strung together: get-service| sort-object -property Status -descending
    • Symbols in Powershell
      • ` (Used in a long command that has to be continued on next line)
      • $ When you declare a variable
      • {} enclose block of code. sometimes when using where
      • () to execute something first or group expressions
      • ; run multiple commands on a single line
      • % Use an alias in ForEach-Object
      • ? alias for Where-object
  • What can we do with Powershell?
    • PowerShell Execution Policy
      • Determines how PowerShell handles scripts.
      • This is very important when users try to run a script and it fails.
      • If your organization runs many scripts you may want to understand the 6 different execution policies that may effect your script running.
        • Simple Diagram (table 4.2)
      • Two factors help you to decide which execution policy to run
        • Security
        • Administrative Efficiency
      • Default policy for Server 2012 R2 and 2016 is Remoted Signed
    • Working with Windows hotfixes
      • Displays information on hotfixes that have been installed: Get-Hotfix
      • Displays information on hotfixes that are filtered: Get-Hotfix | where InstalledOn -eq '5/18/2017 12:00:00 AM'
      • Displays more details with the filtered output: Get-Hotfix -Description 'Security Update' | where {$_.InstalledOn -eq '5/18/2017 12:00:00 AM'} | select HotfixID,InstalledOn,InstalledBy
    • Troubleshooting network connectivity
      • Test Basic Connectivity: Test-NetConnection -ComputerName O365-DC01
      • Test if a service is listening on port: Test-NetConnection -ComputerName O365-DC01 -Port 23
      • Test if a service is listening on port: Test-NetConnection -ComputerName O365-DC01 -Port 3389
      • Find an IP Address of a Computer: Resolve-DNSName -Name O365-DC01
      • Find all powershell commands you've run from current powershell command prompt: get-history
      • Run a previous command again:
        • invoke-history ##
        • Use up arrow
      • Count object that meet a certain criteria:
        • get-service | measure-object
    • Working with pipeline
      • connects multiple commands together to get a result.
      • e.g. Get-Process
        • you want to sort by CPU
      • e.g. Install a windows Feature
        • get-WindowsFeature -name "SMTP"
        • get-WindowsFeature -name "RSAT-SMTP" | install-windows feature`
    • Using Help
      • get-command *eventlog*
      • get-command *get-* -Module ActiveDirectory
      • Get-Module -ListAvailable
      • Get-Service | get-member