Skip to content

Instantly share code, notes, and snippets.

View nichollsc81's full-sized avatar
🦛

Christian Nicholls nichollsc81

🦛
View GitHub Profile
function Invoke-CancelAdoBuildsAndJobs
{
param(
[Parameter()]
[ValidateNotNullOrEmpty()]
$AzureDevOpsPAT,
$OrganizationName,
$ProjectName
)
@nichollsc81
nichollsc81 / UserLoginFailures.kcl
Created October 11, 2022 08:59
Details bad logins for given user
let timeframe = 1hr;
let userName = '<username without domain>';
SecurityEvent
| where TimeGenerated >= ago(timeframe)
| where TargetUserName == (userName)
| where EventID == 4625 // bad login
| extend Reason = case(
SubStatus == '0xc000005e', 'No logon servers available to service the logon request',
SubStatus == '0xc0000062', 'Account name is not properly formatted',
SubStatus == '0xc0000064', 'Account name does not exist',
@nichollsc81
nichollsc81 / restartTeamCityAgents.sh
Last active April 13, 2022 14:55
Restarts TC agents
#!/bin/bash
restartWindowsAgents () {
local TEAMCITY_USER_NAME=$1
local TEAMCITY_USER_SECRET=$2
local TEAMCITY_TARGET_AGENTS="$3"
# teamcity root
TEAMCITY_URI='https://my.teamcity.local'
if [ -z "${TEAMCITY_TARGET_AGENTS}" ]; then
Function Get-RandomPort
{
return Get-Random -Max 32767 -Min 30000;
}
Function Test-PortInUse
{
Param(
[Parameter(Mandatory = $true)]
[Int] $portToTest
@nichollsc81
nichollsc81 / Test-Port.ps1
Created December 9, 2021 10:11
Test if port is open or not
function Test-Port
{
param
(
$Address,
$Port
)
$tcpClient = New-Object Net.Sockets.TcpClient
try
{
@nichollsc81
nichollsc81 / Get-CloudElementsIps.ps1
Created October 21, 2021 09:58
Returns public IPs for given Cloud Elements environment (staging/production)
# collect CE IP ranges
$AllCEIps = (Invoke-RestMethod https://my.cloudelements.io/ip-ranges.json).prefixes
# counter
[int] $Count = 0
# CE Environment: staging / production
[string] $Environment = 'staging'
foreach ($a In $AllCEIps)
{
# extract environment and ip
@nichollsc81
nichollsc81 / Get-WebAppSystemIdentity.ps1
Last active October 1, 2021 11:07
Returns AAD Object_ID for given Az Web App
#Requires -module az.websites
param(
$AppName = 'cirrus-a'
)
$App = [ordered]@{
AppName = $AppName
AAD_ID = $((Get-AzWebApp | Where-Object Name -EQ $AppName).Identity.PrincipalId)
HostName = $((Get-AzWebApp | Where-Object Name -EQ $AppName).DefaultHostName)
}
@nichollsc81
nichollsc81 / Update-AllUserModules.ps1
Created July 6, 2021 09:42
Updates all global user modules from admin scope
function Update-AllUserModules
{
[cmdletbinding(SupportsShouldProcess = $True)]
param()
if ($PSCmdlet.ShouldProcess($env:COMPUTERNAME, 'Update all user modules'))
{
(Get-InstalledModule).Name | ForEach-Object {
Write-Verbose "Updating module: $_"
try
@nichollsc81
nichollsc81 / Test-CertificateChain.ps1
Last active June 23, 2021 10:29
Test certificate chain of target uri
function Test-PactEndpoint
{
[cmdletbinding()]
param (
[Parameter(Position=0)]
[string] $Uri,
[Parameter(Position=1)]
[int] $Retrycount = '3'
)
#!/bin/bash
## declare array
declare -a REQUIRED_PKGS=("dnsutils" "nano")
# iterate over array
for i in "${REQUIRED_PKGS[@]}";
do
# if installed then remove
if [ "$(dpkg -l | grep $i)" ]; then
sudo apt-get purge --auto-remove ${i} -y #--simulate