Skip to content

Instantly share code, notes, and snippets.

View JohnLBevan's full-sized avatar
🏠
Working from home

John Bevan JohnLBevan

🏠
Working from home
View GitHub Profile
@JohnLBevan
JohnLBevan / Get-SQLVersion.ps1
Last active August 29, 2015 14:07
Get Installed SQL Version
#NB: replace "." with instance name (e.g. ".\sqlexpress" or "axlive\sql06")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
New-Object -typeName Microsoft.SqlServer.Management.Smo.Server(".") | select edition, version
@JohnLBevan
JohnLBevan / PipeLineParamters.ps1
Created October 20, 2014 12:22
Demo of how to get content from pipeline
powershell
cls
function testme {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
@JohnLBevan
JohnLBevan / ReverseArray.ps1
Created October 21, 2014 15:47
Reverse an array in powershell
$a = ipconfig
$a
# Reverse array contents and then output it again:
[array]::Reverse($a)
$a
Start-Process powershell.exe -Credential "TestDomain\Me" -NoNewWindow -ArgumentList "Start-Process powershell.exe -Verb runAs"
--https://holsopple.wordpress.com/2011/02/18/sp_axwho-that-i-use/
USE [DynamicsTest]
GO
/****** Object: StoredProcedure [dbo].[SP_AXWHO] Script Date: 02/18/2011 14:32:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[SP_AXWHO] AS
@JohnLBevan
JohnLBevan / BatchFileDateFormat.bat
Last active August 29, 2015 14:14
Batch File Date Format
::See http://www.robvanderwoude.com/datetimentparse.php for lots of useful info on dates in batch files.
::The script below assumes a locale of UK (i.e. %date% gives DD/MM/YYYY).
@echo off
::Split date & time into component parts; assumes dd/mm/yyyy
FOR /F "TOKENS=1,2,3 DELIMS=/ " %%A IN ('echo %Date%') DO (SET dd=%%A&SET mm=%%B&SET yyyy=%%C)
FOR /F "TOKENS=1,2,3 DELIMS=:. " %%A IN ('echo %Time%') DO (SET hh=%%A&SET mi=%%B&SET ss=%%C)
::join in order of greatest affector to least (i.e. a year is longer than a month, so comes first)
@JohnLBevan
JohnLBevan / ExportDynamicsAX2012Security.sql
Created February 4, 2015 11:59
Export Dynamics AX 2012 Security
SELECT UI.Name, UI.ID, SR.AOTName, SRC.DATAAREA
FROM HarmonyLive.dbo.SecurityUserRole UR
LEFT JOIN HarmonyLive_Model.dbo.SecurityRole SR ON SR.RecId = UR.SecurityRole
LEFT JOIN HarmonyLive.dbo.UserInfo UI ON UI.Id = UR.User_ and UI.PARTITION = UR.PARTITION
left join HarmonyLive.dbo.SecurityUserRoleCondition SRC on SRC.SECURITYUSERROLE = UR.RECID and SRC.PARTITION = UR.PARTITION
WHERE UI.Enable = '1'
ORDER BY UI.Name, SR.AOTName
@JohnLBevan
JohnLBevan / Write-EventLog2.ps1
Created February 10, 2015 15:36
A wrapper for write-eventlog which given the -force parameter will first check and if needed create the log/source prior to writing to it. Also logged here: http://codereview.stackexchange.com/questions/80154/write-to-the-event-log-without-needing-to-check-whether-or-not-it-exists-by-use
cls
$myLog = 'Application'
$mySource = 'My PS Script'
$myEventId = 1
[System.Diagnostics.EventLogEntryType]$myEntryType = [System.Diagnostics.EventLogEntryType]::Error
$myMessage = 'This is a test message'
$myMessage2 = 'This is a test message (2)'
$myMessage3 = 'This is a test message (3)'
function Write-EventLog2
declare @emptyGuid uniqueidentifier;
--instead of having to type:
set @emptyGuid= '{00000000-0000-0000-0000-000000000000}'
--you can do:
set @emptyGuid = cast(cast(0 as binary) as uniqueidentifier)
--or even:
set @emptyGuid = cast(0x0 as uniqueidentifier)
--REF: http://stackoverflow.com/questions/3092999/check-empty-guid-in-sql
@JohnLBevan
JohnLBevan / CalculatedProperties.ps1
Created February 26, 2015 11:59
Powershell Calculated Properties
Select-Object Name, @{Name="LabelHere";Expression={$_.Length * 100}}