Skip to content

Instantly share code, notes, and snippets.

View AshFlaw's full-sized avatar

AshFlaw

  • The Full Circle
View GitHub Profile
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 / 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
@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 / Get-StaleADComputers.ps1
Created May 2, 2018 17:07
Get computer accounts that haven't logged on in a year.
$duration = (Get-Date).AddDays(-365)
Get-ADComputer -Filter {LastLogonDate -lt $duration} | Select-Object Name, LastLogonDate | Sort-Object Name
@AshFlaw
AshFlaw / Set-SQLShinkAllLogFiles.sql
Created May 14, 2018 07:43
Shrink all SQL Transaction Log Files on an Instance
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 / Set-SQLInstanceAllDBLogFileSettings.ps1
Created May 14, 2018 08:10
Function to set the log file initial size and growth values for all databases on an instance to 512MB
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 / RenewLetsEncryptSynology.sh
Last active December 29, 2018 04:29
Manually renew a Let's Encrypt certificate on a Synology NAS
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 / Invoke-RemoteVolumeExpand.ps1
Created May 14, 2018 13:38
Remotely expand all volumes on a server that have available space.
Function Invoke-RemoteVolumeExpand
{
Param
(
$Server
)
Function Invoke-VolumeExpand
{
$Include = "C|W|D|E|F"
$Partitions = Get-Partition | Where-Object {$_.DriveLetter -Match $Include}
@AshFlaw
AshFlaw / ChangeYourADPassword.ps1
Created June 1, 2018 07:38
Change your AD password with PowerShell
$AccountName = ""
Set-AdAccountPassword -Identity $AccountName -OldPassword (Read-Host -asSecureString "Current password") -NewPassword (Read-Host -asSecureString "New password")
@AshFlaw
AshFlaw / LogOffRemoteServer.ps1
Created June 18, 2018 18:42
Windows Server Core, closed terminal windows. Remote log off of session so next time, console will launch.
logoff /server:remote_computer_name