Skip to content

About

automation scripts in powershell

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Windows endpoint security

Use 64-bit Windows PowerShell 5.1 on a Windows endpoint with Windows Firewall and Microsoft Defender Antivirus. Apply rules and run the audit from an elevated PowerShell session.

Run the scripts under your endpoint's approved PowerShell execution policy. If your policy requires signed scripts, sign them through your organization's existing process.

Manage firewall rules

Replace the documentation subnet, port, and profile with settings for your endpoint. Preview first, then remove -WhatIf to apply.

.\Set-EndpointFirewallRule.ps1 -Id internal-https -Direction Inbound -Action Allow -Profile Domain -Protocol TCP -Port 443 -RemoteAddress '192.0.2.0/24' -WhatIf

Inbound rules match a local port and outbound rules match a remote port. Supply -Program with an absolute executable path when a rule should apply to a single application. Omitting it matches all programs. Reuse the same ID and direction to update the rule. Choose the narrowest subnet and profile that cover the intended traffic.

Check whether Windows includes the local rule in its effective policy. Group Policy or device management can control local rule merging, and other rules may affect the same traffic. Also test connectivity from an allowed and a disallowed source. Microsoft firewall rule documentation

Get-NetFirewallRule -PolicyStore ActiveStore -Name 'EndpointSecurity-internal-https'
Remove-NetFirewallRule -PolicyStore PersistentStore -Name 'EndpointSecurity-internal-https' -WhatIf

Audit endpoint health

.\Test-EndpointSecurity.ps1 -LookbackHours 24 -ReportPath .\endpoint-health.json
.\Test-EndpointSecurity.ps1 -CheckIntegrity -ReportPath .\endpoint-integrity.json

The JSON includes effective firewall profile settings, Defender protection and signature status, active threats, and recent Defender events, service installations, and Security log clears. Matching events warrant review and can include routine changes. Each event query keeps up to 200 records. Keep reports access-restricted because event messages can include local paths and security details. Microsoft Defender PowerShell reference · Effective firewall profiles

-CheckIntegrity scans the Windows component store using DISM and verifies protected system files with SFC. Review Integrity.SystemFileChecker.Output for the localized integrity result, including when the process exits successfully. Both scans can take time. DISM PowerShell reference · SFC command reference

Exit code Meaning
0 Checks completed with no automated findings. Review SFC output if requested.
1 One or more findings need review.
2 One or more checks could not complete or need manual verification. Review both Errors and Findings.

For recurring monitoring, create a daily Windows Task Scheduler task under an administrator account and enable Run with highest privileges. Use powershell.exe with the arguments below, substituting absolute paths. Store the script and report in directories writable only by trusted administrators and the task account. This example overwrites the latest report on each run. Schedule a weekly task with -CheckIntegrity and a separate report path for periodic integrity scans.

-NoProfile -NonInteractive -File "C:\EndpointSecurity\Test-EndpointSecurity.ps1" -LookbackHours 26 -ReportPath "C:\EndpointSecurity\endpoint-health.json"

About

automation scripts in powershell

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages