
Powershell...Level 2examples
1. Automating Software Deployment
​
Scenario: Deploy software to multiple machines in the network.
# Deploy software to multiple computers
$Computers = @("PC1", "PC2", "PC3")
foreach ($Computer in $Computers) {
Invoke-Command -ComputerName $Computer -ScriptBlock {
Start-Process -FilePath "\\Server\Share\Installer.msi" -ArgumentList "/quiet /norestart" -Wait
}
}
2. Checking Windows Update Status
Scenario: Ensure all systems are up to date with the latest patches.
# Check update status
Get-WindowsUpdateLog | Select-String "Failed" | Out-File "UpdateErrors.txt"
3. Managing Shared Folder Permissions
Scenario: Modify permissions for shared folders on a server.
# Set permissions for a shared folder
$Path = "C:\SharedFolder"
$User = "DOMAIN\User"
$Permission = "Read"
icacls $Path /grant "$User:($Permission)"
4. Monitoring CPU and Memory Usage
Scenario: Monitor resource usage on critical servers.
# Monitor CPU and memory usage
Get-WmiObject Win32_Processor | Select-Object LoadPercentage
Get-WmiObject Win32_OperatingSystem | Select-Object FreePhysicalMemory
5. Exporting Installed Software List
Scenario: Generate a list of installed software for inventory purposes.
# Export installed software
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion | Export-Csv -Path "InstalledSoftware.csv" -NoTypeInformation
6. Automating Printer Deployment
Scenario: Add printers to multiple machines.
# Add a network printer
Add-Printer -Name "OfficePrinter" -DriverName "HP Universal Printing PCL 6" -PortName "192.168.1.100"
7. Restarting Services on Remote Machines
Scenario: Restart a problematic service on multiple computers.
# Restart a service remotely
$Computers = @("PC1", "PC2", "PC3")
foreach ($Computer in $Computers) {
Invoke-Command -ComputerName $Computer -ScriptBlock {
Restart-Service -Name "Spooler"
}
}
8. Checking Active Directory Replication
Scenario: Verify AD replication status across domain controllers.
# Check AD replication
Get-ADReplicationPartnerMetadata -Target "DC1" | Format-Table
9. Automating Disk Cleanup
Scenario: Free up disk space by deleting temporary files.
# Delete temp files
Remove-Item -Path "C:\Temp\*" -Recurse -Force
10. Exporting Event Logs for Analysis
Scenario: Export logs for troubleshooting system issues.
# Export event logs
Get-EventLog -LogName Application -Newest 1000 | Export-Csv -Path "ApplicationLogs.csv" -NoTypeInformation
