Skip to content

Instantly share code, notes, and snippets.

View nichollsc81's full-sized avatar
🦛

Christian Nicholls nichollsc81

🦛
View GitHub Profile
@nichollsc81
nichollsc81 / Remove-ModulePreviousVersion.ps1
Last active June 11, 2021 08:48
Removes all previous versions of an installed module
function Remove-ModulePreviousVersion {
<#
.SYNOPSIS
Removes all previous versions of given module.
.DESCRIPTION
Long description
.EXAMPLE
PS C:\> $m = 'oh-my-posh'
PS C:\> Remove-ModulePreviousVersion -ModuleName $m -Verbose -WhatIf
Removes all previous versions of given module oh-mu-posh
@nichollsc81
nichollsc81 / Remove-RecordFromHosts.ps1
Last active May 20, 2021 13:24
Removes record from host file
# credit Tom Chantler: https://github.com/TomChantler/EditHosts
function Remove-RecordFromHosts
{
[cmdletbinding()]
param(
[Parameter(Mandatory = $true, Position = 0)]
[string] $Hostname
)
begin
@nichollsc81
nichollsc81 / Add-RecordToHosts.ps1
Last active May 20, 2021 13:24
Adds record to hosts file
# credit Tom Chantler: https://github.com/TomChantler/EditHosts
function Add-RecordToHosts
{
[cmdletbinding()]
param (
[Parameter(Mandatory = $true, Position = 0)]
[ValidatePattern('^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$')]
[string[]] $DesiredIP,
[Parameter(Mandatory = $true, Position = 1)]
# This code parse the audit logs exported from azure devops and saved as file auditlog.json
function Parse-AzureDevOpsAuditLogs {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string] $Path
)
# A random session is chosen
$AllServices = Get-Service
$Body = foreach($Service in $AllServices) {
[PSCustomObject]@{
ServiceName = $Service.ServiceName
ServiceStatus = $Service.Status
Startup = $Service.StartupType
Requires = $Services.RequiredServices
}
[string]$(deploymentPath)
[string]$(FORWARD_PORT)
$ErrorActionPreference = 'Stop'
echo "starting function"
# set runtime location
[string] $ArgumentList = "powershell.exe -command ""set-location $(deploymentPath);func start --port $(FORWARD_PORT) --verbose"""
Write-Host "Executing:: $ArgumentList"
function Test-SQLDatabase
{
param(
[Parameter(Position = 0, Mandatory = $True, ValueFromPipeline = $True)] [string] $Server,
[Parameter(Position = 1, Mandatory = $True)] [string] $Database,
[Parameter(Position = 2, Mandatory = $True, ParameterSetName = 'SQLAuth')] [string] $Username,
[Parameter(Position = 3, Mandatory = $True, ParameterSetName = 'SQLAuth')] [string] $Password,
[Parameter(Position = 2, Mandatory = $True, ParameterSetName = 'WindowsAuth')] [switch] $UseWindowsAuthentication
)
import json
import sys
#from pprint import pprint as pretty
# read json
def read_json(appSettingsFile):
with open(appSettingsFile) as data_file:
data = json.load(data_file)
# pretty(data)
return data
### load functions region
function Format-Json
{
<#
.SYNOPSIS
Prettifies JSON output.
.DESCRIPTION
Reformats a JSON string so the output looks better than what ConvertTo-Json outputs.
.PARAMETER Json
Required: [string] The JSON text to prettify.
@nichollsc81
nichollsc81 / Set-ScreeningBatchConnString.ps1
Last active January 18, 2021 11:32
PoSh Json File Transform
<#
.SYNOPSIS
Substitutes connection string via json connstring key.
.DESCRIPTION
Substitutes connection string via json connstring key.
.EXAMPLE
PS>$files = ('C:\TEMP\git\moneycorp\Screening.Batch\Screening.Batch.Db\appsettings.json','C:\TEMP\git\moneycorp\Screening.Batch\Screening.Batch.Api\appsettings.json').Split(',')
PS>foreach($file in $files){
PS> $Transform = @{
PS> Filepath = $file