Skip to content

Instantly share code, notes, and snippets.

@jamiekt
Last active April 21, 2018 14:51
Show Gist options
  • Save jamiekt/1dbd0c3350bc32e04705 to your computer and use it in GitHub Desktop.
Save jamiekt/1dbd0c3350bc32e04705 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>6CAFC0C6-A428-4d30-A9F9-700E829FEA51</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>MyApplication</RootNamespace>
<AssemblyName>MyApplication</AssemblyName>
<Name>POSHProfile</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup />
<ItemGroup>
<Compile Include="powershellprofile.ps1" />
<Compile Include="profile.ps1" />
<Compile Include="sign.bat" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="Build" />
</Project>

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F5034706-568F-408A-B7B3-4D38C6DB8A32}") = "POSHProfile", "POSHProfile.pssproj", "{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<#
To run this every time you open a Powershell session pop the latest version of this:
https://gist.github.com/jamiekt/1dbd0c3350bc32e04705#file-profile-ps1
into your Powershell profile
#>
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
<#
.SYNOPSIS
Converts files to the given encoding.
Matches the include pattern recursively under the given path.
.EXAMPLE
Convert-FileEncoding -Include *.js -Path scripts -Encoding UTF8
#>
function Convert-FileEncoding([string]$Include, [string]$Path, [string]$Encoding='UTF8') {
$count = 0
Get-ChildItem -Include $Pattern -Recurse -Path $Path `
| select FullName, @{n='Encoding';e={Get-FileEncoding $_.FullName}} `
| where {$_.Encoding -ne $Encoding} `
| % { (Get-Content $_.FullName) `
| Out-File $_.FullName -Encoding $Encoding; $count++; }
Write-Host "$count $Pattern file(s) converted to $Encoding in $Path."
}
# http://franckrichard.blogspot.com/2010/08/powershell-get-encoding-file-type.html
<#
.SYNOPSIS
Gets file encoding.
.DESCRIPTION
The Get-FileEncoding function determines encoding by looking at Byte Order Mark (BOM).
Based on port of C# code from http://www.west-wind.com/Weblog/posts/197245.aspx
.EXAMPLE
Get-ChildItem *.ps1 | select FullName, @{n='Encoding';e={Get-FileEncoding $_.FullName}} | where {$_.Encoding -ne 'ASCII'}
This command gets ps1 files in current directory where encoding is not ASCII
.EXAMPLE
Get-ChildItem *.ps1 | select FullName, @{n='Encoding';e={Get-FileEncoding $_.FullName}} | where {$_.Encoding -ne 'ASCII'} | foreach {(get-content $_.FullName) | set-content $_.FullName -Encoding ASCII}
Same as previous example but fixes encoding using set-content
# Modified by F.RICHARD August 2010
# add comment + more BOM
# http://unicode.org/faq/utf_bom.html
# http://en.wikipedia.org/wiki/Byte_order_mark
#
# Do this next line before or add function in Profile.ps1
# Import-Module .\Get-FileEncoding.ps1
#>
function Get-FileEncoding
{
[CmdletBinding()]
Param (
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
[string]$Path
)
[byte[]]$byte = get-content -Encoding byte -ReadCount 4 -TotalCount 4 -Path $Path
#Write-Host Bytes: $byte[0] $byte[1] $byte[2] $byte[3]
# EF BB BF (UTF8)
if ( $byte[0] -eq 0xef -and $byte[1] -eq 0xbb -and $byte[2] -eq 0xbf )
{ Write-Output 'UTF8' }
# FE FF (UTF-16 Big-Endian)
elseif ($byte[0] -eq 0xfe -and $byte[1] -eq 0xff)
{ Write-Output 'Unicode UTF-16 Big-Endian' }
# FF FE (UTF-16 Little-Endian)
elseif ($byte[0] -eq 0xff -and $byte[1] -eq 0xfe)
{ Write-Output 'Unicode UTF-16 Little-Endian' }
# 00 00 FE FF (UTF32 Big-Endian)
elseif ($byte[0] -eq 0 -and $byte[1] -eq 0 -and $byte[2] -eq 0xfe -and $byte[3] -eq 0xff)
{ Write-Output 'UTF32 Big-Endian' }
# FE FF 00 00 (UTF32 Little-Endian)
elseif ($byte[0] -eq 0xfe -and $byte[1] -eq 0xff -and $byte[2] -eq 0 -and $byte[3] -eq 0)
{ Write-Output 'UTF32 Little-Endian' }
# 2B 2F 76 (38 | 38 | 2B | 2F)
elseif ($byte[0] -eq 0x2b -and $byte[1] -eq 0x2f -and $byte[2] -eq 0x76 -and ($byte[3] -eq 0x38 -or $byte[3] -eq 0x39 -or $byte[3] -eq 0x2b -or $byte[3] -eq 0x2f) )
{ Write-Output 'UTF7'}
# F7 64 4C (UTF-1)
elseif ( $byte[0] -eq 0xf7 -and $byte[1] -eq 0x64 -and $byte[2] -eq 0x4c )
{ Write-Output 'UTF-1' }
# DD 73 66 73 (UTF-EBCDIC)
elseif ($byte[0] -eq 0xdd -and $byte[1] -eq 0x73 -and $byte[2] -eq 0x66 -and $byte[3] -eq 0x73)
{ Write-Output 'UTF-EBCDIC' }
# 0E FE FF (SCSU)
elseif ( $byte[0] -eq 0x0e -and $byte[1] -eq 0xfe -and $byte[2] -eq 0xff )
{ Write-Output 'SCSU' }
# FB EE 28 (BOCU-1)
elseif ( $byte[0] -eq 0xfb -and $byte[1] -eq 0xee -and $byte[2] -eq 0x28 )
{ Write-Output 'BOCU-1' }
# 84 31 95 33 (GB-18030)
elseif ($byte[0] -eq 0x84 -and $byte[1] -eq 0x31 -and $byte[2] -eq 0x95 -and $byte[3] -eq 0x33)
{ Write-Output 'GB-18030' }
else
{ Write-Output 'ASCII' }
}
# SIG # Begin signature block
# MIIFuQYJKoZIhvcNAQcCoIIFqjCCBaYCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUtTBifYXvztqP5OH3zHyBwOeN
# 7oCgggNCMIIDPjCCAiqgAwIBAgIQunABiSkP5ohGHMwHEB9BmjAJBgUrDgMCHQUA
# MCwxKjAoBgNVBAMTIVBvd2VyU2hlbGwgTG9jYWwgQ2VydGlmaWNhdGUgUm9vdDAe
# Fw0xNTA3MDIwODAyNDJaFw0zOTEyMzEyMzU5NTlaMBoxGDAWBgNVBAMTD1Bvd2V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hoFAKB4MBgGCisGAQQBgjcCAQwxCjAIoAKAAKECgAAwGQYJ
# KoZIhvcNAQkDMQwGCisGAQQBgjcCAQQwHAYKKwYBBAGCNwIBCzEOMAwGCisGAQQB
# gjcCARUwIwYJKoZIhvcNAQkEMRYEFNy8owNRYdu6vLaGZSWr0Y8LrzPQMA0GCSqG
# SIb3DQEBAQUABIIBAJxOYSrfSTMlEzMJZKTosxMoKNXsFyBH7xmhMpyOFWGDPc4y
# O2r4cW2Lnbj/TpM1PO7ERYFeDJmebS/fPEBnFm/5XRKjAUyrj68ZFICtelnBkuGp
# TuCtxBiy2WgYKPfxEQLtDaZzLSsNAaN0RhUsrK8sUFoxbeX1XqU9HFUDHTrvzL2c
# yiFJuvGfu5J33DEDs11bUjiM2PhToexn4SKK+TxhqhNQNhs9SGabVkffHZeSI/v0
# ZIxQjww7SByjiytrM6MVUiEQ3UddVUrv42cykA5huMJJHRlc002CXbRzs6FS7t0L
# RYBEGkEXu+XusJoYs+iWh02fN3hC9/Znhtyqmxk=
# SIG # End signature block
<#
To download an up-to-date profile every time you open Powershell pop the code below into your Powershell profile.
The script that it downloads and executes can be seen at https://gist.github.com/jamiekt/1dbd0c3350bc32e04705#file-powershellprofile-ps1
To edit your Powershell profile enter the following into Powershell:
if(-not (test-path $profile)) {new-item $profile -Type File -Force}; notepad $profile
At some point may need to incorporate the script shown here: https://github.com/dahlbyk/posh-git/issues/161 if
posh-git isn't displaying repo info in the prompt.
#>
$clnt = new-object System.Net.WebClient
#$url = "https://gist.githubusercontent.com/jamiekt/1dbd0c3350bc32e04705/raw/3a8a40eb0512c39da24920ea9f58d10f694a21a7/powershellprofile.ps1"
#$url = "https://gist.githubusercontent.com/jamiekt/1dbd0c3350bc32e04705/raw/85b42bb70b28f4f1df471f311b89e473d25ceeb2/powershellprofile.ps1"
#$url = "https://gist.githubusercontent.com/jamiekt/1dbd0c3350bc32e04705/raw/dd610c1ac8044ee84c5e2262f3d8073baa68c933/powershellprofile.ps1"
$url = "https://gist.githubusercontent.com/jamiekt/1dbd0c3350bc32e04705/raw/c92393c62a40ad2bb2cf8d3484ade81d9215c045/powershellprofile.ps1"
$folder = "c:\temp"
mkdir $folder -force
$infile = "$folder\inprofile.ps1"
$outfile = "$folder\outprofile.ps1"
$clnt.DownloadFile($url,$infile)
(gc $infile) | %{$_.split("`n")} | Out-File $outfile #replace LFs with CRLFs
. $outfile
# SIG # Begin signature block
# MIIFuQYJKoZIhvcNAQcCoIIFqjCCBaYCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUOVD5jAtzQcqljDdZwX1BFaa0
# hhmgggNCMIIDPjCCAiqgAwIBAgIQunABiSkP5ohGHMwHEB9BmjAJBgUrDgMCHQUA
# MCwxKjAoBgNVBAMTIVBvd2VyU2hlbGwgTG9jYWwgQ2VydGlmaWNhdGUgUm9vdDAe
# Fw0xNTA3MDIwODAyNDJaFw0zOTEyMzEyMzU5NTlaMBoxGDAWBgNVBAMTD1Bvd2Vy
# U2hlbGwgVXNlcjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKiVU7Vg
# sheFXyM3E+c6iN8fNWC8Al2iaovN9K0Pt5ZEuJw3qKoO2gSMys8l3dEzLYps7Cm2
# K41dGJdYnbZ2ViT8neXZ/psVGyNLbcgoyHJQxLOhdzEbmQROzPLORgRJIniKTd9e
# +rBEqBRyUwWIJuOR7n6/NL8MEDU33M19GINNfMyur5zHslrz0aq+cejdrVbOnrWI
# 4Z8YlyFRNCu23Iyv6jR85Vfcnsv8n8mM+mVu/wyGE3FYRLtgMffnZ7prm8k+77mS
# kHSHDKHjDE3VAmO8iTWkKS3pwf24Yt769KWVATB7XccLmXSlXEFdo4zIupFIlU3a
# n9sIVciqDQaebP0CAwEAAaN2MHQwEwYDVR0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tX8
# ep94SicZ7ZrJKTuC7BAkivFdFMOo0wCdZnuuMHBT8xxhMdvAHn6tHhj78UVhk7ky
# qyEeEBeOHnqFSo0lhpNmqoyka8dxLwO0fN5clOg=
# SIG # End signature block
rem You might have to ruin this signing script from a developer command prompt (so that it knows where makecert.exe is) and also elevated (can't remember why)
powershell.exe -NoProfile -command "$certs = Get-ChildItem cert:\CurrentUser\My -codesign | ?{$_.Subject -match 'PowerShell User'}; if ($certs -eq $null ){ exit 1};"
echo. %ERRORLEVEL%
if %ERRORLEVEL% == 0 goto SIGNSCRIPTS
PUSHD C:\Windows\system32
makecert -n "CN=PowerShell Local Certificate Root" -a sha1 -eku 1.3.6.1.5.5.7.3.3 -r -sv root.pvk root.cer -ss Root -sr localMachine
makecert -pe -n "CN=PowerShell User" -ss MY -a sha1 -eku 1.3.6.1.5.5.7.3.3 -iv root.pvk -ic root.cer
POPD
:SIGNSCRIPTS
powershell.exe -NoProfile -command "Get-ChildItem .\ -Recurse | Where-Object {$_.Extension -eq '.ps1'} | foreach { Set-AuthenticodeSignature $_.Fullname @(Get-ChildItem cert:\CurrentUser\My -codesign | ?{$_.Subject -match 'PowerShell User'})[0]}"
powershell.exe -NoProfile -command "Get-ChildItem .\ -Recurse | Where-Object {$_.Extension -eq '.psm1'} | foreach { Set-AuthenticodeSignature $_.Fullname @(Get-ChildItem cert:\CurrentUser\My -codesign | ?{$_.Subject -match 'PowerShell User'})[0]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment