Skip to content

Instantly share code, notes, and snippets.

View dpo007's full-sized avatar

Dev dpo007

  • Ontario, Canada
View GitHub Profile
<#
.SYNOPSIS
This script retrieves scheduled tasks from the Task Scheduler and checks whether "Synchronize across time zones" is enabled for tasks in the root task path (\).
.DESCRIPTION
The script iterates through all scheduled tasks, but only those in the root task path (\) are processed.
It exports each task's XML definition, searches for the <StartBoundary> element, and checks if the value ends with a timezone offset (e.g., -04:00, +02:00).
If a task has "Synchronize across time zones" enabled (indicated by the timezone offset), the script includes the task in the results.
.PARAMETER None
@dpo007
dpo007 / Remove-GPOAcrossTrustedDomains.ps1
Created September 20, 2024 18:18
Removes a named GPO (and associated links) from multiple trusted domains
# Define the GPO name and the domains
$gpoName = "GPO To Go"
$domains = @("domain1.local", "domain2.local", "anotherDomain.com")
foreach ($domain in $domains) {
# Get the GPO
$gpo = Get-GPO -Name $gpoName -Domain $domain -ErrorAction SilentlyContinue
if ($gpo) {
# Get all OUs in the domain
function Write-Slow {
[Alias("WS", "WOPR", "WOPRType")]
param (
[string]$Message,
[int]$DelayMilliseconds = 50,
[ConsoleColor]$ForegroundColor = $Host.UI.RawUI.ForegroundColor,
[ConsoleColor]$BackgroundColor = $Host.UI.RawUI.BackgroundColor
)
# Delay multipliers for punctuation and sentence-ending marks
@dpo007
dpo007 / Get-CatFact.ps1
Last active July 2, 2024 19:04
PowerShell :: The Best Login Script Ever
# Get random cat fact from API
$catFact = Invoke-RestMethod -Uri "https://catfact.ninja/fact" -Method Get
# Print cat fact
Write-Host $catFact.fact
# Setup speech synthesizer
Add-Type -AssemblyName System.Speech
$speech = New-Object System.Speech.Synthesis.SpeechSynthesizer
@dpo007
dpo007 / Find-NonMatchingADUserFolders.ps1
Created June 29, 2023 18:59
PowerShell :: Find-NonMatchingADUserFolders
<#
.SYNOPSIS
Script to find subfolders without matching Active Directory (AD) users and optionally move them to a destination folder.
.DESCRIPTION
This PowerShell script imports the Active Directory module and defines a function named Find-NonMatchingADUserFolders. The function takes two parameters: folderPath (mandatory) and destinationFolder (optional). It retrieves all subfolders in the specified folder and all existing AD users. It then iterates through each subfolder, checks if the subfolder name matches an existing AD user, and performs the specified action (move or list) based on the presence or absence of a matching user.
.EXAMPLE
Find-NonMatchingADUserFolders -folderPath "C:\Path\To\Folder" -destinationFolder "D:\Temp\OldUserFolders"
Moves the subfolders without matching AD users to the specified destination folder.
@dpo007
dpo007 / Get-UsersWithMismatchedHomeDirectory.ps1
Last active June 29, 2023 19:02
PowerShell :: Get-UsersWithMismatchedHomeDirectory
<#
.SYNOPSIS
Retrieves users whose home directory paths do not contain their SamAccountName.
.DESCRIPTION
The Get-UsersWithMismatchedHomeDirectory function retrieves users from Active Directory whose home directory paths do not contain their SamAccountName. By default, it excludes users with empty home directories. Users can be optionally included by specifying the -IncludeEmptyHomeDirs switch parameter.
.PARAMETER IncludeEmptyHomeDirs
Switch parameter to include users with empty home directories in the results.
@dpo007
dpo007 / MoveFilesBetweenTeams.ps1
Last active June 29, 2023 19:05
PowerShell :: Move all folders between Teams
#Requires -Version 5.0
#Requires -Modules SharePointPnPPowerShellOnline
<#
.SYNOPSIS
Script to move folders and files from a source team's site to a destination team's site in SharePoint Online.
.DESCRIPTION
This PowerShell script requires PowerShell version 5.0 and the SharePointPnPPowerShellOnline module. It connects to SharePoint Online and retrieves the source team's site and the destination team's site based on the provided team names. It then retrieves all folders and files in the source team's site and moves each item to the destination team's site.
.PARAMETER SrcTeam
@dpo007
dpo007 / Detect-PortableComputer.ps1
Created August 29, 2022 14:46
PowerShell :: Detect if local computer is portable or not, based on WMI/ChassisType.
$isPortable = $false
$chassisType = (Get-CimInstance -Query "Select * from Win32_SystemEnclosure").ChassisTypes[0]
switch ($chassisType) {
# Case 8 "Portable"
# Case 9 "Laptop"
# Case 10 "Notebook"
# Case 11 "Handheld"
# Case 14 "Sub-Notebook"
{$_ -in 8, 9, 10, 11, 14} { $isPortable = $true }
@dpo007
dpo007 / HyperVReplicationSetup.ps1
Created August 29, 2022 05:17
PowerShell :: Configure Hyper-V replication between a set of host servers.
<#
Configures Hyper-V replication between a set of host servers.
v1.0 - DPO - Aug. 2022
#>
#Requires -RunAsAdministrator
#Requires -Version 5.1
param (
[string]$HostReplicaFolderPath = 'D:\ReplicaVMs',
[switch]$LeaveExistingAllowedServers
)
@dpo007
dpo007 / Make-Cert.ps1
Created June 1, 2022 17:57
PowerShell :: Create a Self-Signed Certificate On Local Machine and Export it to PFX and CRT.
$subject = 'automationname.domain.ca'
$certFileName = $subject -replace '\.','_'
$certPass = ConvertTo-SecureString 'AutomationCertificate!1' -AsPlainText -Force
# Create a self-signed certificate in the local machine personal certificate store and store the result in the $cert variable.
$cert = New-SelfSignedCertificate -Subject $subject
# Display the new certificate properties
$cert | Format-List -Property *
# Save the certificate (with private key) into a PFX file, and just the public key into a CRT file.