MSP StockroomFind a guide, template or tool…/
Field guides / Standards and documentation

ST-02 Field guide / Standards and documentation

Review a community PowerShell script or GPO before it touches a client

A script from a forum or a GPO backup from a blog runs with your RMM's or your domain admin's rights. Read every line before it runs, test it where a mistake is cheap, and know how to undo it before it reaches a client.

5 min read / Updated Dec 2026

For Service desk & technicians, Tech lead, Cybersecurity, Automation & AI

On this page

1. Get the exact file, and do not run it

Download the raw file from its source repository, not text copied out of a web page or a chat. Save it to a review folder on a machine that is not a client's. Record the URL, the author, the version or commit, and the licence. Then record its hash, so you can prove later that the file you deploy is the file you reviewed:

Get-FileHash -Path .\candidate.ps1   # SHA256 by default

Do not rely on execution policy to protect you here. Microsoft notes that files downloaded with Invoke-WebRequest, Invoke-RestMethod or curl.exe may not be marked as coming from the internet, so a RemoteSigned policy will not treat them as remote.

2. Read every line, starting with the red flags

Run a read-only search first to find the lines that need the closest look:

Select-String -Path .\candidate.ps1 -Pattern 'Invoke-Expression|iex|DownloadString|DownloadFile|Invoke-WebRequest|iwr|Invoke-RestMethod|irm|FromBase64String|EncodedCommand|-enc|Bypass|Set-ExecutionPolicy|AsPlainText|DisableRealtimeMonitoring|ExclusionPath|http'

A clean result does not make the script safe. Obfuscated code can avoid every pattern. Read the whole file, and reject it if you hit any of these without a clear reason:

  • Download and execute: fetching code at run time and passing it to Invoke-Expression, or downloading an executable and starting it. You reviewed this file, not whatever that URL serves tomorrow.
  • Encoded or packed content: -EncodedCommand takes a Base64 string, and [Convert]::FromBase64String decodes one. Decode it and read it, or reject it.
  • Weakening protection: Set-MpPreference -DisableRealtimeMonitoring $true, Add-MpPreference -ExclusionPath, turning off the firewall, logging or tamper protection.
  • Credentials in the script: passwords, API keys, tokens, or ConvertTo-SecureString -AsPlainText with a literal value. Secrets belong in your RMM's or vault's secret store, passed in at run time.
  • Persistence and privilege changes: new local admins, scheduled tasks, services, Run keys or new user accounts that the script's stated purpose does not need.
  • Broad destruction: Remove-Item -Recurse -Force on a path built from a variable that could be empty.

Then write down, in one line each, what the script reads, what it changes, and where it sends data. If you cannot, you do not understand it well enough to run it.

3. Check signing and execution policy for what they are

Get-AuthenticodeSignature -FilePath .\candidate.ps1 shows whether the file is signed and by whom. A Valid signature tells you who published the file and that it has not changed since. It does not tell you the code is safe, and most community scripts are unsigned.

Microsoft states plainly that execution policy is not a security boundary. Check what applies on a target with Get-ExecutionPolicy -List. A policy set by the Turn on Script Execution Group Policy setting overrides every other scope, including -ExecutionPolicy Bypass on the command line. If your clients run AllSigned, sign the reviewed file with your own code-signing certificate after review. Any later edit breaks the signature, which is the point.

4. For a GPO: read the report, then check the scope

Import a community GPO backup into a new, unlinked GPO in your lab domain, never straight into a client. Generate a report by GUID, because display names are not guaranteed unique:

Get-GPOReport -Guid <gpo-guid> -ReportType Html -Path .\candidate-gpo.html -Domain lab.contoso.com

The report shows settings, links, security filtering, WMI filtering and delegation. Look for:

  • Startup, shutdown, logon or logoff scripts, and where they load from. A script on a share someone else can write to is a way in.
  • Group Policy Preferences items that store passwords (mapped drives, local users, scheduled tasks, services, data sources). Microsoft removed this ability in MS14-025 because the stored passwords can be decrypted by any domain user. Reject any GPO that carries one.
  • User rights assignments, restricted groups and local group changes.
  • Security settings that loosen a baseline: SMB signing, NTLM, LDAP signing, firewall rules, Defender settings.

Then decide scope before linking anything: which OU, whether it is enforced, which security filter and which WMI filter. Write that down as part of the change.

5. Test in a lab, then a pilot ring

In the lab, take a VM snapshot first. Turn on Turn on PowerShell Script Block Logging (Administrative Templates, Windows Components, Windows PowerShell; PowerShell 7 has its own PowerShell Core template). PowerShell then records the content of every script block it processes in the Microsoft-Windows-PowerShell/Operational log as event 4104, so you see what actually ran, not what the file appeared to say. Run the script the way your RMM will run it, as the same account and context. Compare files, services, scheduled tasks and local groups before and after.

For a GPO, link it to a test OU containing one lab machine and one machine outside the OU. Run gpupdate /force, then confirm what applied with Get-GPResultantSetOfPolicy -Computer lab.contoso.com\pc01 -ReportType Html -Path .\rsop.html. Confirm the outside machine is unchanged.

Then a pilot ring: your own staff machines first, then a small named group at one client, with the client told. Wait at least one full business day of normal use before going wider.

6. Write the rollback before you deploy

  • Script: list every change it makes and how to reverse each one. If it has no undo, the change ticket says so and gets a second approval.
  • GPO: back up the target first with Backup-GPO -Guid <gpo-guid> -Path <backup-folder>. A restore with Restore-GPO puts the settings back, but it does not touch links, and it restores the link to a WMI filter but not the filter itself. Record links, link order and filters separately.
  • Tattooed settings: unlinking or deleting a GPO does not necessarily undo what it already applied. Microsoft warns that removing a preference item from a GPO does not necessarily remove settings already applied to clients. Plan an explicit reversing change for those.

Finally, record the approved file's hash and version in the change ticket. Any upstream update is a new candidate and goes through this review again.

Checklist / Usable takeaway

Script and GPO review checklist

  • Source: [URL / author / version or commit / licence] and SHA256 hash recorded.
  • Red-flag search run and every line read. Download-and-execute, encoded content, weakened protection or embedded secrets: none, or rejected.
  • One line each: what it reads / what it changes / where it sends data.
  • Signature checked with Get-AuthenticodeSignature; execution policy on targets checked with Get-ExecutionPolicy -List.
  • GPO: report reviewed by GUID; no GPP stored passwords; scope written down (OU / enforced / security filter / WMI filter).
  • Lab: snapshot taken, script block logging on, run as the RMM runs it, before and after compared.
  • Pilot ring: [machines / client told / date] and one business day without issues.
  • Rollback written and tested; GPO backed up; links and filters recorded; approved hash in the change ticket.

A failed red-flag check ends the review. Rejecting a script is a normal result, not a failure of the process.

Sources and notes

Cmdlet names, parameters, the event ID and Group Policy behaviour were checked against Microsoft Learn. The red-flag list is a starting point for a human reviewer, not a scanner. Run commands from an account with only the rights the review needs. Vendor details checked December 1, 2026. See method and evidence notes.

Search the stockroom

↑ ↓ to choose · Enter to open · Esc to close

Open the full search page →