PowerShell Genie

PowerShell script library: choose a reporting workflow

Guide 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Use this library to choose a workflow before opening its implementation. Start with the report you need, then follow the linked script to inspect parameters and assumptions. Browse Scripts when you already know which command or task you need.

Overview

TESTED SCRIPT LIBRARY

SCRIPT CONTRACT

Every featured script answers four questions

Prerequisites, output shape, safety boundary and verification live next to the code instead of in a disclaimer nobody reads.

Prerequisites

Edition, module, privilege, network and data assumptions.

Output

Object type and properties before any display formatting.

Safety

Read-only vs state-changing behavior, WhatIf support and irreversible steps.

Verification

A repeatable check or Pester assertion that proves the expected behavior.

Stopped automatic services

1PS> Get-Service |
2PS> Where-Object {
3PS> $_.Status -eq 'Stopped' -and
4PS> $_.StartType -eq 'Automatic'
5PS> } |
6PS> Select-Object Name, DisplayName, Status, StartType

Verification idea

Show reference output
1 It 'returns only stopped automatic services' {
2 $result | ForEach-Object {
3 $_.Status | Should -Be 'Stopped'
4 $_.StartType | Should -Be 'Automatic'
5 }
6 }

Large file inventory

1PS> Get-ChildItem -File -Recurse |
2PS> Where-Object Length -gt 100MB |
3PS> Select-Object FullName, Length, LastWriteTime

Verification idea

1PS> $result | ForEach-Object {
2PS> $_.Length | Should -BeGreaterThan 100MB
3PS> }

Azure resource inventory

1PS> Connect-AzAccount
2PS> Get-AzContext
3PS> Get-AzResource |
4PS> Select-Object Name, ResourceType, ResourceGroupName, Location

Verification starts by confirming tenant/subscription context before trusting inventory results.

Entra user review

1PS> Connect-MgGraph -Scopes 'User.Read.All'
2PS> Get-MgContext
3PS> Get-MgUser -All -Property Id,DisplayName,UserPrincipalName,AccountEnabled

Keep discovery separate from account changes. Export a review queue before remediation.

Continue
Genie guideFind a useful script

Use this library to choose a workflow before opening its implementation. Start with the report you need, then follow the linked script to inspect parameters and assumptions. Browse Scripts when you already know which command or task you need.