├── GlobalScripts ├── Remove-Item.ps1 ├── xsd.ps1 ├── Dump-CurrentDirectory.ps1 ├── CopyPaste.ps1 ├── touch.ps1 ├── markpad.ps1 ├── Load-Assembly.ps1 ├── Find-Program.ps1 ├── AddTo-7zip.ps1 ├── Invoke-NullCoalescing.ps1 ├── sha1.ps1 ├── Get-WebFileTest.ps1 ├── Set-VisualStudioEnvironmentConfiguration.ps1 ├── gitHelpers.ps1 ├── invoke-psake-locally.ps1 ├── Create-ZipDiffPackage.ps1 ├── find-string.ps1 ├── Is-FileBinary.ps1 ├── Check-Url.ps1 ├── Change-Directory.ps1 └── Get-WebFile.ps1 ├── ReadMe.md ├── .gitignore ├── Bootstrap ├── initPsProfile.ps1 └── BootIt.ps1 └── initProfile.ps1 /GlobalScripts/Remove-Item.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staxmanade/DevMachineSetup/HEAD/GlobalScripts/Remove-Item.ps1 -------------------------------------------------------------------------------- /GlobalScripts/xsd.ps1: -------------------------------------------------------------------------------- 1 | function xsd() { 2 | & (Find-Program "Microsoft SDKs\Windows\v7.0A\Bin\xsd.exe") $args 3 | } 4 | -------------------------------------------------------------------------------- /GlobalScripts/Dump-CurrentDirectory.ps1: -------------------------------------------------------------------------------- 1 | function Dump-CurrentDirectory(){ 2 | (pwd).Path 3 | } 4 | 5 | set-alias cdir Dump-CurrentDirectory 6 | -------------------------------------------------------------------------------- /GlobalScripts/CopyPaste.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-ClipboardText { 3 | add-type -an system.windows.forms 4 | [System.Windows.Forms.Clipboard]::GetText() 5 | } 6 | 7 | set-alias paste Get-ClipboardText 8 | 9 | set-alias pbpaste Get-ClipboardText 10 | set-alias pbcopy clip 11 | -------------------------------------------------------------------------------- /GlobalScripts/touch.ps1: -------------------------------------------------------------------------------- 1 | function touch($file) { 2 | if(test-path $file) { 3 | $f = get-item $file; 4 | $d = get-date 5 | $f.LastWriteTime = $d 6 | } 7 | else 8 | { 9 | "" | out-file -FilePath $file -Encoding ASCII 10 | } 11 | } -------------------------------------------------------------------------------- /GlobalScripts/markpad.ps1: -------------------------------------------------------------------------------- 1 | 2 | function markpad($file){ 3 | 4 | $markpadExe = "$($env:HOME)\AppData\Local\MarkPad\MarkPad.exe" 5 | 6 | if( test-path $markpadExe) { 7 | 8 | & $markpadExe (get-item $file) 9 | } 10 | else { 11 | 12 | throw "markpad not found: cinst markpad" 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /GlobalScripts/Load-Assembly.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Load-Assembly($assembly) 3 | { 4 | echo $assembly 5 | if(test-path $assembly) 6 | { 7 | $assemblyPath = get-item $assembly 8 | [System.Reflection.Assembly]::LoadFrom($assemblyPath) 9 | } 10 | else 11 | { 12 | [System.Reflection.Assembly]::LoadWithPartialName("$assembly") 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /GlobalScripts/Find-Program.ps1: -------------------------------------------------------------------------------- 1 | function Find-Program($folderName) 2 | { 3 | $p1 = "C:\Program Files\$folderName" 4 | if(!(test-path $p1)) 5 | { 6 | $p2 = "C:\Program Files (x86)\$folderName" 7 | 8 | if((test-path $p2)) 9 | { 10 | $p2 11 | } 12 | } 13 | else 14 | { 15 | $p1 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /GlobalScripts/AddTo-7zip.ps1: -------------------------------------------------------------------------------- 1 | function AddTo-7zip($zipFileName) { 2 | BEGIN { 3 | #$7zip = "$($env:ProgramFiles)\7-zip\7z.exe" 4 | $7zip = Find-Program "\7-zip\7z.exe" 5 | if(!([System.IO.File]::Exists($7zip))){ 6 | throw "7zip not found"; 7 | } 8 | } 9 | PROCESS { 10 | & $7zip a -tzip $zipFileName $_ 11 | } 12 | END { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /GlobalScripts/Invoke-NullCoalescing.ps1: -------------------------------------------------------------------------------- 1 | # Copied from posh-git 2 | # https://github.com/dahlbyk/posh-git/blob/master/Utils.ps1 3 | 4 | 5 | function Invoke-NullCoalescing { 6 | $result = $null 7 | foreach($arg in $args) { 8 | if ($arg -is [ScriptBlock]) { 9 | $result = & $arg 10 | } else { 11 | $result = $arg 12 | } 13 | if ($result) { break } 14 | } 15 | $result 16 | } 17 | 18 | Set-Alias ?? Invoke-NullCoalescing -Force 19 | -------------------------------------------------------------------------------- /GlobalScripts/sha1.ps1: -------------------------------------------------------------------------------- 1 | function sha1() 2 | { 3 | <# 4 | Thank you Brad Wilson 5 | http://bradwilson.typepad.com/blog/2010/03/calculating-sha1-in-powershell.html 6 | #> 7 | 8 | [Reflection.Assembly]::LoadWithPartialName("System.Security") | out-null 9 | $sha1 = new-Object System.Security.Cryptography.SHA1Managed 10 | 11 | $args | %{ 12 | resolve-path $_ | %{ 13 | write-host ([System.IO.Path]::GetFilename($_.Path)) 14 | 15 | $file = [System.IO.File]::Open($_.Path, "open", "read") 16 | $sha1.ComputeHash($file) | %{ 17 | write-host -nonewline $_.ToString("x2") 18 | } 19 | $file.Dispose() 20 | 21 | write-host 22 | write-host 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /GlobalScripts/Get-WebFileTest.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Get-WebFileTest { 3 | [CmdletBinding()] 4 | param( 5 | [Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)] 6 | [string[]] $urls, 7 | $fileName = $null, 8 | [switch]$Passthru, 9 | [switch]$quiet 10 | ) 11 | BEGIN { 12 | $webClient = New-Object System.Net.WebClient 13 | } 14 | PROCESS { 15 | 16 | foreach($url in $urls) { 17 | 18 | $file = $webClient.DownloadString($url) 19 | 20 | New-Object Object ` 21 | | Add-Member NoteProperty Url $url -PassThru ` 22 | | Add-Member NoteProperty Contents $file -PassThru 23 | } 24 | } 25 | END { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /GlobalScripts/Set-VisualStudioEnvironmentConfiguration.ps1: -------------------------------------------------------------------------------- 1 | function Set-VisualStudioEnvironmentConfiguration(){ 2 | 3 | if(!($DTE)){ 4 | throw "This function must be executed within the Nuget Package Manager to work correctly."; 5 | } 6 | 7 | # Map Ctrl+W to close a tab 8 | $DTE.Commands.Item("File.Close").Bindings = "Global::Ctrl+W"; 9 | $DTE.Commands.Item("File.Close").Bindings = "Text Editor::Ctrl+W" 10 | 11 | # Turn on line numbers for ALL language types 12 | ($DTE.Properties("TextEditor", "AllLanguages") | where {$_.Name -eq "ShowLineNumbers" } ).Value = $true 13 | 14 | # Autoload files when they've changed on disk - great for git branch switching or typescript reloads of js files. 15 | ($DTE.Properties("Environment", "Documents") | where {$_.Name -eq "AutoloadExternalChanges" }).Value = $true 16 | 17 | } 18 | -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | 2 | > By: [@staxmanade](http://staxmanade.com) 3 | 4 | Purpose for repo! 5 | -- 6 | 7 | 8 | 9 | To organize the configuration and setup of my typical development environment. 10 | 11 | 12 | 13 | 1. One time setup of my developer machine 14 | -- 15 | 16 | Execute the following one-liner in an elevated powershell prompt 17 | 18 | set-executionpolicy unrestricted; 19 | iex ((new-object net.webclient).DownloadString('https://raw.github.com/staxmanade/DevMachineSetup/master/Bootstrap/BootIt.ps1')) 20 | 21 | 22 | 2. Initialize powershell profile 23 | -- 24 | 25 | NOTE: This is already included in the #1 above 26 | 27 | set-executionpolicy unrestricted; 28 | iex ((new-object net.webclient).DownloadString('https://raw.github.com/staxmanade/DevMachineSetup/master/Bootstrap/initPsProfile.ps1')) 29 | 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | #OS junk files 3 | [Tt]humbs.db 4 | *.DS_Store 5 | 6 | #Visual Studio files 7 | *.[Oo]bj 8 | *.user 9 | *.aps 10 | *.pch 11 | *.vspscc 12 | *.vssscc 13 | *_i.c 14 | *_p.c 15 | *.ncb 16 | *.suo 17 | *.tlb 18 | *.tlh 19 | *.bak 20 | *.[Cc]ache 21 | *.ilk 22 | *.log 23 | *.lib 24 | *.sbr 25 | *.sdf 26 | *.docstates 27 | ipch/ 28 | obj/ 29 | [Bb]in 30 | [Dd]ebug*/ 31 | [Rr]elease*/ 32 | 33 | #Tooling 34 | _ReSharper*/ 35 | *.resharper 36 | [Tt]est[Rr]esult* 37 | *.Tests.VisualState.xml 38 | *.vs10x 39 | 40 | #Project and build files 41 | [Bb]uild/Packages/ 42 | Temp/ 43 | 44 | #Subversion files 45 | .svn 46 | 47 | # Office Temp Files 48 | ~$* 49 | 50 | # WCF diagnostic files 51 | *.svclog 52 | 53 | # DB Professional files 54 | *.dbmdl 55 | 56 | # Include the DebugReleaseImplementations folder which would be ignored by the above 57 | !*DebugReleaseImplementations/ 58 | 59 | # Files added by the Visual Studio Productivity Power Tools extension 60 | *.docstates 61 | 62 | # Files created by the git mergetool 63 | *.orig 64 | 65 | # VIM backup files 66 | *~ 67 | 68 | # 69 | # CUSTOM PROJECT IGNORE 70 | # 71 | 72 | NuGet_profile.ps1 73 | -------------------------------------------------------------------------------- /GlobalScripts/gitHelpers.ps1: -------------------------------------------------------------------------------- 1 | function gitinit() 2 | { 3 | git init 4 | if($LASTEXITCODE) 5 | { 6 | return; 7 | } 8 | 9 | $gitIgnoreRemotePath = 'https://raw.github.com/staxmanade/Scripts/master/.gitignore.rename' 10 | $destinationPath = "$(pwd)\.gitignore" 11 | $clnt = new-object System.Net.WebClient 12 | echo "Downloading base .gitignore from - $gitIgnoreRemotePath" 13 | $clnt.DownloadFile($gitIgnoreRemotePath, "$destinationPath") 14 | } 15 | 16 | function gitGo($message) { 17 | 18 | git add . 19 | git commit . -m $message 20 | 21 | 22 | } 23 | 24 | function gitlog() { 25 | 26 | # found on StackOverflow 27 | # http://stackoverflow.com/questions/1838873/visualizing-branch-topology-in-git 28 | 29 | git log --graph --full-history --all --color --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s" 30 | } 31 | 32 | function gitstandup() { 33 | 34 | # Good post on git pretty formatting 35 | # http://alexefish.com/post/18453172089/pretty-git-logging 36 | git log --author=Jason --graph --full-history --all --color --pretty=format:"%ar %x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s" 37 | } 38 | 39 | function gitsummary(){ 40 | git shortlog --numbered --summary --no-merges 41 | } 42 | function gitFixWhiteSpace { git rm --cached -r .; git reset --hard; } 43 | -------------------------------------------------------------------------------- /GlobalScripts/invoke-psake-locally.ps1: -------------------------------------------------------------------------------- 1 | 2 | function invoke-psake-locally 3 | { 4 | # Helper script for those who want to run psake without importing the module. 5 | # Example: 6 | # .\psake.ps1 "default.ps1" "BuildHelloWord" "4.0" 7 | 8 | # Must match parameter definitions for psake.psm1/invoke-psake 9 | # otherwise named parameter binding fails 10 | param( 11 | [Parameter(Position=0,Mandatory=0)] 12 | [string]$buildFile = 'default.ps1', 13 | [Parameter(Position=1,Mandatory=0)] 14 | [string[]]$taskList = @(), 15 | [Parameter(Position=2,Mandatory=0)] 16 | [string]$framework = '4.0', 17 | [Parameter(Position=3,Mandatory=0)] 18 | [switch]$docs = $false, 19 | [Parameter(Position=4,Mandatory=0)] 20 | [System.Collections.Hashtable]$parameters = @{}, 21 | [Parameter(Position=5, Mandatory=0)] 22 | [System.Collections.Hashtable]$properties = @{} 23 | ) 24 | 25 | try { 26 | $psakeModulePath = (join-path ($pwd).Path psake.psm1) 27 | 28 | if(!(test-path $psakeModulePath)) 29 | { 30 | throw "Cannot find $psakeModulePath" 31 | } 32 | import-module $psakeModulePath 33 | invoke-psake $buildFile $taskList $framework $docs $parameters $properties 34 | } finally { 35 | remove-module psake -ea 'SilentlyContinue' 36 | } 37 | } 38 | set-alias ip invoke-psake-locally 39 | -------------------------------------------------------------------------------- /Bootstrap/initPsProfile.ps1: -------------------------------------------------------------------------------- 1 | # Developer machine setup - run the below oneliner (in an elevated PS profile to setup a my development environment) 2 | # iex ((new-object net.webclient).DownloadString('https://raw.github.com/staxmanade/DevMachineSetup/master/Bootstrap/initPsProfile.ps1')) 3 | # 4 | 5 | ##### What is this script doing? 6 | # 1. Make the `$Profile` directory if it doesn't exist. 7 | # 2. CD into that profile directory 8 | # 3. If the DevMachineSetup folder already exists (use git to pull down the latest version) 9 | # Else clone the DevMachineSetup folder from my github 10 | # 4. Now make sure that the `initProfile` script gets loaded into the `$Profile` 11 | # 5. Dot-Source the `$Profile` so we have the latest/greatest. 12 | 13 | $profileDir = (split-path $profile) 14 | if(! (test-path $profileDir)) 15 | { 16 | mkdir $profileDir 17 | } 18 | 19 | pushd $profileDir 20 | 21 | if(test-path DevMachineSetup) 22 | { 23 | pushd DevMachineSetup 24 | try{ 25 | git pull 26 | } 27 | catch{ 28 | $error 29 | } 30 | popd 31 | } 32 | else 33 | { 34 | git clone https://github.com/staxmanade/DevMachineSetup.git 35 | } 36 | 37 | if(!(cat $profile | select-string 'DevMachineSetup\\initProfile.ps1')) 38 | { 39 | "Adding initProfile to $Profile" 40 | ". `"$(split-path $profile)\DevMachineSetup\initProfile.ps1`"" | Out-File $profile -append -encoding ASCII 41 | } 42 | . $profile 43 | popd 44 | -------------------------------------------------------------------------------- /GlobalScripts/Create-ZipDiffPackage.ps1: -------------------------------------------------------------------------------- 1 | function Create-ZipDiffPackage() { 2 | 3 | param( 4 | $beginSha = $(throw '-beginSha is required'), 5 | $endSha = $(throw '-endSha is required'), 6 | $projectName = $( (get-item .).name ) 7 | ) 8 | 9 | 10 | # Get a list of all the files that have been added/modified/deleted 11 | $filesWithMods = git diff --name-status $beginSha $endSha | Select @{Name="ChangeType";Expression={$_.Substring(0,1)}}, @{Name="File"; Expression={$_.Substring(2)}} 12 | 13 | # There has to be a cleaner way? (to get the sha1 of the 'end commit') 14 | $endShaShortName = (git log --format=%H $endSha | select -First 1).Substring(0, 10) 15 | $beginShaShortName = (git log --format=%H $beginSha | select -First 1).Substring(0, 10) 16 | 17 | $deployFileBasename = "..\$($projectName)_$endShaShortName" 18 | 19 | #var to hold the 'readme' file we're dumping information to 20 | $rm = "$deployFileBaseName.txt" 21 | 22 | 23 | "Changes from $beginShaShortName to $endShaShortName" > $rm 24 | "" >> $rm 25 | 26 | "Files Removed:" >> $rm 27 | $filesWithMods | where{$_.ChangeType -eq 'D' } | %{ "`t" + $_.File } >> $rm 28 | "" >> $rm 29 | 30 | $filesAddedOrModified = $filesWithMods | where{$_.ChangeType -ne 'D' } 31 | "Files Added or Modified:" >> $rm 32 | $filesWithMods | where{$_.ChangeType -ne 'D' } | %{ "`t" + $_.File } >> $rm 33 | "" >> $rm 34 | "" >> $rm 35 | "" >> $rm 36 | 37 | "Complete git diff between the changes:" >> $rm 38 | git diff $beginSha $endSha >> $rm 39 | 40 | # Dump the modified/added files to the zip (excluding the deleted files) 41 | $filesAddedOrModified | %{ $_.File} | AddTo-7Zip "$deployFileBasename.zip" | out-null 42 | } 43 | 44 | 45 | -------------------------------------------------------------------------------- /GlobalScripts/find-string.ps1: -------------------------------------------------------------------------------- 1 | 2 | # copied this from 3 | # http://weblogs.asp.net/whaggard/archive/2007/03/23/powershell-script-to-find-strings-and-highlight-them-in-the-output.aspx 4 | 5 | function Find-String(){ 6 | # Find-String.ps1 7 | # Wrapper around dir | select-string which will highlight the pattern in the results 8 | param ( [string] $pattern = "" 9 | , [string] $filter = "*.*" 10 | , [switch] $recurse = $false 11 | , [switch] $caseSensitive = $false) 12 | 13 | if ($pattern -eq $null -or $pattern -eq "") { Write-Error "Please provide a search pattern!" ; return } 14 | 15 | $regexPattern = $pattern 16 | if($caseSensitive -eq $false) { $regexPattern = "(?i)$regexPattern" } 17 | $regex = New-Object System.Text.RegularExpressions.Regex $regexPattern 18 | 19 | # Write the line with the pattern highlighted in red 20 | function Write-HostAndHighlightPattern([string]$inputText) 21 | { 22 | $index = 0 23 | while($index -lt $inputText.Length) 24 | { 25 | $match = $regex.Match($inputText, $index) 26 | if($match.Success -and $match.Length -gt 0) 27 | { 28 | Write-Host $inputText.SubString($index, $match.Index - $index) -nonewline 29 | Write-Host $match.Value.ToString() -ForegroundColor Red -nonewline 30 | $index = $match.Index + $match.Length 31 | } 32 | else 33 | { 34 | Write-Host $inputText.SubString($index) -nonewline 35 | $index = $inputText.Length 36 | } 37 | } 38 | } 39 | 40 | # Do the actual find in the files 41 | Get-ChildItem -recurse:$recurse -filter:$filter | where { !$_.PSIsContainer } | where { !(Is-FileBinary $_) } | 42 | Select-String -caseSensitive:$caseSensitive -pattern:$pattern | 43 | foreach { 44 | Write-Host "$($_.FileName)($($_.LineNumber)): " -nonewline 45 | Write-HostAndHighlightPattern $_.Line 46 | Write-Host 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /initProfile.ps1: -------------------------------------------------------------------------------- 1 | function Coalesce-Paths { 2 | $result = $null 3 | foreach($arg in $args) { 4 | if ($arg -is [ScriptBlock]) { 5 | $result = & $arg 6 | } else { 7 | $result = $arg 8 | } 9 | if($result){ 10 | if (test-path "$result") { break } 11 | } 12 | } 13 | $result 14 | } 15 | 16 | # - this will attempt to pull down the latest profile in the background. 17 | $profileUpdatedVar = "LastProfileUpdatedDate" 18 | 19 | if([Environment]::GetEnvironmentVariable($profileUpdatedVar, "User") -lt ((get-date).Date)) { 20 | 21 | if(test-path (split-path $profile)){ 22 | pushd (split-path $profile) 23 | pushd DevMachineSetup 24 | git pull 25 | 26 | [Environment]::SetEnvironmentVariable($profileUpdatedVar, (get-date).Date, "User") 27 | popd 28 | popd 29 | } 30 | else { 31 | "Could not update profile because the folder doesn't exist? - weird!" 32 | } 33 | } 34 | 35 | $globalProfileScriptsPath = "$(split-path $profile)\DevMachineSetup\GlobalScripts\" 36 | foreach($file in (ls "$globalProfileScriptsPath*.ps1")) 37 | { 38 | "Dot Sourcing Script - $($file.FullName)" 39 | . $file.FullName 40 | } 41 | 42 | 43 | 44 | $tfPath = Coalesce-Paths (Find-Program 'Microsoft Visual Studio 11.0\Common7\IDE\TF.exe' -force) (Find-Program 'Microsoft Visual Studio 10.0\Common7\IDE\TF.exe' -force) 45 | function tf(){ 46 | if($tfPath -and (test-path $tfPath)) { 47 | & $tfPath $args; 48 | } 49 | else { 50 | throw "TF path [$tfPath] could not be found" 51 | } 52 | } 53 | 54 | 55 | $editorOfChoice = Coalesce-Paths (Find-Program 'vim\vim73\vim.exe') (Find-Program 'Notepad++\notepad++.exe') 56 | if($editorOfChoice) 57 | { 58 | set-alias notepad $editorOfChoice 59 | set-alias edit $editorOfChoice 60 | } 61 | 62 | # got used to using 'open' on the mac to open files 63 | set-alias open invoke-item 64 | 65 | 66 | if($error.Count -eq 0) 67 | { 68 | cls 69 | } 70 | -------------------------------------------------------------------------------- /GlobalScripts/Is-FileBinary.ps1: -------------------------------------------------------------------------------- 1 | function Is-FileBinary(){ 2 | 3 | param( 4 | [Parameter( 5 | Position=0, 6 | Mandatory=$true, 7 | ValueFromPipeline=$true, 8 | ValueFromPipelineByPropertyName=$true) 9 | ] 10 | [Alias('FullName')] 11 | [String[]]$FilePath 12 | ) 13 | 14 | # Copied/modified from 15 | # http://stackoverflow.com/questions/1077634/powershell-search-script-that-ignores-binary-files 16 | 17 | 18 | BEGIN { 19 | 20 | } 21 | PROCESS { 22 | # The file to be tested 23 | 24 | if($FilePath -and ($FilePath.PsIsContainer)) 25 | { 26 | throw "this only works against files, not folders [$FilePath]"; 27 | return; 28 | } 29 | 30 | # encoding variable 31 | $encoding = "" 32 | 33 | # Get the first 1024 bytes from the file 34 | $byteArray = Get-Content -Path $FilePath -Encoding Byte -TotalCount 1024 35 | 36 | if( ("{0:X}{1:X}{2:X}" -f $byteArray) -eq "EFBBBF" ) 37 | { 38 | # Test for UTF-8 BOM 39 | $encoding = "UTF-8" 40 | } 41 | elseif( ("{0:X}{1:X}" -f $byteArray) -eq "FFFE" ) 42 | { 43 | # Test for the UTF-16 44 | $encoding = "UTF-16" 45 | } 46 | elseif( ("{0:X}{1:X}" -f $byteArray) -eq "FEFF" ) 47 | { 48 | # Test for the UTF-16 Big Endian 49 | $encoding = "UTF-16 BE" 50 | } 51 | elseif( ("{0:X}{1:X}{2:X}{3:X}" -f $byteArray) -eq "FFFE0000" ) 52 | { 53 | # Test for the UTF-32 54 | $encoding = "UTF-32" 55 | } 56 | elseif( ("{0:X}{1:X}{2:X}{3:X}" -f $byteArray) -eq "0000FEFF" ) 57 | { 58 | # Test for the UTF-32 Big Endian 59 | $encoding = "UTF-32 BE" 60 | } 61 | 62 | if($encoding) 63 | { 64 | # File is text encoded 65 | return $false 66 | } 67 | 68 | # So now we're done with Text encodings that commonly have '0's 69 | # in their byte steams. ASCII may have the NUL or '0' code in 70 | # their streams but that's rare apparently. 71 | 72 | # Both GNU Grep and Diff use variations of this heuristic 73 | 74 | if( $byteArray -contains 0 ) 75 | { 76 | # Test for binary 77 | return $true 78 | } 79 | 80 | # This should be ASCII encoded 81 | $encoding = "ASCII" 82 | 83 | return $false 84 | } 85 | END { 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /GlobalScripts/Check-Url.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Takes a list of urls and verifies that the url is valid. 4 | 5 | .DESCRIPTION 6 | The Check-Url script takes a piped list of url and attempts download the HEAD of the file from the web. If it retrieves an HTTP status of OK then the URL is reported as valid. If the result is anything else or an exception, then the url is reported as invalid. 7 | 8 | .INPUTS 9 | List of url's to check. Note: the url's must begin with http:// or https:// 10 | 11 | .OUTPUTS 12 | Returns a powershell object with two properties 13 | 1. IsValid [bool] - signifies weather the url was determined as Valid or not 14 | 2. Url [string] - the url that was checked. 15 | 3. HttpStatus - The http status resulting from the web request. 16 | 4. Error - Any possible error resulting from the request. 17 | 18 | .EXAMPLE 19 | @('http://www.google.com', 'http://www.asd----fDSAWQSDF-GZz.com') | .\Check-Url.ps1 20 | 21 | .EXAMPLE 22 | @('http://www.google.com', 'http://www.asd----fDSAWQSDF-GZz.com') | .\Check-Url.ps1 | where { !$_.IsValid } 23 | Reports the Invalid url's. 24 | #> 25 | 26 | BEGIN { 27 | } 28 | PROCESS { 29 | ## You have to at least make sure it's got a value 30 | ## Really you should check it's TYPE to make sure you can do something useful... 31 | if($_) { 32 | 33 | $url = $_; 34 | 35 | $urlIsValid = $false 36 | try 37 | { 38 | $request = [System.Net.WebRequest]::Create($url) 39 | $request.Method = 'HEAD' 40 | $response = $request.GetResponse() 41 | $httpStatus = $response.StatusCode 42 | $urlIsValid = ($httpStatus -eq 'OK') 43 | $tryError = $null 44 | $response.Close() 45 | } 46 | catch [System.Exception] { 47 | $httpStatus = $null 48 | $tryError = $_.Exception 49 | $urlIsValid = $false; 50 | } 51 | 52 | $x = new-object Object | ` 53 | add-member -membertype NoteProperty -name IsValid -Value $urlIsvalid -PassThru | ` 54 | add-member -membertype NoteProperty -name Url -Value $_ -PassThru | ` 55 | add-member -membertype NoteProperty -name HttpStatus -Value $httpStatus -PassThru | ` 56 | add-member -membertype NoteProperty -name Error -Value $tryError -PassThru 57 | $x 58 | } 59 | } 60 | END { 61 | 62 | } 63 | <# 64 | References... 65 | 66 | http://stackoverflow.com/questions/924679/c-how-can-i-check-if-a-url-exists-is-valid 67 | http://huddledmasses.org/using-script-functions-in-the-powershell-pipeline/ 68 | #> 69 | -------------------------------------------------------------------------------- /Bootstrap/BootIt.ps1: -------------------------------------------------------------------------------- 1 | # Developer machine setup - run the below oneliner (in an elevated PS profile to setup a my development environment) 2 | # iex ((new-object net.webclient).DownloadString('https://raw.github.com/staxmanade/DevMachineSetup/master/Bootstrap/BootIt.ps1')) 3 | # 4 | 5 | 6 | # Install Chocolatey from chocolatey.org 7 | iex ((new-object net.webclient).DownloadString('http://bit.ly/psChocInstall')) 8 | 9 | # add chocolatey to the path since v0.9.8.16 doesn't do it. 10 | if(!(where.exe chocolatey)){ $env:Path += ';C:\Chocolatey\bin;' } 11 | 12 | # get the pre released version. It haz cool features! 13 | chocolatey install chocolatey -pre 14 | 15 | 16 | $chocolateyIds = '7zip 17 | notepadplusplus 18 | poshgit 19 | fiddler 20 | treesizefree 21 | P4Merge 22 | wincommandpaste 23 | linqpad4 24 | putty 25 | f.lux 26 | SkyDrive 27 | paint.net 28 | git-credential-winstore 29 | dotpeek 30 | googlechrome 31 | WindowsLiveWriter 32 | boxstarter' 33 | 34 | $chocolateyIds > ChocolateyInstallIds.txt 35 | $path = get-item 'ChocolateyInstallIds.txt' 36 | $notepad = [System.Diagnostics.Process]::Start( "notepad.exe", $path ) 37 | $notepad.WaitForExit() 38 | $chocolateyIds = (cat $path | where { $_ }) 39 | $chocolateyIds | %{ cinstm $_ } 40 | 41 | 42 | 43 | 44 | import-module "$env:chocolateyinstall\chocolateyInstall\helpers\chocolateyInstaller.psm1" 45 | $helperDir = (Get-ChildItem $env:ChocolateyInstall\lib\boxstarter.helpers*) 46 | if($helperDir.Count -gt 1){$helperDir = $helperDir[-1]} 47 | import-module $helperDir\boxstarter.helpers.psm1 48 | 49 | Set-ExplorerOptions -showHidenFilesFoldersDrives -showProtectedOSFiles -showFileExtensions 50 | 51 | Install-ChocolateyPinnedTaskBarItem (Find-Program "Google\Chrome\Application\chrome.exe") 52 | Install-ChocolateyPinnedTaskBarItem "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe" 53 | 54 | Install-ChocolateyFileAssociation ".txt" "$editorOfChoice" 55 | Install-ChocolateyFileAssociation ".dll" "$env:ChocolateyInstall\bin\dotPeek.bat" 56 | 57 | Enable-RemoteDesktop 58 | 59 | 60 | 61 | 62 | if(!(where.exe git)){ 63 | #Why is git not on the PATH? 64 | 65 | $gitPath = 'C:\Program Files\git\bin' 66 | if(!(test-path $gitPath)){ 67 | $gitPath = 'C:\Program Files (x86)\Git\bin' 68 | } 69 | 70 | if(test-path "$gitPath\git.exe"){ 71 | $env:Path += ";$gitPath" 72 | } 73 | else{ 74 | throw "could not find git, rest of setup not going to execute..." 75 | return; 76 | } 77 | } 78 | 79 | git config --global user.email jason@elegantcode.com 80 | git config --global user.name 'Jason Jarrett' 81 | git config --global color.status.changed "cyan normal bold" 82 | git config --global color.status.untracked "cyan normal bold" 83 | 84 | # configure git diff and merge if p4merge was installed 85 | if($chocolateyIds -match 'p4merge') { 86 | git config --global merge.tool p4merge 87 | git config --global mergetool.p4merge.cmd 'p4merge.exe \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"' 88 | git config --global mergetool.prompt false 89 | 90 | git config --global diff.tool p4merge 91 | git config --global difftool.p4merge.cmd 'p4merge.exe \"$LOCAL\" \"$REMOTE\"' 92 | } 93 | 94 | # setup local powershell profile. 95 | iex ((new-object net.webclient).DownloadString('https://raw.github.com/staxmanade/DevMachineSetup/master/Bootstrap/initPsProfile.ps1')) 96 | 97 | 98 | Install-WindowsUpdate -AcceptEulaInstall-WindowsUpdate -AcceptEula 99 | -------------------------------------------------------------------------------- /GlobalScripts/Change-Directory.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Internal-Change-Directory($cmd, $ShowCount){ 3 | 4 | if(!$ShowCount) { 5 | $ShowCount = 10; 6 | } 7 | 8 | if(!$global:CD_COMMAND_HISTORY_LIST) { 9 | $global:CD_COMMAND_HISTORY_LIST = New-Object 'System.Collections.Generic.List[string]' 10 | } 11 | 12 | function Set-CDLocation($newLocation) { 13 | $newLocation = get-item $newLocation; 14 | $global:CD_COMMAND_HISTORY_LIST.Add($newLocation) 15 | Push-Location $newLocation 16 | } 17 | 18 | function Get-CommandList() { 19 | $global:CD_COMMAND_HISTORY_LIST | sort -Unique 20 | } 21 | 22 | function Print-Extended-CD-Menu() { 23 | $index = 1; 24 | foreach($location in Get-CommandList){ 25 | Write-Host ("{0,6}) {1}" -f $index, $location) 26 | $index++ 27 | if($index -gt $ShowCount){ 28 | break; 29 | } 30 | } 31 | } 32 | 33 | switch($cmd) { 34 | "" { Print-Extended-CD-Menu } 35 | "?" { Print-Extended-CD-Menu } 36 | "--help" { Print-Extended-CD-Menu } 37 | "-" { 38 | if($global:CD_COMMAND_HISTORY_LIST.Count -ge 2) { 39 | Set-CDLocation ($global:CD_COMMAND_HISTORY_LIST[$global:CD_COMMAND_HISTORY_LIST.Count-2]) 40 | } 41 | } 42 | default { 43 | 44 | $newLocation = $cmd; 45 | 46 | # Turn "cd ...." into "cd ../../../" 47 | if ($newLocation -match "^\.*$" -and $newLocation.length -gt 2) { 48 | $numberToChange = $newLocation.length - 1 49 | $newLocation = "" 50 | for($i = 0; $i -lt $numberToChange; $i++) { 51 | $newLocation += "../" 52 | } 53 | } 54 | 55 | 56 | # check to see if we're using a number command and get the correct directory. 57 | [int]$cdIndex = 0; 58 | if([system.int32]::TryParse($cmd, [ref]$cdIndex)) { 59 | 60 | # Don't pull from the history if the index value is the same as a folder name 61 | if( !(test-path $cdIndex) ) { 62 | $results = (Get-CommandList); 63 | if( ($results | measure).Count -eq 1 ){ 64 | $newLocation = $results 65 | } 66 | else { 67 | $newLocation = $results[$cdIndex-1] 68 | } 69 | } 70 | } 71 | 72 | #If we are actually changing the dir. 73 | if($pwd.Path -ne $newLocation){ 74 | 75 | # if the path exists 76 | if( test-path $newLocation ){ 77 | 78 | # if it's a file - get the file's directory. 79 | if( !(Get-Item $newLocation -Force).PSIsContainer ) { 80 | $newLocation = (split-path $newLocation) 81 | } 82 | 83 | Set-CDLocation $newLocation 84 | } 85 | else { 86 | if($force) { 87 | $prompt = 'y' 88 | } 89 | else { 90 | $prompt = Read-Host "Folder not found. Create it? [y/n]" 91 | } 92 | 93 | if($prompt -eq 'y' -or $prompt -eq 'yes') { 94 | mkdir $newLocation 95 | Set-CDLocation $newLocation 96 | } 97 | } 98 | } 99 | } 100 | } 101 | } 102 | 103 | Internal-Change-Directory -cmd $cmd -ShowCount $ShowCount 104 | 105 | # allow typing `..` to go up 1 dir or `....` to go up 3 dirs 106 | function ..() { cd .. } 107 | function ...() { cd ... } 108 | function ....() { cd .... } 109 | function .....() { cd ..... } 110 | function ......() { cd ...... } 111 | function .......() { cd ....... } 112 | function ........() { cd ........ } 113 | 114 | Set-Alias -Name cd -Value Internal-Change-Directory -Option AllScope 115 | -------------------------------------------------------------------------------- /GlobalScripts/Get-WebFile.ps1: -------------------------------------------------------------------------------- 1 | 2 | ## Get-WebFile (aka wget for PowerShell) 3 | ############################################################################################################## 4 | ## Downloads a file or page from the web 5 | ## History: 6 | ## v3.6 - Add -Passthru switch to output TEXT files 7 | ## v3.5 - Add -Quiet switch to turn off the progress reports ... 8 | ## v3.4 - Add progress report for files which don't report size 9 | ## v3.3 - Add progress report for files which report their size 10 | ## v3.2 - Use the pure Stream object because StreamWriter is based on TextWriter: 11 | ## it was messing up binary files, and making mistakes with extended characters in text 12 | ## v3.1 - Unwrap the filename when it has quotes around it 13 | ## v3 - rewritten completely using HttpWebRequest + HttpWebResponse to figure out the file name, if possible 14 | ## v2 - adds a ton of parsing to make the output pretty 15 | ## added measuring the scripts involved in the command, (uses Tokenizer) 16 | ############################################################################################################## 17 | function Get-WebFile { 18 | param( 19 | $url = (Read-Host "The URL to download"), 20 | $fileName = $null, 21 | [switch]$Passthru, 22 | [switch]$quiet 23 | ) 24 | 25 | $req = [System.Net.HttpWebRequest]::Create($url); 26 | $res = $req.GetResponse(); 27 | 28 | if($fileName -and !(Split-Path $fileName)) { 29 | $fileName = Join-Path (Get-Location -PSProvider "FileSystem") $fileName 30 | } 31 | elseif((!$Passthru -and ($fileName -eq $null)) -or (($fileName -ne $null) -and (Test-Path -PathType "Container" $fileName))) 32 | { 33 | [string]$fileName = ([regex]'(?i)filename=(.*)$').Match( $res.Headers["Content-Disposition"] ).Groups[1].Value 34 | $fileName = $fileName.trim("\/""'") 35 | if(!$fileName) { 36 | $fileName = $res.ResponseUri.Segments[-1] 37 | $fileName = $fileName.trim("\/") 38 | if(!$fileName) { 39 | $fileName = Read-Host "Please provide a file name" 40 | } 41 | $fileName = $fileName.trim("\/") 42 | if(!([IO.FileInfo]$fileName).Extension) { 43 | $fileName = $fileName + "." + $res.ContentType.Split(";")[0].Split("/")[1] 44 | } 45 | } 46 | $fileName = Join-Path (Get-Location -PSProvider "FileSystem") $fileName 47 | } 48 | if($Passthru) { 49 | $encoding = [System.Text.Encoding]::GetEncoding( $res.CharacterSet ) 50 | [string]$output = "" 51 | } 52 | 53 | if($res.StatusCode -eq 200) { 54 | [int]$goal = $res.ContentLength 55 | $reader = $res.GetResponseStream() 56 | if($fileName) { 57 | $writer = new-object System.IO.FileStream $fileName, "Create" 58 | } 59 | [byte[]]$buffer = new-object byte[] 4096 60 | [int]$total = [int]$count = 0 61 | do 62 | { 63 | $count = $reader.Read($buffer, 0, $buffer.Length); 64 | if($fileName) { 65 | $writer.Write($buffer, 0, $count); 66 | } 67 | if($Passthru){ 68 | $output += $encoding.GetString($buffer,0,$count) 69 | } elseif(!$quiet) { 70 | $total += $count 71 | if($goal -gt 0) { 72 | Write-Progress "Downloading $url" "Saving $total of $goal" -id 0 -percentComplete (($total/$goal)*100) 73 | } else { 74 | Write-Progress "Downloading $url" "Saving $total bytes..." -id 0 75 | } 76 | } 77 | } while ($count -gt 0) 78 | 79 | $reader.Close() 80 | if($fileName) { 81 | $writer.Flush() 82 | $writer.Close() 83 | } 84 | if($Passthru){ 85 | $output 86 | } 87 | } 88 | $res.Close(); 89 | if($fileName) { 90 | ls $fileName 91 | } 92 | } 93 | #set-alias wget Get-WebFile 94 | --------------------------------------------------------------------------------