top of page

Powershell: Level 1 scripts

​

1. Automating User Account Creation

​

Scenario: IT support often needs to create new Active Directory (AD) user accounts for onboarding employees.Why It’s Useful: Automates repetitive tasks, reduces errors, and ensures consistency.Implementation:

​

# Import Active Directory module

​

Import-Module ActiveDirectory

​

# Create a new user

 

New-ADUser -Name "John Doe" -GivenName "John" -Surname "Doe" -SamAccountName "jdoe" -UserPrincipalName "jdoe@domain.com" -Path "OU=Users,DC=domain,DC=com" -AccountPassword (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force) -Enabled $true

 

This script creates a new AD user with a default password and places them in a specific organizational unit (OU).

​

2. Password Reset Automation

 

Scenario: Level 1 support frequently handles password reset requests.Why It’s Useful: Simplifies the process and reduces response time.Implementation:

 

# Reset AD password

 

$Username = Read-Host "Enter username for password reset"

Set-ADAccountPassword -Identity $Username -Reset -NewPassword (ConvertTo-SecureString "NewP@ssw0rd123" -AsPlainText -Force)

Enable-ADAccount -Identity $Username

 

This script resets a user’s password and re-enables their account if it’s locked.

 

3. Exporting AD Group Membership

 

Scenario: IT teams need to generate reports of users in specific AD groups for audits or troubleshooting.Why It’s Useful: Provides quick insights into group memberships for compliance or troubleshooting.Implementation:

 

# Export group members to CSV

 

Get-ADGroupMember -Identity "IT Support" | Select-Object Name, SamAccountName | Export-Csv -Path "ITSupportGroup.csv" -NoTypeInformation

 

This script exports the members of the "IT Support" group to a CSV file.

​

4. Disk Space Monitoring

 

Scenario: IT support needs to monitor disk space on servers and workstations to prevent outages.Why It’s Useful: Proactively identifies storage issues before they cause downtime.Implementation:

 

# Check disk space

 

$Threshold = 10

$Drives = Get-PSDrive -PSProvider FileSystem

foreach ($Drive in $Drives) {

    if ($Drive.Free -lt ($Threshold * 1GB)) {

        Write-Output "$($Drive.Name) is running low on space!"

    }

}

 

This script checks all drives and alerts if free space is below 10 GB.

 

5. Automating Software Installation

 

Scenario: IT teams often need to install or update software across multiple machines.Why It’s Useful: Saves time by automating repetitive installation tasks.Implementation:

 

# Install software silently

 

Start-Process -FilePath "C:\Installers\app.msi" -ArgumentList "/quiet /norestart" -Wait

 

This script installs software silently using an .msi installer.

 

6. Monitoring Server Uptime

 

Scenario: IT support needs to ensure critical servers are online and responsive.Why It’s Useful: Quickly detects outages and minimizes downtime.Implementation:

 

# Ping servers to check uptime

 

$Servers = @("192.168.1.1", "192.168.1.2")

foreach ($Server in $Servers) {

    if (Test-Connection -ComputerName $Server -Count 2 -Quiet) {

        Write-Output "$Server is online."

    } else {

        Write-Output "$Server is offline!"

    }

}

 

This script pings a list of servers and reports their status.

 

7. Bulk User Account Unlock

 

Scenario: After a system outage, multiple user accounts may become locked.Why It’s Useful: Quickly unlocks multiple accounts to restore access.Implementation:

 

# Unlock all locked accounts

 

Search-ADAccount -LockedOut | ForEach-Object { Unlock-ADAccount -Identity $_.SamAccountName }

 

This script finds all locked accounts in AD and unlocks them.

 

8. Generating System Information Reports

 

Scenario: IT teams need to gather system information for troubleshooting or inventory purposes.Why It’s Useful: Provides detailed system information in a structured format.Implementation:

 

# Generate system info report

 

Get-ComputerInfo | Select-Object CsName, WindowsVersion, OsArchitecture, CsManufacturer, CsModel | Export-Csv -Path "SystemInfo.csv" -NoTypeInformation

 

This script collects system information and exports it to a CSV file.

 

9. Monitoring Event Logs for Errors

 

Scenario: IT support needs to monitor Windows Event Logs for critical errors.Why It’s Useful: Helps identify and resolve issues proactively.Implementation:

 

# Monitor event logs for errors

 

Get-EventLog -LogName System -EntryType Error -Newest 10 | Select-Object TimeGenerated, EntryType, Source, Message

 

This script retrieves the 10 most recent error entries from the System Event Log.

 

10. Automating Printer Configuration

 

Scenario: IT support often needs to configure printers for new users or machines.Why It’s Useful: Simplifies printer setup and reduces manual effort.Implementation:

 

# Add a network printer

 

Add-Printer -Name "OfficePrinter" -DriverName "HP Universal Printing PCL 6" -PortName "192.168.1.100"

 

This script adds a network printer with the specified driver and port.


    
    ​​

​

​​

  • Facebook - Black Circle
  • Twitter - Black Circle

© 2023 by IT SERVICES.  Proudly created with Wix.com

bottom of page