Skip to content

Instantly share code, notes, and snippets.

@Staggerlee011
Staggerlee011 / Pester Script Analyser Test
Created February 28, 2017 11:41
Pester tests which runs every script analyser rule
Import-Module -Name Pester
Import-Module -Name ScriptAnalyzer
Describe 'Script Analyzer Tests' {
Context 'Script Analyzer' {
$analysis = Invoke-ScriptAnalyzer -Path '.\MyScript.ps1'
$rules = Get-ScriptAnalyzerRule
@Staggerlee011
Staggerlee011 / PowerShell Accelerators
Created February 28, 2017 11:42
List of available PowerShell accelerators
# List of available PowerShell Accelerators to use in functions
[psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get | sort-Object -Property Value
@Staggerlee011
Staggerlee011 / Visual Studio Code - PowerShell Integrated Terminal
Created March 4, 2017 22:10
Code to configure Visual Studio Code for PowerShell as the integrated terminal
// File -> Preferences -> Settings : Settungs.json
// Update to the below code (Starting line 4, added alternates that may come in useful at other times, at present you cant choose which to load :(
{
// 64-bit PowerShell if available, otherwise 32-bit
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
// Git Bash
//"terminal.integrated.shell.windows3": "C:\\Program Files\\Git\\bin\\bash.exe",
// 64-bit cmd if available, otherwise 32-bit
//"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe"
@Staggerlee011
Staggerlee011 / Common SQL Server CLR database settings
Created March 8, 2017 15:03
Common SQL Server CLR database settings
SELECT 'Pre Deployment Changes',name ,
is_trustworthy_on ,
SUSER_SNAME(owner_sid) AS [DBOwner]
FROM sys.databases
WHERE name = 'databaseName';
USE [master];
GO
ALTER DATABASE databaseName SET READ_WRITE WITH ROLLBACK IMMEDIATE;
GO
$env:ServerName = "MyServer"
$env:JenkinsUser = "domain\login"
$env:JenkinsPassword = "SuperSecretPassword"
## Ivoke OS Pester test output to OSreport.xml
Invoke-Pester -Script @{Path ='C:\GIT\DBA\Build\Pester\SQL Server OS.test.ps1'; Parameters = @{ServerName = $($env:ServerName); JenkinsUser = $($env:JenkinsUser) ; JenkinsPassword = $($env:JenkinsPassword)}} -OutputFile OSreport.xml -OutputFormat NUnitXml
## Push data into SQL Server via DBATools
$output = Parse-PesterXML -XMLFile ./OSreport.xml -Server $env:ServerName | Out-DbaDataTable
Write-DbaDataTable -SqlServer PRD-SQL-INT01 -InputObject $output -Table admin.dbo.pesterresults -AutoCreateTable
@Staggerlee011
Staggerlee011 / Chef Commands
Last active November 22, 2017 11:22
Collection of Chef commands by Example
# help
chef --help
chef generate --help
# Create Chef-Repo
Chef generate repo chef-repo
# Create new Cookbook
Chef generate cookbook ax_SQLServer
@Staggerlee011
Staggerlee011 / Chef knife Cookbooks
Last active November 20, 2017 15:13
Chef knife commands for cookbooks by Example
# list all cookbooks on Chef Server
knife cookbook list
# List all cookbooks on Chef Server (with version info)
knife cookbook list -a
# download all cookbooks from the Chef Server
knife download cookbooks
# Upload all cookbooks from workstation to Chef Server
@Staggerlee011
Staggerlee011 / Chef Test-Kitchen By Example
Created November 20, 2017 11:33
Collection of Chef Test-Kitchen commands by example
## list kitchen test state
kitchen list
## creates vm based on kitchen.yml
kitchen create
## applies cookbook to vm
kitchen converge
## kitchen verify runs tests from folder:
@Staggerlee011
Staggerlee011 / Chef Knife Roles
Created November 20, 2017 16:21
Collection of knife commands for Roles by example
# help
knife role --help
# List all roles
knife role list
# Details of role
knife role show myrole
# Create a role from a file
@Staggerlee011
Staggerlee011 / Chef run_list commands
Created November 21, 2017 10:18
Collection of Chef run_list commands
## list the run_lists on a node
knife node run_list list <NODE> -r
## Set a run_list
knife node run_list <NODE> 'recipe[iis]'
## Add an item before
knife node run_list add <NODE> recipe[basicconfig::join_ad] -b recipe[iis]
## Add an item after