Skip to content

Instantly share code, notes, and snippets.

Joshua King Windos

View GitHub Profile
Windos / Restore-SPO-Files.ps1
Created May 26, 2020
Deleted a *very* large directory in SharePoint Online? Restore the files en masse with the SPO PnP Module
View Restore-SPO-Files.ps1
# Needs the SharePoint Online PnP module, install if haven't got it already:
# Install-Module SharePointPnPPowerShellOnline
$Uri = ''
Connect-PnPOnline -Url $Uri -UseWebLogin
$DeletedAt = (Get-Date -Day 24 -Month 05 -Hour 0 -Minute 0 -Second 0)
$DeletedBy = ''
Windos / Toast-RTEvent-Example.ps1
Created Mar 31, 2020
Example of trying to register a Windows RT event via PowerShell, specifically here we're looking at events on Toast Notifications
View Toast-RTEvent-Example.ps1
$XmlString = @"
<binding template="ToastGeneric">
<text>Default Notification</text>
<image src="C:\Program Files\PowerShell\7\assets\Powershell_av_colors.ico" placement="appLogoOverride" />
<audio src="ms-winsoundevent:Notification.Default" />
Windos / RTPSUG-Null.ps1
Last active Mar 5, 2020
Null operators demo for RTPSUG 2020-03-04
View RTPSUG-Null.ps1
#region Null Coalescing Operator (??)
# Returns value on the left if it's not null
# Otherwise the right had side is evaluated and returned
$Left ?? $Right
Windos / MembershipMatrix.ps1
Created Dec 11, 2019
Group Membership Matrix Example
View MembershipMatrix.ps1
$Users = Get-ADUser -Filter 'Enabled -eq $true'
$GroupNames = (Get-ADGroup -Filter * |
Where-Object {$_.DistinguishedName -notlike '*CN=Builtin,*'}).Name
$Report = foreach ($User in $Users) {
$Groups = Get-ADPrincipalGroupMembership -Identity $User.DistinguishedName
$ReportProp = [Ordered] @{
'Name' = $User.DisplayName
'Username' = $User.SamAccountName
Windos / SplitPaths to Excel.ps1
Created Oct 9, 2019
It's not pretty, or fast, but it'll work!
View SplitPaths to Excel.ps1
$Files = Get-ChildItem -Path C:\Temp -Recurse -File
$SplitFiles = @()
foreach ($File in $Files) {
$SplitFiles += ,$File.FullName.Split('\')
$NumColumns = ($SplitFiles | Measure-Object -Maximum -Property Count).Maximum
View File-Per-Directory.ps1
$Files = Get-ChildItem -Path 'C:\Temp' -Filter "*.tsv" -Recurse
$Directories = $Files | Group-Object -Property 'DirectoryName'
foreach ($Directory in $Directories) {
$Outfile = Join-Path -Path $Directory.Name -ChildPath '\HTML-File-Name.html'
# Start your HTML file here, add CSS or headings.
foreach ($File in $Directory.Group) {
Import-Csv -Delimiter "`t" -Path $File.FillName | ConvertTo-Html | Out-File -FilePath $Outfile -Append
View ToastButton.ps1
$Time = Get-Date -Format t
$Text1 = New-BTText -Content 'Report Generated'
$Text2 = New-BTText -Content "Completed at $Time"
$Audio1 = New-BTAudio -Source 'ms-winsoundevent:Notification.IM'
$Binding1 = New-BTBinding -Children $Text1, $Text2
$Visual1 = New-BTVisual -BindingGeneric $Binding1
$Button1 = New-BTButton -Content 'Open Report' -Arguments 'C:\Fake\Report\Location.csv'
View AzureAD-DisablePlans-ExistingUsers.ps1
Import-Module AzureAD
# Need to know the License Sku and Service Plan
# It is possible to get this from the module itself
Get-AzureADSubscribedSku | select SkuId, SkuPartNumber, ServicePlans
# May be easier to get online:
View BlogTweet-Azure.ps1
$Uri = ''
$Posts = [System.Collections.ArrayList]::new()
$PageNumber = 1
$More = $true
while ($More) {
try {
$Page = Invoke-RestMethod -Uri "$Uri$PageNumber" -ErrorAction Stop
} catch {
$Page = $null
View toast-click.xml
# For cliackable toast, the toast element needs an activationtype set to protocol and a "launch" argument set to the thing to launch
# (be that a website or file, etc.)
# Example with BurntToast:
<?xml version="1.0" encoding="utf-8"?>
<toast activationType="protocol" launch="">
<binding template="ToastGeneric">
You can’t perform that action at this time.