Skip to content

Instantly share code, notes, and snippets.

View RhysC's full-sized avatar

Rhys Campbell RhysC

  • Perth; Australia
View GitHub Profile
@RhysC
RhysC / MachineAudit.ps1
Created February 28, 2011 23:17
Retrieve details for the machine
#Audit script
$auditFile = "audit.txt"
$computername = "." #i.e local machine
"Computer name $computername" > $auditFile
"Computer details:" >> $auditFile
get-wmiobject Win32_ComputerSystem -computername $computername |
select Name, Manufacturer, Model,`
NumberOfProcessors, TotalPhysicalMemory, `
@RhysC
RhysC / VersionTest.ps1
Created March 1, 2011 15:14
Tests is versions are greater
#Version checks
#Version type
function Test-VersionIsGreaterThanOrEqualTo()
{
param ([string] $versionA, [string] $versionB)
"versionA $versionA"
"versionB $versionB"
$version1 = New-Version $versionA
@RhysC
RhysC / GetProjectSummarys.ps1
Created March 2, 2011 12:43
Recursively Gets the code quality details from the csroj files
$projectSummarys = @{}
Get-ChildItem -exclude '*Test*' -Recurse -Include *.csproj |
Where-Object {$_.Attributes -ne "Directory"} |
%{
$filename = $_.FullName
$proj = [xml](get-Content $filename);
$projectSummarys[$filename] = ($proj.Project.PropertyGroup)|select -Skip 1 -First 1 |
select WarningLevel, CodeAnalysisRuleSet, RunCodeAnalysis, TreatWarningsAsErrors
}
@RhysC
RhysC / GetUniqueSvnExternsRecursive.ps1
Created March 18, 2011 15:58
Get the svn externs for all folder and provide a distinct list
#Get the svn externs for all folders and provide a distinct list
$svnDirectory="c:\sg\programfiles\svn\1.6.6.40053" #NOTE : put your svn path here
$svnExe="$svnDirectory\svn.exe"
$externs = & $svnExe propget svn:externals -R
$externs | sort | Get-Unique >> DistinctSvnExternal.txt #Raw file
$uniqueDependencies = @{};
$externs | sort | Get-Unique |
@RhysC
RhysC / TestHelpers.Random.cs
Created March 19, 2011 15:37
Provides random values for simple types
public static class Random
{
private static readonly System.Random rand = new System.Random();
public static int Int(int maxValue = int.MaxValue)
{
return rand.Next(maxValue);
}
public static bool Bool()
{
@RhysC
RhysC / PerfCounterSample.cs
Created April 4, 2011 10:37
Linq Pad CPU usage C# program sample
void Main()
{
var instanceName = "LINQPad";
var counterCollectionInterval = TimeSpan.FromSeconds(1);
var continueCollectingTimeFrame = TimeSpan.FromSeconds(10);
var counters = from performanceCounterDefinition in PerformanceCounterRepository.GetPerfCounters
from counterName in performanceCounterDefinition.Counters
select new {
@RhysC
RhysC / StartStopNirvanaServices.ps1
Created April 13, 2011 13:21
Start or stop all my nirvana services
function Stop-Nirvana{
Get-Service |
Where {($_.Name -like "*nirvana*") -and ($_.Status -ne "Stopped")} |
Stop-Service
}
function Start-Nirvana{
Get-Service |
Where {($_.Name -like "*nirvana*") -and ($_.Status -eq "Stopped")} |
Start-Service
@RhysC
RhysC / ConfigTemplateSwitcher.ps1
Created May 5, 2011 10:47
handles swapping out templated values in configs from nested prop files
#config swapper
#load the default values in to a hash
#get the values from the env and override in the hash
#foreach key in the hash replace the {[key]} with the value i.e. (Get-Content $_) -replace "$tokenedKey","$value" | Set-Content -path $_.$env
function Create-ConfigFromTemplate{
param ([string]$envPropFile, #".\$env.properties"
[string]$outputFolder,#".\$env\
[string]$templateFile #".\App.template.config"
)
@RhysC
RhysC / GetChildFolderTotalSize.Ps1
Created July 18, 2011 20:00
Get all the immediate children folders and tell me their total size
function Get-ChildFolderTotalSize
{
param($parentDir)
$children = (Get-ChildItem $parentDir | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)
$results = @();
foreach ($i in $children)
{
$childSum = (Get-ChildItem $i.FullName -recurse | Measure-Object -property length -sum)
$results += New-Object Object |
@RhysC
RhysC / Helpers.ps1
Created August 1, 2011 09:38
String and file helpers
function Select-UniqueChildrenWithStringPattern {
param($path, $pattern)
Get-ChildItem $path -Recurse |
Select-String -Pattern $pattern |
Select-Object Path |
Get-Unique
}
function String-ReplaceRecursive {
param($path, $pattern, $replaceValue)