Skip to content

Instantly share code, notes, and snippets.

View Windos's full-sized avatar

Josh King Windos

View GitHub Profile
@Windos
Windos / RTPSUG-Null.ps1
Last active March 5, 2020 02:28
Null operators demo for RTPSUG 2020-03-04
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 December 11, 2019 09:33
Group Membership Matrix Example
$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 October 9, 2019 22:56
It's not pretty, or fast, but it'll work!
$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
$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
$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'
Import-Module AzureAD
Connect-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: https://docs.microsoft.com/en-us/azure/active-directory/users-groups-roles/licensing-service-plan-reference
$Uri = 'https://king.geek.nz/rss/'
$Posts = [System.Collections.ArrayList]::new()
$PageNumber = 1
$More = $true
while ($More) {
try {
$Page = Invoke-RestMethod -Uri "$Uri$PageNumber" -ErrorAction Stop
} catch {
$Page = $null
# 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: https://king.geek.nz/2017/05/08/crouton-clickable/
<?xml version="1.0" encoding="utf-8"?>
<toast activationType="protocol" launch="https://google.com">
<visual>
<binding template="ToastGeneric">
<text>Google!</text>
Import-Module BurntToast
$Text1 = New-BTText -Content 'This is a test'
$Text2 = New-BTText -Content 'This more testing'
$AppLogo = New-BTImage -Source 'https://raw.githubusercontent.com/Windos/BurntToast/master/Media/BurntToast.png' -Crop Circle -AppLogoOverride
$Binding1 = New-BTBinding -Children $Text1, $Text2 -AppLogoOverride $AppLogo
$Visual1 = New-BTVisual -BindingGeneric $Binding1
$Content = New-BTContent -Visual $Visual1
$AppId = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe"
@Windos
Windos / RemoteToast.xml
Created January 10, 2019 05:18
XML dump for inclusion in blog post
<?xml version="1.0" encoding="utf-8"?><toast><visual><binding template="ToastGeneric"><text>No Time For Questions</text><text>All servers are being shut down in __WARNTIME__, save your work!</text></binding></visual><audio src="ms-winsoundevent:Notification.Looping.Alarm" /></toast>