Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh King Windos

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am windos on github.
  • I am windosnz (https://keybase.io/windosnz) on keybase.
  • I have a public key ASAfWmAOfO_MviM60G-tNVJBpgl43PTNPJlsiFzi2IyYtQo

To claim this, I am signing this object:

@Windos
Windos / ToastEvents-PowerShell5.1.ps1
Created Mar 17, 2021
Rough mock-up of actionable toasts in PowerShell 5.1
View ToastEvents-PowerShell5.1.ps1
Add-Type -Path 'C:\temp\microsoft.toolkit.uwp.notifications.7.0.0\lib\net461\Microsoft.Toolkit.Uwp.Notifications.dll'
$CompatMgr = [Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]
Register-ObjectEvent -InputObject $CompatMgr -EventName OnActivated -Action {
if ($Event.SourceArgs.Argument -eq 'SubmitButton') {
switch ($Event.SourceArgs.UserInput.Value) {
Item1 {
$Text1 = 'GIF: Picard Facepalm'
$ImagePath = 'C:\Demos\Gifs\facepalm.gif'
}
@Windos
Windos / TopWords.ps1
Created Feb 2, 2021
RTPSUG Meetup Practice Challenge
View TopWords.ps1
# See challenge prompt here: https://jdhitsolutions.com/blog/powershell/8107/scripting-challenge-meetup/
$HelpAbout = help about_Splatting
$Words = $HelpAbout -replace '_', ' ' -split '\b' | Where-Object {$_ -match '\w+' -and $_ -ne 'the'}
$GroupedWords = $Words | Group-Object | Sort-Object -Property Count -Descending
[PSCustomObject] @{
Name = $HelpAbout.Name
WordCount = $Words.Count
View Get-TwitchAvatar.ps1
# May need to update the "Chrome Driver", run this from the module path (it's not an imported command)
# .\Selenium-Binary-Updater.ps1
# Start the driver (this is headless so you shouldn't see anything. Do this once.
$StartUri = 'https://www.twitch.tv/'
$Driver = Start-SeChrome -Arguments "incognito" -HideVersionHint -StartURL $StartUri -Quiet -Headless
# Repeat this part for each profile
# Specify the user you're looking for
$UserName = 'WindosNZ'
View Toast-with-side-of-Gif.ps1
# Install-Module BurntToast
$Text1 = New-BTText -Content 'Help!'
$Text2 = New-BTText -Content "Please send help."
$Audio1 = New-BTAudio -Source 'ms-winsoundevent:Notification.Mail'
# Point the source at a gif that exists...
$HeroImage = New-BTImage -Source 'C:\Temp\Help.gif' -HeroImage
$Binding1 = New-BTBinding -Children $Text1, $Text2 -AppLogoOverride $Image1 -HeroImage $HeroImage
@Windos
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 = 'https://tenant.sharepoint.com/sites/Common'
Connect-PnPOnline -Url $Uri -UseWebLogin
$DeletedAt = (Get-Date -Day 24 -Month 05 -Hour 0 -Minute 0 -Second 0)
$DeletedBy = 'first.last@tenant.com'
@Windos
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 = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Default Notification</text>
<image src="C:\Program Files\PowerShell\7\assets\Powershell_av_colors.ico" placement="appLogoOverride" />
</binding>
</visual>
<audio src="ms-winsoundevent:Notification.Default" />
</toast>
@Windos
Windos / RTPSUG-Null.ps1
Last active Mar 5, 2020
Null operators demo for RTPSUG 2020-03-04
View RTPSUG-Null.ps1
break
#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
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
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