Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
johnmmoss / grep.ps1
Created January 16, 2017 11:07
Example grep command
gci D:\git\TimesheetsPoc -Recurse -Filter *.csproj | foreach {
write-host Processing $_.Name -ForegroundColor Green
Get-Content $_.FullName | select-string -Pattern "v10.0"
}
@johnmmoss
johnmmoss / references.ps1
Created January 16, 2017 11:09
VisualStudio: Find all references for a library
(Get-Project -all).Object.References |
Where-Object { $_.Name -eq "Castle.Core" } |
Select-Object Identity, Path
private static string ConvertMarkdown(string unsafeMarkdown)
{
var encodedMarkdown = HttpUtility.HtmlEncode(unsafeMarkdown);
var unsafeContent = CommonMark.CommonMarkConverter.Convert(encodedMarkdown);
var safeContent = new HtmlSanitizer().Sanitize(unsafeContent);
return safeContent;
}
@johnmmoss
johnmmoss / BuildSln.ps1
Created March 6, 2017 15:00
Powershell Function to Build a visual studio sln file
function Build-Sln() {
Param(
[parameter(ValueFromPipeline)]
[string] $slnPath
)
Process {
$msbuildExe = "C:\Windows\Microsoft.Net\Framework\v4.0.30319\msbuild.exe"
@johnmmoss
johnmmoss / Setup-Pester.ps1
Created April 28, 2017 09:28
cmdlet to setup pester
function Setup-Pester {
$ModulePath = "C:\Users\johnm\Documents\WindowsPowerShell\Modules"
$PesterModulePath = "$ModulePath\Pester"
if ((Test-Path $PesterModulePath) -eq $true) {
write-host Deleting Existing -ForegroundColor Gray
ri $PesterModulePath -Recurse -Force
}
gci -Path E:\Code\ -Filter *.sln -Recurse | select Name, FullName
$lines = select-string -Path E:\Code\Application\Websit1.sln -Pattern "^Project.*"
$lines | % {
$pattern = "Project.*=\s`"([^`"]*)`", `"([^`"]*)"
if ([Regex]::IsMatch($_.Line, $pattern) ) {
$matches = [Regex]::Matches($_.Line, $pattern)
$name = $matches[0].Groups[1].Value
$path = $matches[0].Groups[2].Value
[xml] $axml= Get-Content E:\Code\Library\DataLayer.csproj
$ns = new-object Xml.XmlNamespaceManager $axml.NameTable
$ns.AddNamespace("d", "http://schemas.microsoft.com/developer/msbuild/2003")
$nodes = $axml.SelectNodes( "/d:Project/d:ItemGroup/d:Reference", $ns)
foreach ($node in $nodes) {
$object = New-Object –TypeName PSObject
$object | Add-Member -MemberType NoteProperty –Name File –Value (split-path $path -leaf)
$object | Add-Member –MemberType NoteProperty –Name Name –Value $node.Include
$object | Add-Member –MemberType NoteProperty –Name Path –Value $node.HintPath
gci -Path E:\Code -Filter *.sln -Recurse | % {
$exists = (select-string "^Project.*`"$ProjectName`"" $_.FullName).Matches.Count
if ($exists -gt 0) {
write-host $_.FullName -ForegroundColor green
} else {
write-host $_.FullName -ForegroundColor gray
}
}
$currentPsVersion = (get-host).Version.Major;
if ((get-host).Version.Major -ge 4) {
write-host Powershell version $currentPsVersion is already installed -ForegroundColor Red
return;
}
$ps4DownloadUrl = "http://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows6.1-KB2819745-x64-MultiPkg.msu"
$ps4LocalPath = "$env:temp\ps4.msu"
$wusaPath = "$env:windir\System32\wusa.exe"