Skip to content

Instantly share code, notes, and snippets.

View sassdawe's full-sized avatar
💭
Playing PowerShell

David Sass sassdawe

💭
Playing PowerShell
View GitHub Profile
@sassdawe
sassdawe / Get-JSONContent.ps1
Created February 27, 2020 20:26
Get a content of a small .json file and return an array of PSCusomObject
function Get-JSONContent {
[OutputType([PSCustomObject[]])]
[CmdletBinding()]
param (
[String]
$Path
)
Get-Content -Path $Path -Raw | ConvertFrom-JSON | Foreach-Object { $_ }
}
@sassdawe
sassdawe / Get-JSONContentX.ps1
Last active October 23, 2023 14:56
Convert large well formatted JSON structures into [PSCustomObject[]]
function Get-JSONContentX {
<#
.Synopsis
Get-JSONContentX
.DESCRIPTION
Get-JSONContentX, to convert eXtra large well formatted .json files into [PSCustomObject]
.EXAMPLE
Get-JSONContentX -Path C:\Source\temp.json -PropertyCount 4
Will return the content to the console
@sassdawe
sassdawe / About OutWithOut.md
Created August 25, 2020 06:36 — forked from Jaykul/About OutWithOut.md
You can redirect the other output streams like *>&1 | Out-String.ps1 and these commands will capture them labelled (and optionally, in color), e.g. for | more or | less

PowerShell has a problem with it's extra output streams. The actual content of the Warning, Verbose, Debug, Information, and even Error streams doesn't have the label text like "WARNING: " or "VERBOSE: " that we're used to seeing in the host. That label is actually added by the host (hopefully, in a culture-aware way). However, this means that when you attempt to redirect all of this output, for example by redirecting all output streams to stdout, with *>&1, you don't get labels on them at all, which is confusing, and can make the output difficult to comprehend.

Take for example a function that writes in a loop:

if ($i % 5 -eq 0) {
    Write-Output $i
} else {
    Write-Verbose $i
}
@sassdawe
sassdawe / DeleteListItems.ps1
Created August 29, 2020 17:01 — forked from cakriwut/DeleteListItems.ps1
PowerShell to delete SharePoint list items in batch mode.
function DeleteListItems{
<#
.SYNOPSIS
Deletes SharePoint List Items in batch
.DESCRIPTION
Deleted SharePoint List items in batch and provide sleep between batch. By default, it will delete all List Items.
You can delete List Items based on the CAML Query input parameter.
.PARAMETER ListUrl
@sassdawe
sassdawe / Microsoft.VSCode_profile.ps1
Created November 14, 2020 21:18
VSCode Profile for Windows PowerShell
if ($PSVersionTable.PSVersion.Major -eq 5) {
$env:PSModulePath = ($env:PSModulePath.Split(';') | ? { -not ( $_ -ilike "*Files\Powershell*" ) }) -join ';'
Get-Module | ?{ $_.path -ilike '*Files\PowerShell*'} | Remove-Module
}
@sassdawe
sassdawe / Clear-ClipboardContent.ps1
Created December 13, 2020 12:45
Clear-ClipboardContent will remove all formating from the content of your clipboard
<#
.Synopsis
Clear-ClipboardContent
.DESCRIPTION
Clear-ClipboardContent will remove all formating from the content of your clipboard
#>
function Clear-ClipboardContent {
[CmdletBinding()]
[Alias("ccc")]
Param()
@sassdawe
sassdawe / Implement-a-Serverless-Azure-Logic-App-Contact-Form.md
Created January 18, 2021 06:32
Implement a Serverless Azure Logic App Contact Form

Step By Step: Implement a Serverless Azure Logic App Contact Form

Pre-requisites

  1. An Azure Account, there are free and paid options
  2. A SendGrid account, there are free trial, free and paid options
  3. Code from this post!
  4. Approximately X time to implement and test
  5. Optional: A custom domain for the contact form html and Azure function Application Program Interface (API)

**Securing your Azure and Sendgrid accounts with Two Factor Authentication (2FA) is recommended. 2FA will not have an effect on how the Azure function or Sendgrid API works.

@sassdawe
sassdawe / defenderwatch.ps1
Created June 7, 2021 05:32 — forked from svch0stz/defenderwatch.ps1
WMI Watcher for Windows Defender RealtimeMonitoring
$WMI = @{
Query = "SELECT * FROM __InstanceModificationEvent WITHIN 5 WHERE TargetInstance ISA 'MSFT_MpPreference' AND TargetInstance.DisableRealtimeMonitoring=True"
Action = {
#$Global:Data = $Event
Write-Host "Defender Configuration change - DisableRealtimeMonitoring:"$Event.SourceEventArgs.NewEvent.TargetInstance.DisableRealtimeMonitoring"(Old Value:"$Event.SourceEventArgs.NewEvent.PreviousInstance.DisableRealtimeMonitoring")"
}
Namespace = 'root\microsoft\windows\defender'
SourceIdentifier = "Defender.DisableRealtimeMonitoring"
}
$Null = Register-WMIEvent @WMI
@sassdawe
sassdawe / Debug-PowerShell.ps1
Created July 25, 2021 12:36
Debug in PowerShell with rolling log file
Function Debug-PowerShell() {
[CmdletBinding()]
[Alias("dbps")]
param (
[string]$Path = "$ENV:TEMP\psdebu.log"
)
$Global:DebugLog = $Path
New-Item $Global:DebugLog -Force -ItemType File
Start-Process powershell -ArgumentList "-noprofile","-command &{Get-Content '$DebugLog' -Wait}"
}
@sassdawe
sassdawe / Clear-Url.ps1
Created September 1, 2021 17:52
Clear URLs with PowerShell from parameters
function clear-url {
[cmdletbinding()]
[alias('cc')]
param(
[string]$url = @(Get-Clipboard)[0]
)
$url = $url.Trim()
Write-Verbose "original url: `'$url`'"
if ( ([uri]$url).Query ) {
Write-Verbose "removing: `'$(([uri]$url).Query)`'"