Skip to content

Instantly share code, notes, and snippets.

View jstangroome's full-sized avatar

Jason Stangroome jstangroome

View GitHub Profile
@jstangroome
jstangroome / Get-AbsolutePath.ps1
Created February 13, 2011 02:41
Converts relative paths to absolute paths but does not require the path to exist.
function Get-AbsolutePath {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string[]]
$Path
)
process {
$Path | ForEach-Object {
@jstangroome
jstangroome / TSSession.psm1
Created February 13, 2011 22:40
Basic PowerShell wrapper around command-line tools for querying and reseting Terminal Services sessions.
function Get-TSSession {
& query session |
Select-Object -Skip 1 |
ForEach-Object {
if ($_ -match '^(?<this>.)(?<sessionname>.{18})(?<username>.{22})(?<id>.{6})(?<state>.{8})(?<type>.{8})(?<device>.*)') {
New-Object -TypeName PSObject -Property @{
SessionName = $Matches.sessionname.TrimEnd()
UserName = $Matches.username.TrimEnd()
SessionId = [int]::Parse($Matches.id)
@jstangroome
jstangroome / RSPermission.ps1
Created February 15, 2011 02:59
Grant a role to a user on a Reporting Services item
$ReportServerUri = 'http://myreportserver/ReportServer/ReportService2005.asmx'
$InheritParent = $true
$ItemPath = '/SomeReportFolder'
$GroupUserName = 'MYDOMAIN\SomeUser'
$RoleName = 'SomeReportServerRoleToGrant'
$Proxy = New-WebServiceProxy -Uri $ReportServerUri -Namespace SSRS.ReportingService2005
$Policies = $Proxy.GetPolicies($ItemPath, [ref]$InheritParent)
# effectively this is VB's Option Strict On but for PowerShell
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$buildFile = "build\Build.proj"
# simulate the variable representing the folder this script is in (a PS Module would get this by default)
$PSScriptRoot = ($MyInvocation.MyCommand.Path | Split-Path | Resolve-Path).ProviderPath
# never pass relative paths outside your script
@jstangroome
jstangroome / gist:831310
Created February 17, 2011 08:36
Change the Quality of a build from a deployment in TFS Deployer 2010
$CollectionUrl = 'http://mytfs:8080/tfs/mycollection'
'.Client', '.Build.Client' | % {
Add-Type -AssemblyName "Microsoft.TeamFoundation$_, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
}
$Collection = New-Object -TypeName Microsoft.TeamFoundation.Client.TfsTeamProjectCollection -ArgumentList $CollectionUrl
$BuildServer = $Collection.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$LiveBuildDetail = $BuildServer.GetBuild($TfsDeployerBuildDetail.Uri)
@jstangroome
jstangroome / killscc.ps1
Created March 7, 2011 06:51 — forked from anonymous/killscc.ps1
Strip source control bindings from solution and project files
#requires -version 2.0
param (
[ValidateScript({$_ | Test-Path -PathType Container})]
[Parameter(Mandatory=$true)]
[string] $folder
)
function killScc(){
gci -path $folder -i *.vssscc,*.vspscc -recurse | Remove-Item -force -verbose
}
@jstangroome
jstangroome / CLR4PowerShell.psm1
Created March 23, 2011 02:51
Execute individual PowerShell v2 commands using .NET Framework CLR 4
function Invoke-CLR4PowerShellCommand {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[ScriptBlock]
$ScriptBlock,
[Parameter(ValueFromRemainingArguments=$true)]
[Alias('Args')]
[object[]]
@jstangroome
jstangroome / FailOnMoreWarnings.xaml
Created March 27, 2011 22:27
A snippet from an extended DefaultTemplate.xaml TFS 2010 Build Process Template for failing the build when the number of compile warnings increases.
<!-- Insert this Sequence as one of the last children of the Sequence with DisplayName="Compile and Test" -->
<Sequence>
<Sequence.Variables>
<Variable x:TypeArguments="mtbc:IBuildDetail" Name="LastBuildDetail" />
<Variable x:TypeArguments="x:Int32" Name="LastWarningCount" />
<Variable x:TypeArguments="x:Int32" Name="WarningCount" />
</Sequence.Variables>
<Assign x:TypeArguments="mtbc:IBuildDetail" To="[LastBuildDetail]" Value="[BuildDetail.BuildServer.GetBuild(BuildDetail.BuildDefinition.LastBuildUri)]" />
<Assign x:TypeArguments="x:Int32" To="[LastWarningCount]" Value="[Microsoft.TeamFoundation.Build.Client.InformationNodeConverters.GetBuildWarnings(LastBuildDetail).Count]" />
@jstangroome
jstangroome / Msi.psm1
Created April 11, 2011 04:43
Read the ProductVersion from a Windows Installer MSI file via PowerShell
function Get-MsiProductVersion {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[ValidateScript({$_ | Test-Path -PathType Leaf})]
[string]
$Path
)
@jstangroome
jstangroome / Select-UniqueObject.ps1
Created May 27, 2011 06:54
Streaming implementation of PowerShell's Select-Object -Unique
&{
1..7
4..9
} |
ForEach-Object -Begin {
$Unique = @{}
} -Process {
if (-not $Unique.ContainsKey($_)) {
$Unique.Add($_, $null)
$_