
Level 3 scripts
1. Automating Active Directory Health Checks
​
Scenario: Perform a health check of the AD environment.
# Check AD health
dcdiag /q | Out-File "ADHealthCheck.txt"
2. Monitoring and Killing Suspicious Processes
Scenario: Identify and terminate malicious processes.
# Kill suspicious processes
$MaliciousProcesses = @("malware.exe", "ransomware.exe")
Get-Process | Where-Object { $MaliciousProcesses -contains $_.Name } | Stop-Process -Force
3. Automating GPO Backup
Scenario: Backup all Group Policy Objects (GPOs).
# Backup GPOs
Backup-GPO -All -Path "C:\GPOBackups"
4. Managing Certificates
Scenario: Export SSL certificates for backup or migration.
# Export certificates
Get-ChildItem -Path Cert:\LocalMachine\My | Export-Certificate -FilePath "C:\Certs\cert.cer"
5. Automating Security Log Analysis
Scenario: Analyze security logs for failed login attempts.
# Analyze security logs
Get-EventLog -LogName Security -EntryType FailureAudit | Where-Object { $_.EventID -eq 4625 } | Export-Csv -Path "FailedLogins.csv" -NoTypeInformation
6. Automating Server Performance Reports
Scenario: Generate performance reports for critical servers.
# Generate performance report
Get-Counter -Counter "\Processor(_Total)\% Processor Time" | Export-Csv -Path "PerformanceReport.csv" -NoTypeInformation
7. Managing Firewall Rules
Scenario: Add or remove firewall rules for specific applications.
# Add a firewall rule
New-NetFirewallRule -DisplayName "AllowApp" -Direction Inbound -Program "C:\Path\To\App.exe" -Action Allow
8. Automating User Account Audits
Scenario: Identify inactive user accounts in AD.
# Find inactive accounts
Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 | Export-Csv -Path "InactiveAccounts.csv" -NoTypeInformation
9. Automating Patch Compliance Checks
Scenario: Check if critical patches are installed on servers.
# Check installed updates
Get-HotFix | Where-Object { $_.Description -like "*Security*" } | Export-Csv -Path "PatchCompliance.csv" -NoTypeInformation
Example 10: Automating Printer Configuration with PowerShell
Scenario
IT support teams often need to configure printers for new users or machines, especially in environments where multiple network printers are used. Manually adding printers can be time-consuming, especially when dealing with a large number of devices.
Why It’s Useful
Automating printer configuration with PowerShell simplifies the process, reduces manual effort, and ensures consistency. This is particularly helpful in enterprise environments where printers are shared across departments or locations.
Implementation
Here’s how you can use PowerShell to automate the addition of a network printer:
# Add a network printer
Add-Printer -Name "OfficePrinter" -DriverName "HP Universal Printing PCL 6" -PortName "192.168.1.100"
Explanation
​
-
Add-Printer Cmdlet:
-
This cmdlet is used to add a new printer to the system.
-
It supports both local and network printers.
-
-
Parameters:
-
-Name: Specifies the name of the printer as it will appear on the system (e.g., "OfficePrinter").
-
-DriverName: Specifies the printer driver to use. Ensure the driver is already installed on the system.
-
-PortName: Specifies the port or IP address of the printer. For network printers, this is typically the printer’s IP address.
-
-
Example Use Case:
-
A new employee joins the company, and their workstation needs to be configured with access to the office printer. Instead of manually adding the printer through the Control Panel, the IT support team can run this script to configure the printer in seconds.
-
Advanced Use Case: Adding Multiple Printers
If you need to configure multiple printers at once, you can use a loop to automate the process:
powershell
# Add multiple printers
$Printers = @(
@{Name="HRPrinter"; Driver="HP Universal Printing PCL 6"; Port="192.168.1.101"},
@{Name="FinancePrinter"; Driver="Canon Generic PCL6"; Port="192.168.1.102"},
@{Name="ITPrinter"; Driver="Brother HL-L2350DW"; Port="192.168.1.103"}
)
foreach ($Printer in $Printers) {
Add-Printer -Name $Printer.Name -DriverName $Printer.Driver -PortName $Printer.Port
}
