Skip to content

Instantly share code, notes, and snippets.

@roe3p
roe3p / BackupAgentJobs.ps1
Created July 19, 2019 16:56
DBA - Backup SQL Agent Jobs
<# Script out all SQL Agent jobs #>
$ServerInstance = "MY_SERVER"
$OutputPath ="G:\BACKUPS\MY_SERVER\MY_SERVERAgentJobs\"
$jobs = Get-DbaAgentJob -SqlInstance $serverInstance
foreach ($job in $jobs)
{
$jobnameclean = $job.Name
#Write-Host "Job Name before clean: " $jobnameclean
@roe3p
roe3p / ExportDBUsers.ps1
Created June 25, 2019 11:12
Export DB Users using DBATools
$ServerName = "Myserver.mydomain.co.uk"
$OutputPath = "G:\Backups\SRV01Users\"
$Dt = Get-Date -f yyyyMMdd #-hhmmss
$Databases = Get-DbaDatabase -sqlinstance localhost
$Counter = 1
$DBCount = $Databases.Count
@roe3p
roe3p / InvokeCommandWithStoredCreds.ps1
Created June 12, 2019 10:44
Use Stored Password to Invoke a PS command
## Use Windows Credentials encrypted and stored in a file to invoke a PS command. Using the concept at:
## https://interworks.com/blog/trhymer/2013/07/08/powershell-how-encrypt-and-store-credentials-securely-use-automation-scripts
## Useful to run in situations where double-hop authentication is a problem
$Username = 'p_service_account'
$passfile = 'D:\scripts\p_service_account_password.txt'
$encrypted = Get-Content $passfile | ConvertTo-SecureString
$Cred = New-Object System.Management.Automation.PsCredential($Username, $encrypted)
$ServerName = 'SVR01.mydomain.com'
@roe3p
roe3p / CheckStoredPassword.ps1
Created June 12, 2019 10:37
Check a stored password
## This script will retrieve a stored encrypted password to ensure the PS session has been started under the correct
## user context. This should only be needed for debugging/testing as the password will be exposed as plaintext
## (Note the same account password must be entered before the stored version will be decrypted)
##
## If the p/w does not come out as expected, try opening the PS session using 'Run as a different user' then
## entering the creds of the account the encrypted password belongs to (usually a service acct). Or enter the following:
## start powershell_ise -credential ""
##
"User: " + $env:UserName
@roe3p
roe3p / EncryptPassword.ps1
Created June 12, 2019 10:32
Encrypt a password/key and store in a file
## Encrypt a password/key in a file using Windows Credentials
## To log on as another user (e.g. a service acct), use:
## start powershell_ise -credential ""
$filename = 'D:\scripts\p_ssas_backup_password.txt'
$credential = Get-Credential -Message "Enter password" -UserName $env:username ## e.g. mydomain\p_ssas_backup'
$credential.Password | ConvertFrom-SecureString | Set-Content $filename
@roe3p
roe3p / GetSPParameters.sql
Last active November 16, 2018 11:24
SQL Stored proc that gets parameter info for another stored proc - required by the VBA module that executes stored procedures
CREATE PROCEDURE usp_GetSPParameters @SPName VARCHAR(50)
AS
BEGIN
SET NOCOUNT ON;
SELECT
Name AS ParameterName,
TYPE_NAME(user_type_id) AS DataType,
max_length AS CharacterMaxLength,
scale AS NumericScale,
precision AS NumericPrecision
@roe3p
roe3p / mdlGen_Functions.vb
Last active March 23, 2023 04:54
Assortment of Excel VBA UDFs
'Module containing generic functions. Any requisite functions/variables are now annotated
'in the routine header, allowing this module to be swapped out more easily
'
' (c) R Shenoy 30/07/2013
'
' Last Updated 16/11/2018
Option Explicit
'Used for function that gets screen size
@roe3p
roe3p / A5Language.js
Created May 18, 2016 11:14
A5 Language Switching Functions
//''------------------------- Language Functions
function setLanguage(){
var lang = {dialog.object}.appVars.currentLanguage;
if(lang == 'English') {
A5.msgBox.buttons.cancel = {html: "Cancel"};
A5.msgBox.buttons.yes = {html: "Yes"};
A5.msgBox.buttons.no = {html: "No"};
} else {
@roe3p
roe3p / A5Validation.js
Created May 18, 2016 11:11
A5 Field validation functions
//''------------------------- Validation Functions
function isValidDate(s) {
var bits = s.split('/');
var d = new Date(bits[2], bits[1] - 1, bits[0]);
return d && (d.getMonth() + 1) == bits[1] && d.getDate() == Number(bits[0]);
}
function validate(data, type, maxLen, req){
//debugger;
req = (typeof(req) == 'undefined') ? true : req;
@roe3p
roe3p / A5Authentication.js
Last active May 18, 2016 11:13
A5 Authentication functions for a PhoneGap app (requires Alpha Apps Server)
//''------------------------- Authentication Functions
function authenticate(){
var data = getLoginDetails();
jQuery.ajax({
type: "GET",
url: {dialog.object}.appVars.appURL + "ajax.a5w",
timeout: 30000,