Skip to content

Instantly share code, notes, and snippets.

AshFlaw

  • The Full Circle
Block or report user

Report or block AshFlaw

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@AshFlaw
AshFlaw / Invoke-RemoteVolumeExpand.ps1
Created May 14, 2018
Remotely expand all volumes on a server that have available space.
View Invoke-RemoteVolumeExpand.ps1
Function Invoke-RemoteVolumeExpand
{
Param
(
$Server
)
Function Invoke-VolumeExpand
{
$Include = "C|W|D|E|F"
$Partitions = Get-Partition | Where-Object {$_.DriveLetter -Match $Include}
@AshFlaw
AshFlaw / RenewLetsEncryptSynology.sh
Last active Dec 29, 2018
Manually renew a Let's Encrypt certificate on a Synology NAS
View RenewLetsEncryptSynology.sh
ssh user@synology.local
sudo -i
# Method 1
/usr/syno/sbin/syno-letsencrypt renew-all
# Method 2 - Verbose
/usr/syno/sbin/syno-letsencrypt renew-all -vv
@AshFlaw
AshFlaw / Set-SQLInstanceAllDBLogFileSettings.ps1
Created May 14, 2018
Function to set the log file initial size and growth values for all databases on an instance to 512MB
View Set-SQLInstanceAllDBLogFileSettings.ps1
Function Set-SQLLogFileSizeAndGrowth
{
Param
(
$Instance
)
Import-Module dbatools -ErrorAction SilentlyContinue
If ((Get-Module | Where-Object {$_.Name -eq "dbatools"}) -eq $null)
{
Write-Output "Installing required module: $dbatools"
@AshFlaw
AshFlaw / Set-SQLShinkAllLogFiles.sql
Created May 14, 2018
Shrink all SQL Transaction Log Files on an Instance
View Set-SQLShinkAllLogFiles.sql
SET NOCOUNT ON
USE master
GO
/*
* Update usage statistics. Not a necessary step
* but will provide more accurate results
*/
DBCC UPDATEUSAGE(0)
IF OBJECT_ID('tempdb..#tmp') IS NOT NULL
@AshFlaw
AshFlaw / Get-StaleADComputers.ps1
Created May 2, 2018
Get computer accounts that haven't logged on in a year.
View Get-StaleADComputers.ps1
$duration = (Get-Date).AddDays(-365)
Get-ADComputer -Filter {LastLogonDate -lt $duration} | Select-Object Name, LastLogonDate | Sort-Object Name
@AshFlaw
AshFlaw / Install-Choco.ps1
Created Apr 15, 2018
PowerShell function to install Chocolatey if it isn't already.
View Install-Choco.ps1
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 Apr 15, 2018
Install Chocolatey with PowerShell and enable global automatic install confirmations.
View ChocoInstall.ps1
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
View Test-SQLTableExists.ps1
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 Apr 4, 2018
Get the AD groups a user is a member of.
View Get-ADUserGroupMebership.ps1
Get-ADPrincipalGroupMembership username | select name
@AshFlaw
AshFlaw / Set-SSISServiceAccountDCOMPermissions.ps1
Created Feb 1, 2018
# Set SQL 2016 SSIS Service Account DCOM Permissions on Windows Server 2012 R2 Core
View Set-SSISServiceAccountDCOMPermissions.ps1
$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
You can’t perform that action at this time.