This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# batch replace domain name portion of UPN in active directory | |
$SearchBase = "OU=Domain Users, DC=contoso, DC=com" | |
$OldDN = "contoso.com.local" | |
$NewDN = "contoso.com" | |
Import-Module ActiveDirectory | |
Get-ADUser -Filter { UserPrincipalName -like "*$OldDN" } -SearchBase $SearchBase | | |
ForEach-Object { | |
Write-Host $_.Name | |
$Upn = $_.UserPrincipalName.Replace( $OldDN, $NewDN ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ProcessName = "outlook" | |
$DateOffset = 30 | |
$StartDate = (Get-Date).AddDays(-($DateOffset)) | |
$SearchBase = "OU=Domain Computers, DC=contoso, DC=com" | |
Get-ADComputer -Filter { | |
( LastLogonDate -gt $StartDate ) -and | |
( Name -ne "$env:COMPUTERNAME" ) | |
} -SearchBase $SearchBase | | |
Foreach-Object { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Shuts down computers without notice | |
$DateOffset = 30 | |
$StartDate = (Get-Date).AddDays(-($DateOffset)) | |
$SearchBase = "OU=Domain Computers, DC=contoso, DC=com" | |
Get-ADComputer -Filter { | |
( LastLogonDate -gt $StartDate ) -and | |
( Name -ne "$env:COMPUTERNAME" ) | |
} -SearchBase $SearchBase -Properties LastLogonDate | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$DateOffset = 30 | |
$StartDate = (Get-Date).adddays(-($DateOffset)) | |
$SearchBase = "OU=Domain Computers, DC=contoso, DC=com" | |
Get-ADComputer -Filter { | |
( LastLogonDate -gt $StartDate ) -and | |
( Name -ne "$env:COMPUTERNAME" ) | |
} -SearchBase $SearchBase -Properties LastLogonDate | | |
Sort-Object -Property LastLogonDate | | |
Format-Table -Property Name, LastLogonDate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ComputerName = Read-Host -Prompt 'Target' | |
$Cred = Get-Credential -Credential $null | |
Write-Host "Opening session with remote host" | |
$Session = New-PSSession -ComputerName $ComputerName -Credential $Cred -ErrorAction Stop | |
$Confirm = Read-Host "Are you sure that you want to delete all print jobs on $ComputerName (Y/N)" | |
if ( $Confirm -eq 'Y' ) { | |
Write-Host "1. Stopping spooler" -ForegroundColor Green |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ExcludeDays = 90 # Exclude if password changed in the last $ days | |
$CutoffDate = (Get-Date).adddays(-($ExcludeDays)) | |
$Users = Get-ADUser -filter { | |
Enabled -eq $True -and | |
PasswordNeverExpires -eq $False -and | |
PasswordLastSet -lt $CutoffDate | |
} -Properties msDS-UserPasswordExpiryTimeComputed, PasswordLastSet, CannotChangePassword | |
$Users | Sort-Object -Property msDS-UserPasswordExpiryTimeComputed | Select-Object Name, PasswordLastSet, | |
@{ Name="ExpiryDate";Expression={ [datetime]::FromFileTime( $_."msDS-UserPasswordExpiryTimeComputed" ) } } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Generates a report of system configuration | |
.DESCRIPTION | |
Queries system properties using WMI and exports findings to an HTML file | |
.PARAMETER ComputerName | |
Specifies target. Defaults to local hostname | |
.PARAMETER FilePath | |
Specifies output path. Defaults to current location | |
.PARAMETER Open |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# duplicates indicate multiple processors | |
$Search = "OU=Domain servers,dc=contoso,dc=com" | |
Get-ADComputer -filter * -SearchBase $Search | Foreach-Object { | |
$property = "systemname","maxclockspeed","addressWidth","numberOfCores","NumberOfLogicalProcessors" | |
Get-WmiObject -computername $_.name -class win32_processor -Property $property -erroraction silentlycontinue | Select-Object -Property $property | |
} |