This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$folder = 'C:\Temp\', $env:TEMP, '~/Downloads' | |
$threshold = (Get-Date).AddMonths(-1.0) | |
$ConfirmPreference = 'Low' | |
$oldFiles = $folder | Get-ChildItem -File -Recurse | ?{ $_.LastAccessTime -lt $threshold } | |
$oldFiles | Sort-Object -Property Length -Descending | Select -First 25 Length, FullName | |
$oldFiles | Measure-Object -Property Length -Sum -Maximum -Minimum -Average | |
$oldFiles | Remove-Item -Force -Confirm | |
$emptyFolders = $folder | Get-ChildItem -Directory -Recurse ` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ConvertTo-Dictionary { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$true, ValueFromPipeline=$true)] | |
$Collection, | |
[Parameter(Mandatory=$true)] | |
[string]$Key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-WithProgress { | |
param( | |
[string] $Activity = 'Processing', | |
[int] $Loop = 0 | |
) | |
# v1.0 Initial version | |
# v1.1 Only increase progress AFTER processing an item | |
# Collect the pipeline input ($Input) up front in an array, | |
# using @(...) to force enumeration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- To check if database files are nearing the SQL Server (Express Edition) limits | |
DECLARE @version varchar(32) = CONVERT(varchar(32), SERVERPROPERTY ('ProductVersion')); | |
SELECT @version, @@VERSION; | |
DECLARE @limit_GB float; | |
IF SERVERPROPERTY('EngineEdition') = 4 -- Express Edition | |
BEGIN | |
-- SQL Server Express Edition: | |
-- Up till SQL Server 2008, limit is 4 GB / file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH BackupsPerDatabase AS | |
( | |
SELECT | |
--CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, | |
db.database_id, | |
bs.type, | |
MAX(bs.backup_finish_date) AS last_db_backup_date | |
FROM sys.databases db | |
LEFT OUTER JOIN msdb.dbo.backupset bs ON db.name = bs.database_name | |
INNER JOIN msdb.dbo.backupmediafamily bmf ON bmf.media_set_id = bs.media_set_id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Autotask Login Proxy Page</title> | |
<script> | |
function loginForm() { | |
document.myform.submit(); | |
} | |
</script> | |
</head> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# First: | |
# Create backup user | |
# bash> mysql | |
# mysql> CREATE USER 'backupuser'@'localhost' IDENTIFIED BY 'p455w0rd'; | |
# mysql> GRANT SELECT, SHOW VIEW, LOCK TABLES, RELOAD, REPLICATION CLIENT ON *.* TO 'backupuser'@'localhost'; | |
# mysql> FLUSH PRIVILEGES; | |
# mysql> exit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# system boot time | |
[Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [master] | |
GO | |
/****** Object: StoredProcedure [dbo].[sp_BackupDatabases] ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF OBJECT_ID('sp_BackupDatabases') IS NOT NULL | |
BEGIN |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$command = 'C:\SQLBackups\DoBackup.ps1' | |
# trigger hourly | |
$trigger = New-JobTrigger -Once -At '2015-01-01' -RepetitionInterval (New-TimeSpan -Hour 1) -RepetitionDuration ([TimeSpan]::MaxValue) | |
$cred = Get-Credential | |
Register-ScheduledJob -FilePath $command -Name SQLBackup -Trigger $trigger -Credential $cred | |