Skip to content

Instantly share code, notes, and snippets.

View ukcoderj's full-sized avatar

Justin ukcoderj

View GitHub Profile
@ukcoderj
ukcoderj / nested-variables.ps1
Created September 13, 2017 14:39
How to create a nested variable in powershell
# How to create a nested variable in powershell
Clear-Host
$NestedObject1 = [pscustomobject]@{Item1="Bob";Item2="Fred";Item3="Joe"}
$ParentObject = [pscustomobject]@{LevelA=[pscustomobject]@{LevelB=@($NestedObject1)}}
#let's check it
$parentObject.LevelA.LevelB[0].Item2
@ukcoderj
ukcoderj / clean-bin-and-obj.ps1
Last active September 18, 2017 10:20
Remove all bin and object folders
Clear-Host
$folderToEmptyBins = "C:\Temp\ATest"
#short way
cd $folderToEmptyBins
get-childitem -Include "bin" -Recurse -force | Remove-Item -Force –Recurse
get-childitem -Include "obj" -Recurse -force | Remove-Item -Force –Recurse
#long way
#function DeleteSubFoldersWithName($folder, $name)
@ukcoderj
ukcoderj / vsts-clone-build-with-powershell.ps1
Last active September 22, 2017 07:56
VSTS Clone Build With Powershell
Clear-Host
$buildToCloneName = "Build 1"
$newBuildName = "Build 1 - Clone"
$user = "[email protected]"
$accessToken="4df31252fqt...PAT...."
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$accessToken)))
$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = "https://mycompany.visualstudio.com/"
$env:SYSTEM_TEAMPROJECTID = "MyProject"
@ukcoderj
ukcoderj / vsts-retain-indefinitely.ps1
Created October 12, 2017 15:47
VSTS Mark a build as retain idenfinitely (powershell)
$buildId = $env:BUILD_BUILDID # the currently running build
"Build ID: $buildId"
$keepforever = @{
keepforever='true'
}
$jsonKeepForever = $keepforever | ConvertTo-Json -Depth 100
$uriForBuildUpdate = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$($env:SYSTEM_TEAMPROJECTID)/_apis/build/builds/" + $buildID + "?api-version=2.0"
@ukcoderj
ukcoderj / createCertAndBindIis.ps1
Created November 20, 2017 16:14
Powershell - Create a self-signed certificate and create an IIS binding for the website
Clear-Host
$certificateDnsName = 'my.localcert.ssl' # a name you want to give to your certificate (can be anything you want for localhost)
$siteName = "Default Web Site" # the website to apply the bindings/cert to (top level, not an application underneath!).
$fqdn = "" #fully qualified domain name (empty for 'All unassigned', or e.g 'contoso.com')
# ----------------------------------------------------------------------------------------
# SSL CERTIFICATE CREATION
# ----------------------------------------------------------------------------------------
@ukcoderj
ukcoderj / makecertsimple.ps1
Created January 3, 2018 11:12
Simple Make Cert with Password
$certName = "mycert.mydomain.com"
$pwdString = "pa55word"
$certNamePfxPath = "C:\temp\mycert.mydomain.com.pfx"
$output = New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname $certName
$pwd = ConvertTo-SecureString -String $pwdString -Force -AsPlainText
$thumb = $output.Thumbprint
$thumb
@ukcoderj
ukcoderj / importPfxAndApplyToIisWithoutPowershell.bat
Created January 12, 2018 09:25
Import a pfx file and import to iis without powershell
cd C:\Windows\System32\inetsrv
certutil -f -p "pa$$word" -importpfx "C:\temp\mycert.pfx"
REM The thumbprint is gained by installing the certificate, going to cert manager > personal, clicking on it, then getting the Thumbprint.
REM appid can be any valid guid
netsh http add sslcert ipport=0.0.0.0:443 certhash=5de934dc39cme0234098234098dd111111111115 appid={75B2A5EC-5FD8-4B89-A29F-E5D038D5E289}
REM bind to all ip's with no domain. There are plenty of domain examples on the web
appcmd set site "Default Web Site" /+bindings.[protocol='https',bindingInformation='*:443:']
@ukcoderj
ukcoderj / ImageToBase64StringAndBack.cs
Last active May 10, 2018 10:00
Quick Handling of a downloaded image to save as base 64 string, then return to original form (assumes jpg). Requires system.drawing as well as other standard using statements
public static void GetImage_ConvertItToBase64String_ThenConvertItBack()
{
var webClient = new WebClient();
byte[] imageBytesRaw = webClient.DownloadData("http://www.google.com/images/logos/ps_logo2.png");
string imageBytesAsBase64String = Convert.ToBase64String(imageBytesRaw);
byte[] imageBytes = Convert.FromBase64String(imageBytesAsBase64String);
@ukcoderj
ukcoderj / getAndSetCss.cs
Created July 18, 2018 12:51
ExCSS getting and setting CSS Example
public void WorkWithExCss(string path)
{
// With nuget package (2.0.6) ref: https://github.com/TylerBrinks/ExCSS
// read an existing stylesheet
var css = System.IO.File.ReadAllText(path);
var stylesheet = new ExCSS.Parser().Parse(css);
// Assuming the stylesheet has a selector for 'html'
@ukcoderj
ukcoderj / SplitString.sql
Created August 28, 2018 13:29
SQL Split String
/*
Converts a delimited string to a table
Works on old versions of sql (2016, has string splitting functionality)
e.g. SplitString 'A,B,C', ','
-> Id, Data
1 A
2 B
3 C
*/