Skip to content

Instantly share code, notes, and snippets.

View dpo007's full-sized avatar

Dev dpo007

  • Ontario, Canada
View GitHub Profile
@dpo007
dpo007 / Get-CatFact.ps1
Last active November 2, 2023 03:30
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.
@dpo007
dpo007 / FoxitPhantomPDFScrubber.ps1
Last active April 29, 2022 17:33
PowerShell :: Scrubs Foxit's PhantomPDF editor off a machine. Created to help make way for upgrade to "Foxit PDF Editor".
<#
Foxit PhantomPDF Remover/Cleaner
V1.5 - DPO - Apr. 2022
#>
param (
[switch]$LeaveUUID
)
Write-Host 'Looking for Foxit PhantomPDF installs...'
$foxitPhantom = Get-Package 'Foxit Phan*' -AllVersions -ErrorAction SilentlyContinue
@dpo007
dpo007 / Create-RebootAtMidnightTask.ps1
Last active March 10, 2022 21:07
PowerShell :: Creates a self-deleting task that reboots Windows at midnight.
<#
Create self-deleting task that reboots the computer at midnight.
#>
$midnight = (Get-date -Hour 0 -Minute 0 -Second 0).AddDays(1)
$taskname = 'Reboot at midnight'
$taskdescription = 'Reboots computer at midnight.'
if (Get-ScheduledTask -TaskName $taskname -ErrorAction SilentlyContinue) {
Unregister-ScheduledTask -TaskName $taskname -Confirm:$false
@dpo007
dpo007 / Import-BarracudaCSVToMS365.ps1
Last active February 3, 2022 20:02
PowerShell :: Import Barracuda Sender Policy CSV into MS365 Anti-Spam Allow//Block Lists
param (
[string]$CsvPath = (Join-Path $PSScriptRoot 'AllowList.csv'),
[string]$MS365User = 'coolguy@coolcompany.com',
[string]$BarracudaQuarantineEmail = 'quarantine@ess.ca.barracudanetworks.com',
[switch]$IncludeBlockLists
)
$getSessions = Get-PSSession | Select-Object -Property State, Name
$isConnected = [bool](@($getSessions) -like '@{State=Opened; Name=ExchangeOnlineInternalSession*').Count -gt 0
If (!$isConnected) {