Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View dpo007's full-sized avatar

Dev dpo007

  • Ontario, Canada
View GitHub Profile
@dpo007
dpo007 / Test-ForPort.ps1
Last active January 27, 2022 21:32
PowerShell :: Test-ForPort function - Tests network port for X retires, or until it answers.
function Test-ForPort {
param (
[Parameter(Mandatory)]
[string]$Server,
[Parameter(Mandatory)]
[int]$Port,
[int]$RetryCount = 3,
[switch]$Quiet
)
@dpo007
dpo007 / Get-ADUserNestedMemberships.PS1
Last active October 12, 2021 15:49
PowerShell :: Get-ADUserNestedMemberships
function Get-ADUserNestedMemberships {
param (
[string]$SAMAccountName = $env:USERNAME
)
$userNestedMembership = @()
$domainConnection = New-Object DirectoryServices.DirectoryEntry
$domainConnection.AuthenticationType = [System.DirectoryServices.AuthenticationTypes]::Secure
@dpo007
dpo007 / UninstallUserLevelChrome.ps1
Created May 18, 2021 15:52
PowerShell :: Uninstall User-level Chrome install (ie: log on script)
$chromeFolder = Join-Path $env:LOCALAPPDATA '\Google\Chrome'
$setupPath = Join-Path $chromeFolder '\Application\*.*\Installer\setup.exe'
# Use setup.exe from most recent version folder found.
if ((gci $setupPath).Count -gt 1) {
$setupPath = gci $setupPath | sort -Descending
$setupPath = $setupPath[0]
}
$argList = '--uninstall --multi-install --chrome --force-uninstall'
@dpo007
dpo007 / ListAllTeamsAppsInUse.ps1
Created January 21, 2021 22:36
PowerShell :: Create CSV of all Apps being used in all Teams.
Connect-MicrosoftTeams
$teams = Get-Team
foreach ($team in $teams) {
$teamApps = Get-TeamsAppInstallation -TeamId $team.GroupId
foreach ($app in $teamApps) {
Write-Output ('{0},{1},{2}' -f $team.DisplayName, $app.DisplayName, $app.TeamsAppId) >> c:\temp\TeamApps.csv
}
}
@dpo007
dpo007 / FindManagerReports.ps1
Last active January 20, 2021 16:11
PowerShell :: Create simple CSV of AD users with reports (aka Managers)
$users = Get-ADUser -Server $DomainController -Filter * -Properties Name, DirectReports
foreach ($user in $users) {
$name = $user.Name
foreach ($report in $user.DirectReports) {
write-output (("$name, $report").Replace("CN=","") -replace ",OU=.*", "") >> c:\temp\ReportsByUser.csv
}
}
@dpo007
dpo007 / UploadToS3Bucket.ps1
Created October 23, 2020 17:18
PowerShell :: Upload folder of files to S3 bucket
Install-Module -Name AWS.Tools.Installer
Install-AWSToolsModule AWS.Tools.S3 -CleanUp
$bucket = 'some-s3-bucket'
Set-AWSCredential `
-AccessKey '<Get Your Own>' `
-SecretKey '<Get Your Own>'
# Gather files to upload
@dpo007
dpo007 / GetPickListChoice.ps1
Created September 14, 2020 21:46
PowerShell :: Console input with search list by typed letters, tab cycling, etc.
function GetPickListChoice {
param (
[Parameter(Mandatory=$true)]
[string[]]$PickList,
[string]$Prompt = 'Type to search, Tab to cycle matches, Backspace to reset, ''?'' for a list: ',
[switch]$PromptNoNewLine
)
function ClearCurrentChoice {
for ($i = $origCursorPos.X; $i -lt $endPos; $i++) {
@dpo007
dpo007 / RunAtTime.ps1
Last active August 29, 2022 05:20
PowerShell :: Simple loop to run commands at a certain time in the future.
$endTime = Get-Date "4:45PM"
Do {
$timeNow = Get-Date
if ($timeNow -ge $endTime) {
Write-Host "Ding! It's $endTime, time to work..."
# Do Stuff
Break
} else {
cls
Write-Host "Waiting until $endTime (Currently: $timeNow)"
@dpo007
dpo007 / TriggerWindowsUpdate.ps1
Last active February 11, 2022 21:35
PowerShell :: Script to trigger a Windows update from WSUS (based on existing approvals) or optionally, everything from MS Update.
<#
- May 22, 2018 - V1.0 - DPO
+ Initial release.
- May 23, 2018 - V1.1 - DPO
+ Added check for packages/modules before force-installing them.
+ Added some output text.
+ Added 'ListOnly' switch, which will cause it to only display approved updates (not download or install them).
- May 23, 2018 - V1.2 - DPO
+ Added 'MicrosoftUpdate' switch to force the check to go to Microsoft Update (circumventing WSUS/WSUS approvals).
- v1.4 - DPO - July, 2021
@dpo007
dpo007 / Test-PasswordForDomain.ps1
Last active August 18, 2020 16:16
PowerShell :: Function to check password against Windows Domain rules.
function Test-PasswordForDomain {
param (
[Parameter(Mandatory=$true)]
[string]$Password,
[Parameter(Mandatory=$false)]
[string]$AccountSamAccountName = "",
[Parameter(Mandatory=$false)]
[string]$AccountDisplayName,
[Microsoft.ActiveDirectory.Management.ADEntity]$PasswordPolicy = (Get-ADDefaultDomainPasswordPolicy -ErrorAction SilentlyContinue)
)