This manual documents a comprehensive collection of PowerShell scripts for managing all aspects of on-premises Windows environments, including Active Directory, Windows 10/11 clients, Windows Server, Exchange Server, and SharePoint Server. These scripts are designed for system administrators to automate common tasks, configure systems, and generate detailed reports.
Author: Michael Witzsche
Date: April 26, 2025
Version: 1.0.0
- PowerShell 5.1 or PowerShell 7.x
- Required PowerShell modules:
- ActiveDirectory
- GroupPolicy
- ServerManager
- DnsServer
- NetTCPIP
- ExchangeManagementShell (for Exchange scripts)
- SharePoint.PowerShell (for SharePoint scripts)
- ImportExcel (for report export)
- Install required PowerShell modules:
# Install general modules
Install-Module -Name ImportExcel -Force
# For Active Directory management
Add-WindowsFeature RSAT-AD-PowerShell
# For Exchange management (run on Exchange server)
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
# For SharePoint management (run on SharePoint server)
Add-PSSnapin Microsoft.SharePoint.PowerShell- Download the scripts to your local machine
- Ensure execution policy allows running the scripts:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserScripts for managing Active Directory users, groups, organizational units, and other objects.
Description: Creates a new user in Active Directory with specified attributes and group memberships.
Parameters:
FirstName- First name of the userLastName- Last name of the userSamAccountName- SAM account name for the userUserPrincipalName- User principal name (email format)Password- Initial passwordChangePasswordAtLogon- Whether to force password change at next logonEnabled- Whether the account should be enabledDepartment- User's departmentTitle- User's job titleCompany- User's company namePath- OU path where the user will be createdGroups- Array of group names to add the user toLogPath- Path where logs will be stored
Example:
.\New-ADUser.ps1 -FirstName "John" -LastName "Doe" -SamAccountName "jdoe" -UserPrincipalName "john.doe@contoso.com" -Password (ConvertTo-SecureString "P@ssw0rd123" -AsPlainText -Force) -ChangePasswordAtLogon $true -Enabled $true -Department "IT" -Title "System Administrator" -Company "Contoso" -Path "OU=IT,OU=Users,DC=contoso,DC=com" -Groups @("IT Staff", "Domain Admins")Description: Creates a new security or distribution group in Active Directory.
Parameters:
Name- Name of the groupSamAccountName- SAM account name for the groupGroupScope- Scope of the group (Global, Universal, DomainLocal)GroupCategory- Category of the group (Security, Distribution)Description- Description of the groupPath- OU path where the group will be createdMembers- Array of user SAM account names to add as group membersMemberOf- Array of group names to add this group as a member ofLogPath- Path where logs will be stored
Example:
.\New-ADGroup.ps1 -Name "IT Department" -SamAccountName "IT_Dept" -GroupScope "Global" -GroupCategory "Security" -Description "IT Department Security Group" -Path "OU=Groups,DC=contoso,DC=com" -Members @("jdoe", "asmith") -MemberOf @("All Staff")Description: Creates a new organizational unit in Active Directory with optional nested OUs.
Parameters:
Name- Name of the organizational unitPath- Parent path where the OU will be createdDescription- Description of the OUProtectedFromAccidentalDeletion- Whether the OU is protected from accidental deletionNestedOUs- Array of nested OUs to create within this OULogPath- Path where logs will be stored
Example:
$nestedOUs = @(
@{Name="Users"; Description="Department Users"; Protected=$true},
@{Name="Computers"; Description="Department Computers"; Protected=$true},
@{Name="Groups"; Description="Department Groups"; Protected=$true}
)
.\New-ADOrganizationalUnit.ps1 -Name "IT" -Path "DC=contoso,DC=com" -Description "IT Department" -ProtectedFromAccidentalDeletion $true -NestedOUs $nestedOUsDescription: Generates a comprehensive report of Active Directory users including account information, group memberships, and last logon time.
Parameters:
SearchBase- The OU to search for usersFilter- LDAP filter to apply to the searchProperties- Array of user properties to include in the reportIncludeGroups- Whether to include group memberships in the reportIncludeLastLogon- Whether to include last logon information in the reportExportPath- Path where the report will be savedExportFormat- Format of the export file (CSV, JSON, Excel, HTML)LogPath- Path where logs will be stored
Example:
.\Export-ADUserReport.ps1 -SearchBase "OU=Users,DC=contoso,DC=com" -Filter "Department -eq 'IT'" -Properties @("Name", "Title", "Department", "Manager", "EmailAddress", "Enabled") -IncludeGroups $true -IncludeLastLogon $true -ExportPath "C:\Reports\ADUsers.xlsx" -ExportFormat "Excel"Description: Generates a report of Active Directory groups and their members.
Parameters:
SearchBase- The OU to search for groupsFilter- LDAP filter to apply to the searchIncludeMembers- Whether to include group members in the reportIncludeNestedGroups- Whether to include nested group membershipsExportPath- Path where the report will be savedExportFormat- Format of the export file (CSV, JSON, Excel, HTML)LogPath- Path where logs will be stored
Example:
.\Export-ADGroupReport.ps1 -SearchBase "OU=Groups,DC=contoso,DC=com" -Filter "*" -IncludeMembers $true -IncludeNestedGroups $true -ExportPath "C:\Reports\ADGroups.xlsx" -ExportFormat "Excel"Scripts for managing Windows 10/11 client computers, including inventory, updates, settings, and more.
Description: Collects comprehensive hardware and software inventory from Windows client computers.
Parameters:
ComputerName- Name of the target computer(s)Credential- Credentials to use for remote connectionIncludeHardware- Whether to include hardware informationIncludeSoftware- Whether to include installed softwareIncludeUpdates- Whether to include installed updatesIncludeServices- Whether to include running servicesExportPath- Path where the inventory will be savedExportFormat- Format of the export file (CSV, JSON, Excel, HTML)LogPath- Path where logs will be stored
Example:
.\Get-ComputerInventory.ps1 -ComputerName @("PC001", "PC002") -Credential (Get-Credential) -IncludeHardware $true -IncludeSoftware $true -IncludeUpdates $true -IncludeServices $true -ExportPath "C:\Reports\Inventory.xlsx" -ExportFormat "Excel"Description: Installs Windows updates on local or remote computers.
Parameters:
ComputerName- Name of the target computer(s)Credential- Credentials to use for remote connectionUpdateType- Type of updates to install (Security, Critical, All)RebootIfRequired- Whether to reboot the computer if requiredScheduleReboot- Time to schedule reboot (if not immediate)LogPath- Path where logs will be stored
Example:
.\Install-WindowsUpdates.ps1 -ComputerName @("PC001", "PC002") -Credential (Get-Credential) -UpdateType "Security" -RebootIfRequired $true -ScheduleReboot "22:00"Description: Configures various Windows settings on local or remote computers.
Parameters:
ComputerName- Name of the target computer(s)Credential- Credentials to use for remote connectionPowerSettings- Power plan settings to configureUAC- User Account Control settingsWindowsFeatures- Windows features to enable or disableRegistrySettings- Registry settings to configureLogPath- Path where logs will be stored
Example:
$powerSettings = @{
PlanName = "High Performance"
TurnOffDisplayMinutes = 15
SleepMinutes = 30
}
$registrySettings = @(
@{Path="HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; Name="EnableLUA"; Value=1; Type="DWord"},
@{Path="HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; Name="ConsentPromptBehaviorAdmin"; Value=2; Type="DWord"}
)
.\Set-WindowsConfiguration.ps1 -ComputerName "PC001" -Credential (Get-Credential) -PowerSettings $powerSettings -UAC "Default" -WindowsFeatures @{Enable=@("Telnet-Client"); Disable=@("Internet-Explorer-Optional-amd64")} -RegistrySettings $registrySettingsDescription: Renames a local or remote computer and optionally joins it to a domain.
Parameters:
ComputerName- Current name of the computerNewName- New name for the computerCredential- Credentials to use for remote connectionDomainName- Domain to join (if not already joined)DomainCredential- Credentials to use for domain joinRestart- Whether to restart the computer after renamingLogPath- Path where logs will be stored
Example:
.\Rename-Computer.ps1 -ComputerName "PC001" -NewName "LAPTOP-SALES01" -Credential (Get-Credential) -DomainName "contoso.com" -DomainCredential (Get-Credential) -Restart $trueDescription: Analyzes Windows event logs for errors, warnings, and specific events.
Parameters:
ComputerName- Name of the target computer(s)Credential- Credentials to use for remote connectionLogName- Name of the event log(s) to analyzeStartTime- Start time for the analysisEndTime- End time for the analysisEventType- Type of events to include (Error, Warning, Information, All)EventID- Specific event IDs to search forExportPath- Path where the analysis will be savedExportFormat- Format of the export file (CSV, JSON, Excel, HTML)LogPath- Path where logs will be stored
Example:
.\Get-EventLogAnalysis.ps1 -ComputerName "DC01" -Credential (Get-Credential) -LogName @("System", "Application") -StartTime (Get-Date).AddDays(-7) -EndTime (Get-Date) -EventType @("Error", "Warning") -EventID @(1001, 1018, 4624) -ExportPath "C:\Reports\EventLogs.xlsx" -ExportFormat "Excel"Description: Configures Windows Firewall settings and rules on local or remote computers.
Parameters:
ComputerName- Name of the target computer(s)Credential- Credentials to use for remote connectionProfileSettings- Settings for each firewall profile (Domain, Private, Public)Rules- Firewall rules to create or modifyLogPath- Path where logs will be stored
Example:
$profileSettings = @{
Domain = @{Enabled=$true; DefaultInboundAction="Block"; DefaultOutboundAction="Allow"; LogAllowed=$true}
Private = @{Enabled=$true; DefaultInboundAction="Block"; DefaultOutboundAction="Allow"; LogBlocked=$true}
Public = @{Enabled=$true; DefaultInboundAction="Block"; DefaultOutboundAction="Allow"; LogMaxSizeKB=4096}
}
$rules = @(
@{Name="Allow RDP"; Direction="Inbound"; Action="Allow"; Protocol="TCP"; LocalPort=3389; Profile=@("Domain", "Private")},
@{Name="Block Telnet"; Direction="Inbound"; Action="Block"; Protocol="TCP"; LocalPort=23; Profile=@("Domain", "Private", "Public")}
)
.\Set-FirewallConfiguration.ps1 -ComputerName "PC001" -Credential (Get-Credential) -ProfileSettings $profileSettings -Rules $rulesScripts for managing Windows Server, including Desired State Configuration, IIS, domain joining, and GPO management.
Description: Creates and applies a Desired State Configuration to Windows servers.
Parameters:
ComputerName- Name of the target computer(s)Credential- Credentials to use for remote connectionConfigurationName- Name of the DSC configurationConfigurationData- Configuration data for the DSC configurationFeatures- Windows features to install or removeServices- Services to configureRegistrySettings- Registry settings to configureFiles- Files to create or modifyOutputPath- Path where the MOF files will be savedApplyConfiguration- Whether to apply the configuration immediatelyLogPath- Path where logs will be stored
Example:
$features = @(
@{Name="Web-Server"; Ensure="Present"},
@{Name="Web-Asp-Net45"; Ensure="Present"},
@{Name="Telnet-Client"; Ensure="Absent"}
)
$services = @(
@{Name="BITS"; State="Running"; StartupType="Automatic"},
@{Name="Spooler"; State="Running"; StartupType="Automatic"}
)
.\New-DSCConfiguration.ps1 -ComputerName "WEB01" -Credential (Get-Credential) -ConfigurationName "WebServerConfig" -Features $features -Services $services -RegistrySettings @() -Files @() -OutputPath "C:\DSC" -ApplyConfiguration $trueDescription: Installs and configures Internet Information Services (IIS) on Windows Server.
Parameters:
ComputerName- Name of the target computer(s)Credential- Credentials to use for remote connectionFeatures- IIS features to installWebsiteName- Name of the website to createWebsitePath- Physical path for the websiteAppPoolName- Name of the application poolAppPoolIdentity- Identity for the application poolBindingInformation- Binding information for the websiteLogPath- Path where logs will be stored
Example:
$features = @(
"Web-Server",
"Web-Common-Http",
"Web-Default-Doc",
"Web-Dir-Browsing",
"Web-Http-Errors",
"Web-Static-Content",
"Web-Http-Logging",
"Web-Stat-Compression",
"Web-Filtering",
"Web-Mgmt-Console",
"Web-Asp-Net45"
)
.\Install-IISServer.ps1 -ComputerName "WEB01" -Credential (Get-Credential) -Features $features -WebsiteName "Corporate Intranet" -WebsitePath "C:\inetpub\wwwroot\intranet" -AppPoolName "IntranetAppPool" -AppPoolIdentity "ApplicationPoolIdentity" -BindingInformation "*:80:intranet.contoso.com"Description: Joins a computer to an Active Directory domain.
Parameters:
ComputerName- Name of the target computer(s)Credential- Credentials to use for remote connectionDomainName- Name of the domain to joinDomainCredential- Credentials to use for domain joinOrganizationalUnit- OU path where the computer account will be createdRestart- Whether to restart the computer after joiningLogPath- Path where logs will be stored
Example:
.\Join-Domain.ps1 -ComputerName "WEB01" -Credential (Get-Credential) -DomainName "contoso.com" -DomainCredential (Get-Credential) -OrganizationalUnit "OU=Servers,DC=contoso,DC=com" -Restart $trueDescription: Creates, modifies, and links Group Policy Objects in Active Directory.
Parameters:
Action- Action to perform (Create, Modify, Link, Unlink, Remove)GPOName- Name of the GPODomain- Domain where the GPO existsComment- Comment for the GPOTargetOU- OU to link the GPO toLinkEnabled- Whether the GPO link is enabledSettings- Group Policy settings to configureLogPath- Path where logs will be stored
Example:
$settings = @(
@{Type="Registry"; Key="HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU"; ValueName="NoAutoUpdate"; Value=0; ValueType="DWord"},
@{Type="Registry"; Key="HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU"; ValueName="AUOptions"; Value=4; ValueType="DWord"}
)
.\Manage-GroupPolicy.ps1 -Action "Create" -GPOName "Windows Update Settings" -Domain "contoso.com" -Comment "Configures Windows Update settings" -TargetOU "OU=Workstations,DC=contoso,DC=com" -LinkEnabled $true -Settings $settingsDescription: Analyzes Windows Server event logs for critical events and generates a report.
Parameters:
ComputerName- Name of the target server(s)Credential- Credentials to use for remote connectionLogName- Name of the event log(s) to analyzeStartTime- Start time for the analysisEndTime- End time for the analysisEventType- Type of events to include (Error, Warning, Critical, All)ExportPath- Path where the report will be savedExportFormat- Format of the export file (CSV, JSON, Excel, HTML)LogPath- Path where logs will be stored
Example:
.\Get-ServerEventLogs.ps1 -ComputerName @("DC01", "WEB01") -Credential (Get-Credential) -LogName @("System", "Application", "Security") -StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date) -EventType @("Error", "Critical") -ExportPath "C:\Reports\ServerEvents.xlsx" -ExportFormat "Excel"Scripts for managing Exchange Server, including mailbox creation, user management, settings configuration, and error analysis.
Description: Creates a new mailbox in Exchange Server.
Parameters:
Name- Name for the mailboxAlias- Email alias for the mailboxFirstName- First name of the userLastName- Last name of the userDisplayName- Display name for the mailboxUserPrincipalName- User principal name (email format)Password- Initial passwordDatabase- Exchange database to store the mailboxMailboxType- Type of mailbox (Regular, Shared, Room, Equipment)OrganizationalUnit- OU path where the user account will be createdLogPath- Path where logs will be stored
Example:
.\New-ExchangeMailbox.ps1 -Name "John Doe" -Alias "jdoe" -FirstName "John" -LastName "Doe" -DisplayName "John Doe" -UserPrincipalName "john.doe@contoso.com" -Password (ConvertTo-SecureString "P@ssw0rd123" -AsPlainText -Force) -Database "Mailbox Database 01" -MailboxType "Regular" -OrganizationalUnit "OU=Users,DC=contoso,DC=com"Description: Creates a new distribution group in Exchange Server.
Parameters:
Name- Name for the distribution groupAlias- Email alias for the groupDisplayName- Display name for the groupPrimarySmtpAddress- Primary SMTP address for the groupMembers- Array of members to add to the groupManagedBy- Array of users who can manage the groupOrganizationalUnit- OU path where the group will be createdLogPath- Path where logs will be stored
Example:
.\New-ExchangeDistributionGroup.ps1 -Name "Sales Team" -Alias "sales" -DisplayName "Sales Team" -PrimarySmtpAddress "sales@contoso.com" -Members @("john.doe@contoso.com", "jane.smith@contoso.com") -ManagedBy @("john.doe@contoso.com") -OrganizationalUnit "OU=Groups,DC=contoso,DC=com"Description: Sets permissions on Exchange mailboxes.
Parameters:
Identity- Identity of the mailboxUser- User to grant permissions toAccessRights- Access rights to grantAutoMapping- Whether to automatically map the mailbox in OutlookInheritanceType- Type of inheritance for the permissionsLogPath- Path where logs will be stored
Example:
.\Set-ExchangeMailboxPermissions.ps1 -Identity "john.doe@contoso.com" -User "jane.smith@contoso.com" -AccessRights @("FullAccess", "SendAs") -AutoMapping $true -InheritanceType "All"Description: Generates a report of Exchange mailboxes including size, item count, and last logon time.
Parameters:
Database- Exchange database to report onFilter- Filter to apply to the mailboxesIncludeSize- Whether to include mailbox size in the reportIncludeItemCount- Whether to include item count in the reportIncludeLastLogon- Whether to include last logon time in the reportExportPath- Path where the report will be savedExportFormat- Format of the export file (CSV, JSON, Excel, HTML)LogPath- Path where logs will be stored
Example:
.\Get-ExchangeMailboxReport.ps1 -Database "Mailbox Database 01" -Filter "RecipientTypeDetails -eq 'UserMailbox'" -IncludeSize $true -IncludeItemCount $true -IncludeLastLogon $true -ExportPath "C:\Reports\MailboxReport.xlsx" -ExportFormat "Excel"Description: Tests the health of Exchange Server components and services.
Parameters:
Server- Name of the Exchange server(s) to testComponents- Components to test (Transport, ClientAccess, Mailbox, All)IncludeDAG- Whether to include Database Availability Group testsIncludeMailflow- Whether to include mail flow testsExportPath- Path where the report will be savedExportFormat- Format of the export file (CSV, JSON, Excel, HTML)LogPath- Path where logs will be stored
Example:
.\Test-ExchangeHealth.ps1 -Server @("EXCH01", "EXCH02") -Components "All" -IncludeDAG $true -IncludeMailflow $true -ExportPath "C:\Reports\ExchangeHealth.html" -ExportFormat "HTML"Scripts for managing SharePoint Server, including site creation, site deletion, and permission management.
Description: Creates a new SharePoint site collection.
Parameters:
URL- URL for the new site collectionTitle- Title for the site collectionDescription- Description of the site collectionTemplate- Template to use for the site collectionOwnerAlias- Owner of the site collectionSecondaryOwnerAlias- Secondary owner of the site collectionContentDatabase- Content database to store the site collectionLanguage- Language for the site collectionTimeZone- Time zone for the site collectionLogPath- Path where logs will be stored
Example:
.\New-SharePointSite.ps1 -URL "https://sharepoint.contoso.com/sites/HR" -Title "Human Resources" -Description "Human Resources Department Site" -Template "STS#0" -OwnerAlias "contoso\jdoe" -SecondaryOwnerAlias "contoso\asmith" -ContentDatabase "WSS_Content" -Language 1033 -TimeZone 4Description: Creates a new SharePoint subsite within an existing site collection.
Parameters:
ParentSiteURL- URL of the parent siteTitle- Title for the subsiteURL- URL name for the subsiteDescription- Description of the subsiteTemplate- Template to use for the subsiteInheritPermissions- Whether to inherit permissions from the parent siteInheritNavigation- Whether to inherit navigation from the parent siteLanguage- Language for the subsiteLogPath- Path where logs will be stored
Example:
.\New-SharePointSubsite.ps1 -ParentSiteURL "https://sharepoint.contoso.com/sites/HR" -Title "Benefits" -URL "Benefits" -Description "Employee Benefits Site" -Template "STS#0" -InheritPermissions $true -InheritNavigation $true -Language 1033Description: Removes a SharePoint site collection.
Parameters:
URL- URL of the site collection to removeGradualDelete- Whether to delete the site graduallyForce- Whether to force deletion of the siteDeleteADAccounts- Whether to delete associated AD accountsLogPath- Path where logs will be stored
Example:
.\Remove-SharePointSite.ps1 -URL "https://sharepoint.contoso.com/sites/Archive" -GradualDelete $true -Force $false -DeleteADAccounts $falseDescription: Sets permissions on SharePoint sites, lists, or items.
Parameters:
SiteURL- URL of the SharePoint siteObjectType- Type of object to set permissions on (Site, List, Item)ObjectName- Name or path of the objectUser- User or group to grant permissions toPermissionLevel- Permission level to grantInheritPermissions- Whether the object should inherit permissionsLogPath- Path where logs will be stored
Example:
.\Set-SharePointPermissions.ps1 -SiteURL "https://sharepoint.contoso.com/sites/HR" -ObjectType "List" -ObjectName "Shared Documents" -User "contoso\HR Team" -PermissionLevel "Contribute" -InheritPermissions $falseDescription: Generates a report of permissions on SharePoint sites, lists, and items.
Parameters:
SiteURL- URL of the SharePoint siteIncludeLists- Whether to include lists in the reportIncludeItems- Whether to include items in the reportIncludeInheritedPermissions- Whether to include inherited permissionsExportPath- Path where the report will be savedExportFormat- Format of the export file (CSV, JSON, Excel, HTML)LogPath- Path where logs will be stored
Example:
.\Get-SharePointPermissionReport.ps1 -SiteURL "https://sharepoint.contoso.com/sites/HR" -IncludeLists $true -IncludeItems $false -IncludeInheritedPermissions $false -ExportPath "C:\Reports\SharePointPermissions.xlsx" -ExportFormat "Excel"