This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
# ---------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 | |
*/ |