Skip to content

Instantly share code, notes, and snippets.

Chris Duck gpduck

Block or report user

Report or block gpduck

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gpduck
gpduck / readme.md
Last active Jun 18, 2018
Ansible on Windows over SSH
View readme.md

Windows

  • Install OpenSSH
  • For domain user on 7.7+ (all lower case): AllowUsers domain\user
  • For local user (all lower case): AllowUsers user
  • run-as user to create profile (or log-in)
  • create .ssh and authorized_keys in the user's profile
  • run the fix user key script (program files\openssh)

Ansible

@gpduck
gpduck / TrimTCX.ps1
Created May 23, 2017
Trim a TCX file from Garmin
View TrimTCX.ps1
$InPath = "c:\activity.tcx"
$OutPath = "c:\activity_trimmed.tcx"
$x = [xml](get-content $InPath)
$x.TrainingCenterDatabase.activities.Activity | %{
$Activity = $_
$Activity.lap | %{
$Lap = $_
$lap.track | %{
$Track = $_
@gpduck
gpduck / default.ps1
Created Apr 12, 2017
PSake Build Script
View default.ps1
Properties {
if(!$OutDir) {
$OutDir = "out"
}
if(!$ProjectDir) {
$ProjectDir = $PSake.build_script_dir
}
if(!$TargetDir) {
$TargetDir = Join-Path -Path $ProjectDir -ChildPath $OutDir
}
@gpduck
gpduck / gist:fd4c2a14b56c18dcbfc0fa13662742a7
Last active Apr 9, 2017
I made a wrapper for your .Net method calls so you can test...
View gist:fd4c2a14b56c18dcbfc0fa13662742a7
[System.AppDomain]::CurrentDomain.GetAssemblies().ExportedTypes | %{
$Type = $_
$Type.GetMethods() | Select -Unique Name | %{
$Method = $_
$Name = "Invoke-{0}.{1}" -f $Type.Fullname, $Method.Name
@"
@gpduck
gpduck / Errors.ps1
Created Mar 7, 2017
PowerShell Errors
View Errors.ps1
$Error.Clear()
Try {
Get-Process fsdks -ErrorAction Stop
} Catch {
Write-Error "Couldn't find the process"
}
#Prints out the error "Couldn't find the process"
#This contains 2 objects, the "Couldn't find the process" error, and the original error from Get-Process
View gist:1cdc1c7c1083da829ac6e7b0268f9c6e
$RemoteComputer = "remotecomputer"
Invoke-Command -Computer $RemoteComputer -ScriptBlock { import-module bitstransfer; get-module bitstransfer; }
$S = New-PSSession -Computer $RemoteComputer
Invoke-Command -Session $S -ScriptBlock { Import-Module bitstransfer}
Invoke-Command -Session $S -ScriptBlock { get-Module bitstransfer}
Remove-PSSession $S
View Collections.md

The PowerShell pipeline unwraps collections. Let's write a function to test to see if something is a collection

function Test-Collection {
  param(
    [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
    $InputObject
  )
  process {
     $InputObject -is [System.Collections.ICollection]
View ValueFromPipeline.md

The whole point of using ValueFromPipeline (and ValueFromPipelineByPropertyName) is to replace this syntax:

"c:\windows","c:\Program Files" | ForEach-Object {
  Get-DirectoryFileSize -Directory $_
}

With this synax:

View GraphViz
function New-Node {
[OutputType("Whatsupduck.Powershell.GraphViz.Node")]
param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String]$Name,
[Parameter(Mandatory=$false)]
@gpduck
gpduck / CarCdr.ps1
Created Aug 12, 2015
Powershell CAR and CDR
View CarCdr.ps1
function car {
[CmdletBinding(DefaultParameterSetName='DefaultParameter', HelpUri='http://go.microsoft.com/fwlink/?LinkID=113387', RemotingCapability='None')]
param(
[Parameter(ValueFromPipeline=$true)]
[psobject]
${InputObject},
[Parameter(ParameterSetName='SkipLastParameter', Position=0)]
[Parameter(ParameterSetName='DefaultParameter', Position=0)]
[System.Object[]]
You can’t perform that action at this time.