resume

Log | Files | Refs | README

02_powershell_crash_course.md (3058B)


      1 # PowerShell Crash Course — Rogers Data Engineer Focus
      2 
      3 ## Core Syntax
      4 
      5 ```powershell
      6 # Variables
      7 $name = "Chris"
      8 $count = 42
      9 
     10 # Arrays and hashtables
     11 $users = @("alice", "bob", "carol")
     12 $config = @{ Server = "db01"; Port = 1433 }
     13 
     14 # Loops
     15 foreach ($user in $users) {
     16     Write-Output "Processing $user"
     17 }
     18 
     19 # Conditionals
     20 if ($count -gt 10) { "big" } else { "small" }
     21 # Note: -gt, -lt, -eq, -ne, -like, -match  (not >, <, ==)
     22 
     23 # Functions
     24 function Get-Greeting {
     25     param([string]$Name)
     26     return "Hello, $Name"
     27 }
     28 ```
     29 
     30 ---
     31 
     32 ## High-Value Skills for This Job
     33 
     34 ### 1. Import/Export CSV — bread and butter for data sync
     35 
     36 ```powershell
     37 $students = Import-Csv "students.csv"
     38 foreach ($s in $students) {
     39     Write-Output "$($s.FirstName) $($s.LastName)"
     40 }
     41 
     42 $results | Export-Csv "output.csv" -NoTypeInformation
     43 ```
     44 
     45 ### 2. Active Directory cmdlets
     46 
     47 ```powershell
     48 # Requires RSAT / ActiveDirectory module
     49 Import-Module ActiveDirectory
     50 
     51 Get-ADUser -Filter { SamAccountName -eq "cjroberts" } -Properties *
     52 New-ADUser -Name "Jane Doe" -SamAccountName "jdoe" -Enabled $true
     53 Set-ADUser -Identity "jdoe" -Department "Staff"
     54 Get-ADGroupMember -Identity "Teachers"
     55 Add-ADGroupMember -Identity "Teachers" -Members "jdoe"
     56 ```
     57 
     58 ### 3. Error handling — they want someone who debugs independently
     59 
     60 ```powershell
     61 try {
     62     $result = Get-ADUser -Identity "nobody"
     63 } catch {
     64     Write-Error "Failed: $($_.Exception.Message)"
     65 } finally {
     66     # cleanup if needed
     67 }
     68 ```
     69 
     70 ### 4. SQL queries from PowerShell
     71 
     72 ```powershell
     73 # Using SqlServer module (common in school districts)
     74 Invoke-Sqlcmd -ServerInstance "db01" -Database "StudentDB" `
     75     -Query "SELECT StudentID, LastName FROM Students WHERE Active = 1"
     76 
     77 # Or with a connection object for more control
     78 $conn = New-Object System.Data.SqlClient.SqlConnection
     79 $conn.ConnectionString = "Server=db01;Database=StudentDB;Integrated Security=True"
     80 $conn.Open()
     81 ```
     82 
     83 ### 5. Logging — process-oriented, documented work
     84 
     85 ```powershell
     86 function Write-Log {
     87     param([string]$Message)
     88     $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
     89     "$timestamp - $Message" | Tee-Object -FilePath "sync.log" -Append
     90 }
     91 ```
     92 
     93 ---
     94 
     95 ## Pipeline Thinking (Very PowerShell)
     96 
     97 ```powershell
     98 # PowerShell passes objects, not text — lean into it
     99 Get-ADUser -Filter * |
    100     Where-Object { $_.Enabled -eq $false } |
    101     Select-Object Name, SamAccountName |
    102     Export-Csv "disabled_users.csv" -NoTypeInformation
    103 ```
    104 
    105 ---
    106 
    107 ## What to Practice Before the Interview
    108 
    109 1. Write a script that reads a CSV and creates AD users from it — classic onboarding task, exactly what they described
    110 2. Add try/catch and logging to it — shows production-readiness mindset
    111 3. Run `Get-Help <cmdlet> -Examples` — practice looking things up; nobody memorizes everything and they'll respect that you know how to find answers
    112 
    113 ---
    114 
    115 ## If They Ask "How's Your PowerShell?"
    116 
    117 > "I'm comfortable with the fundamentals — scripting, AD cmdlets, CSV handling, error handling. I haven't been in it daily lately, but I pick it up quickly and I know how to read the docs."