Skip to content

Instantly share code, notes, and snippets.

View theerikandersson's full-sized avatar

Erik Andersson theerikandersson

View GitHub Profile
@theerikandersson
theerikandersson / nifty.bat
Last active April 6, 2016 08:29
Nifty bat file commands
cls
rem cleared the cmd window
@Echo Current dir: "%CD%"
@Echo Launch dir: "%~dp0"
rem jump to launchdir
pushd "%~dp0"
@Echo new current dir: "%CD%"
@theerikandersson
theerikandersson / gist:077057f44c266fbdacb5
Created March 4, 2015 08:15
Check installed Powershell version
$PSVersionTable.PSVersion
@theerikandersson
theerikandersson / gist:86a38d1abc9d99cfaa78
Created February 4, 2015 11:18
Command to get rid of phantom context menu items in Windows
REM http://superuser.com/questions/57016/menu-select-item-stuck-on-screen-after-context-or-command-menu-has-closed
tskill dwm
@theerikandersson
theerikandersson / gist:00f7fc6892cdaa796051
Created January 23, 2015 13:44
Functions for retrieving last column and row in a sheet in Excel VBA
Function TheLastColumn(sh As Worksheet)
On Error Resume Next
TheLastColumn = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
@theerikandersson
theerikandersson / gist:5b53e560d75b9c89e3e8
Last active August 29, 2015 14:13
Get disconnected Recordset from supplied sql query in VBA
Function ExecuteSql(ByVal sql As String, ByVal connectionString As String) As ADODB.Recordset
'Executes sql statement and returns a disconnected recordset
Dim oConn As ADODB.Connection
Dim oRS As ADODB.Recordset
Set oConn = New ADODB.Connection
Set oRS = New ADODB.Recordset
@theerikandersson
theerikandersson / gist:d2e01312804e25c51e46
Last active August 29, 2015 14:10
Transform XML file with msxml com object in Powershell
# 1st argument = xml file path
$xml = $args[0]
# 2nd argument = xsl file path
$xsl = $args[1]
#--------
$destinationfolder = [System.IO.Path]::GetDirectoryName($xml)
@theerikandersson
theerikandersson / gist:ddd1da5833e467654659
Created November 20, 2014 14:31
Sql query result to CSV in Powershell
# -------- config-parameters ------------
# db config
$userid = "{uid}"
$password = "{pwd}"
$connstring = "Data Source={server};Initial Catalog={db};User Id={0};Password={1}" -f $userid,$password
# output file config
$outpath = "{output folder}"
$filprefix = "{prefix for saved file}"
@theerikandersson
theerikandersson / gist:81e73ac0351e74d75c8f
Created September 2, 2014 11:27
Run Powershell script from bat file with 2 arguments
Powershell.exe -ExecutionPolicy RemoteSigned -inputformat none -file "C:\Temp\Do-StuffWithArgs.ps1" %1 %2
@theerikandersson
theerikandersson / gist:1ae4367355f058294d8d
Created September 2, 2014 11:22
Run Powershell from bat file
Powershell.exe -ExecutionPolicy RemoteSigned -inputformat none -file "C:\Temp\Do-Stuff.ps1"