Skip to content

Instantly share code, notes, and snippets.

View AshFlaw's full-sized avatar

AshFlaw

  • The Full Circle
View GitHub Profile
@AshFlaw
AshFlaw / Install-Choco.ps1
Created April 15, 2018 11:08
PowerShell function to install Chocolatey if it isn't already.
Function Install-Choco
{
Set-ExecutionPolicy Bypass -force
If (!(Test-Path -Path "C:\ProgramData\chocolatey"))
{
$env:chocolateyUseWindowsCompression = 'false'
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
choco feature enable -n=allowGlobalConfirmation
}
}
@AshFlaw
AshFlaw / ChocoInstall.ps1
Last active March 20, 2024 19:59
Install Chocolatey with PowerShell and enable global automatic install confirmations.
Set-ExecutionPolicy Unrestricted
# Install Chocolatey
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
# Enable Global confirmation (auto accept any prompts)
choco feature enable -n=allowGlobalConfirmation
function Test-SQLTableExists
{
param ($Instance,$Database,$TableName)
$Return = $SQL = $dataTable = $null
$sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'$TableName'"
$dataTable = Invoke-Sqlcmd2 -ServerInstance $Instance -Database $Database -Query $sql
if ($dataTable) {$return = $true}
else {$return = $false}
$Return
}
@AshFlaw
AshFlaw / Get-ADUserGroupMebership.ps1
Created April 4, 2018 16:32
Get the AD groups a user is a member of.
Get-ADPrincipalGroupMembership username | select name
@AshFlaw
AshFlaw / Set-SSISServiceAccountDCOMPermissions.ps1
Created February 1, 2018 13:27
# Set SQL 2016 SSIS Service Account DCOM Permissions on Windows Server 2012 R2 Core
$ServiceName = "MsDtsServer130" #SQL 2016 SSIS Service Name
$SSIS_Service = Get-WmiObject win32_service | where-object {$_.Name -eq $ServiceName}
If ($SSIS_Service -ne $null)
{
$SSIS_AppDesc = "Microsoft " + (Get-Service $ServiceName).DisplayName # Add the prefix which is not present in the service description
$SSISAccount = $SSIS_Service.StartName.Split("\")
$user = $SSISAccount[1]
$domain = $SSISAccount[0]
$appdesc = $SSIS_AppDesc
$app = get-wmiobject -query ('SELECT * FROM Win32_DCOMApplicationSetting WHERE Description = "' + $appdesc + '"') -enableallprivileges
@AshFlaw
AshFlaw / Install-EXE.ps1
Created January 18, 2018 19:16
Install executable with command line switches
Function Install-EXE
{
Param
(
$Command
)
$processID = (Invoke-WmiMethod -class Win32_process -name Create -ArgumentList $Command -ErrorAction Stop).processid
Wait-Process -Id $processID
}
@AshFlaw
AshFlaw / styles_custom_v2.css
Last active February 10, 2020 10:34
PRTG login and application page customization to remove news feed, footer, logo, lower message text, lost password and download client links.
/*
// You can use this file to modify the appearance of the PRTG web interface
// as described in https://kb.paessler.com/en/topic/33
//
// Please note that you are using an unsupported and deprecated feature.
// Your changes will be broken or removed with future PRTG updates.
//
// If you modify this file, PLEASE LET US KNOW what you're changing and why!
// Just drop an email to support@paessler.com and help us understand your
// needs. Thank you!
@AshFlaw
AshFlaw / Disable-ScheduledDefrag.ps1
Created October 23, 2017 08:12
Disable Windows scheduled defrag on all computers in a domain
$ErrorActionPreference = "Continue"
$computers = Get-ADComputer -Filter 'ObjectClass -eq "Computer"' | Select-Object -Expand DNSHostName
Function DisableDefrag
{
If ((Get-ScheduledTask -TaskName 'ScheduledDefrag').State -eq 'Ready')
{
    Disable-ScheduledTask -TaskName 'ScheduledDefrag' -TaskPath '\Microsoft\Windows\Defrag'
Write-Output "$env:computername Scheduled defrag disabled"
}
@AshFlaw
AshFlaw / Create-SQLUserAndIPLoggingTrigger.sql
Created October 16, 2017 12:43
Create the trigger to log connection details to the User IP Audit table.
USE UserIPAudit
GO
CREATE TRIGGER LogonTrigger ON ALL SERVER FOR LOGON
AS
BEGIN
DECLARE @data XML
SET @data = EVENTDATA()
INSERT INTO UserIPAudit.dbo.[UserIPLog]
(
@AshFlaw
AshFlaw / Create-SQLUserAndIPLoggingTable.sql
Created October 16, 2017 12:42
Create SQL table for logging user connections with permissions and compression on the logging table.
CREATE DATABASE UserIPAudit
GO
USE UserIPAudit
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON