Putty.psm1

function Get-Putty
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$false, Position=0)]
        [string] $Uri = "http://the.earth.li/~sgtatham/putty/latest/x86/putty.zip",

        [Parameter(Mandatory=$false, Position=1)]
        [string] $Path = $env:TEMP
    )


    if(-not(Test-Path $Path -ErrorAction SilentlyContinue))
    {
        "$Path does not exist. This location will be created"  | Write-Verbose
        New-Item -ItemType Directory -Path $Path
    }

    $filename = $Uri.Substring($Uri.LastIndexOf("/") + 1)
    "Downloading $filename to $Path" | Write-Verbose

    Invoke-WebRequest -Uri $Uri -OutFile (Join-Path $Path $filename)
    Extract-Package -Source (Join-Path $Path $filename) -Target $Path

}

function Extract-Package
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$true, Position=0)]
        [ValidateNotNullOrEmpty()]
        [ValidateScript({ Test-Path $_})]
        [string] $Source,

        [Parameter(Mandatory=$true, Position=0)]
        [ValidateNotNullOrEmpty()]
        [string] $Target
    )
    

    $shell_app=new-object -com shell.application
    $filename = $Source.Substring($Source.LastIndexOf("\") + 1)
    $zip_file = $shell_app.namespace($Source)
    $destination = $shell_app.namespace($Target)
    $destination.Copyhere($zip_file.items())
}

Export-ModuleMember Get*