Get-PublicOSDrivers.ps1

<#
.LINK
    https://www.osdeploy.com/psmodule/osdrivers/
.SYNOPSIS
    Downloads OSDrivers from Amazon S3 Storage
    Requires PowerShell Module AWSPowerShell
    Install-Module -Name AWSPowerShell
.DESCRIPTION
    Downloads OSDrivers from Amazon S3 Storage
    Requires PowerShell Module AWSPowerShell
    Install-Module -Name AWSPowerShell
.PARAMETER DownloadPath
    Local Directory where OSDrivers will be downloaded to
.PARAMETER WindowsProfile
    Filters an Operating System and Architecture for Driver Compatibility
.PARAMETER AWSAccessKey
    Amazon AWS Access Key for Public OSDrivers Authentication
.PARAMETER AWSSecretKey
    Amazon AWS Secret Key for Public OSDrivers Authentication
.PARAMETER PublicCore
    Select Public\Core* Drivers to Download
.PARAMETER PublicDell
    Select Public\Dell* Drivers to Download
.PARAMETER PublicHP
    Select Public\HP* Drivers to Download
.PARAMETER PublicLenovo
    Select Public\Lenovo* Drivers to Download
.PARAMETER PublicVideo
    Select Public\Video* Drivers to Download
.EXAMPLE
    Get-PublicOSDrivers -DownloadPath C:\DeploymentShare\OSDrivers -WindowsProfile "Win10 x64" -PublicCore -PublicVideo
    Downloads from AWS OSDrivers for Win10 x64 Public Core and Public Video to C:\DeploymentShare\OSDrivers
.EXAMPLE
    Get-PublicOSDrivers -DownloadPath C:\DeploymentShare\OSDrivers -WindowsProfile "Win10 x64" -PublicDell
    Downloads from AWS OSDrivers for Win10 x64 Public Dell to C:\DeploymentShare\OSDrivers
.NOTES
    NAME: Get-PublicOSDrivers.ps1
    AUTHOR: David Segura, david@segura.org
    BLOG: http://www.osdeploy.com
    CREATED: 02/17/2018
    VERSION: 1.1.0.1
#>


function Get-PublicOSDrivers
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory=$True)]
        [string]$DownloadPath,
        [Parameter(Mandatory=$True)]
        [ValidateSet('Win10 x64', 'Win10 x86', 'Win7 x64', 'Win7 x86', 'All Operating Systems', 'All x64', 'All x86')]
        [string]$WindowsProfile,
        [string]$AWSAccessKey,
        [string]$AWSSecretKey,
        [switch]$PublicCore,
        [switch]$PublicDell,
        [switch]$PublicHP,
        [switch]$PublicLenovo,
        [switch]$PublicVideo
    )

    $S3Bucket = "osdrivers-public"
    $AWSregion = "us-east-2"

    #Copy OSDrivers.vbs
    Copy-S3Object -BucketName $S3Bucket -Key "OSDrivers.vbs" -LocalFile ($DownloadPath + "\OSDrivers.vbs") -Region $AWSregion -AccessKey $AWSAccessKey -SecretKey $AWSSecretKey
    
    if ($PublicCore) {
        #Set Bucket Name
        $S3Bucket = "osdrivers-public"
        
        #Connect to S3 Bucket
        $FilesPublicCore = Get-S3Object -BucketName $S3Bucket -Region $AWSregion -AccessKey $AWSAccessKey -SecretKey $AWSSecretKey
        
        #Select the Core Files
        $FilesPublicCore = $FilesPublicCore | Where-Object {$_.key -like 'Public/Core*'}
        
        #Filter the Operating System
        if ($WindowsProfile -like 'Win10*') {$FilesPublicCore = $FilesPublicCore | Where-Object {$_.key -notlike '*Win7*'}}
        if ($WindowsProfile -like 'Win7*') {$FilesPublicCore = $FilesPublicCore | Where-Object {$_.key -notlike '*Win10*'}}
        if ($WindowsProfile -like '*x64') {$FilesPublicCore = $FilesPublicCore | Where-Object {$_.key -notlike '*x86*'}}
        if ($WindowsProfile -like '*x86') {$FilesPublicCore = $FilesPublicCore | Where-Object {$_.key -notlike '*x64*'}}

        #Exclude Directories
        $FilesPublicCore = $FilesPublicCore | Where-Object {$_.size -ne 0}
        
        #Prompt for Download
        $FilesPublicCore = $FilesPublicCore | Select-Object -Property Key,Size,LastModified | Out-GridView -Title "OSDrivers Core: Select Drivers to Download" -PassThru
    }
    
    if ($PublicVideo) {
        #Set Bucket Name
        $S3Bucket = "osdrivers-public"
        
        #Connect to S3 Bucket
        $FilesPublicVideo = Get-S3Object -BucketName $S3Bucket -Region $AWSregion -AccessKey $AWSAccessKey -SecretKey $AWSSecretKey
        
        #Select the Video Files
        $FilesPublicVideo = $FilesPublicVideo | Where-Object {$_.key -like 'Public/Video*'}
        
        #Filter the Operating System
        if ($WindowsProfile -like 'Win10*') {$FilesPublicVideo = $FilesPublicVideo | Where-Object {$_.key -notlike '*Win7*'}}
        if ($WindowsProfile -like 'Win7*') {$FilesPublicVideo = $FilesPublicVideo | Where-Object {$_.key -notlike '*Win10*'}}
        if ($WindowsProfile -like '*x64') {$FilesPublicVideo = $FilesPublicVideo | Where-Object {$_.key -notlike '*x86*'}}
        if ($WindowsProfile -like '*x86') {$FilesPublicVideo = $FilesPublicVideo | Where-Object {$_.key -notlike '*x64*'}}

        #Exclude Directories
        $FilesPublicVideo = $FilesPublicVideo | Where-Object {$_.size -ne 0}
        
        #Prompt for Download
        $FilesPublicVideo = $FilesPublicVideo | Select-Object -Property Key,Size,LastModified | Out-GridView -Title "OSDrivers Video: Select Drivers to Download" -PassThru
    }
    
    if ($PublicDell) {
        #Set Bucket Name
        $S3Bucket = "osdrivers-public-dell"
        
        #Connect to S3 Bucket
        $FilesPublicDell = Get-S3Object -BucketName $S3Bucket -Region $AWSregion -AccessKey $AWSAccessKey -SecretKey $AWSSecretKey
        
        #Select the Dell Files
        $FilesPublicDell = $FilesPublicDell | Where-Object {$_.key -like 'Public/Dell*'}
        
        #Filter the Operating System
        if ($WindowsProfile -like 'Win10*') {$FilesPublicDell = $FilesPublicDell | Where-Object {$_.key -notlike '*Win7*'}}
        if ($WindowsProfile -like 'Win7*') {$FilesPublicDell = $FilesPublicDell | Where-Object {$_.key -notlike '*Win10*'}}
        if ($WindowsProfile -like '*x64') {$FilesPublicDell = $FilesPublicDell | Where-Object {$_.key -notlike '*x86*'}}
        if ($WindowsProfile -like '*x86') {$FilesPublicDell = $FilesPublicDell | Where-Object {$_.key -notlike '*x64*'}}

        #Exclude Directories
        $FilesPublicDell = $FilesPublicDell | Where-Object {$_.size -ne 0}
        
        #Prompt for Download
        $FilesPublicDell = $FilesPublicDell | Select-Object -Property Key,Size,LastModified | Out-GridView -Title "OSDrivers Dell: Select Drivers to Download" -PassThru
    }
    
    
    if ($PublicHP) {
        #Set Bucket Name
        $S3Bucket = "osdrivers-public-hp"
        
        #Connect to S3 Bucket
        $FilesPublicHP = Get-S3Object -BucketName $S3Bucket -Region $AWSregion -AccessKey $AWSAccessKey -SecretKey $AWSSecretKey
        
        #Select the HP Files
        $FilesPublicHP = $FilesPublicHP | Where-Object {$_.key -like 'Public/HP*'}
        
        #Filter the Operating System
        if ($WindowsProfile -like 'Win10*') {$FilesPublicHP = $FilesPublicHP | Where-Object {$_.key -notlike '*Win7*'}}
        if ($WindowsProfile -like 'Win7*') {$FilesPublicHP = $FilesPublicHP | Where-Object {$_.key -notlike '*Win10*'}}
        if ($WindowsProfile -like '*x64') {$FilesPublicHP = $FilesPublicHP | Where-Object {$_.key -notlike '*x86*'}}
        if ($WindowsProfile -like '*x86') {$FilesPublicHP = $FilesPublicHP | Where-Object {$_.key -notlike '*x64*'}}

        #Exclude Directories
        $FilesPublicHP = $FilesPublicHP | Where-Object {$_.size -ne 0}
        
        #Prompt for Download
        $FilesPublicHP = $FilesPublicHP | Select-Object -Property Key,Size,LastModified | Out-GridView -Title "OSDrivers HP: Select Drivers to Download" -PassThru
    }
    
    if ($PublicLenovo) {
        #Set Bucket Name
        $S3Bucket = "osdrivers-public-lenovo"
        
        #Connect to S3 Bucket
        $FilesPublicLenovo = Get-S3Object -BucketName $S3Bucket -Region $AWSregion -AccessKey $AWSAccessKey -SecretKey $AWSSecretKey
        
        #Select the Lenovo Files
        $FilesPublicLenovo = $FilesPublicLenovo | Where-Object {$_.key -like 'Public/Lenovo*'}
        
        #Filter the Operating System
        if ($WindowsProfile -like 'Win10*') {$FilesPublicLenovo = $FilesPublicLenovo | Where-Object {$_.key -notlike '*Win7*'}}
        if ($WindowsProfile -like 'Win7*') {$FilesPublicLenovo = $FilesPublicLenovo | Where-Object {$_.key -notlike '*Win10*'}}
        if ($WindowsProfile -like '*x64') {$FilesPublicLenovo = $FilesPublicLenovo | Where-Object {$_.key -notlike '*x86*'}}
        if ($WindowsProfile -like '*x86') {$FilesPublicLenovo = $FilesPublicLenovo | Where-Object {$_.key -notlike '*x64*'}}

        #Exclude Directories
        $FilesPublicLenovo = $FilesPublicLenovo | Where-Object {$_.size -ne 0}
        
        #Prompt for Download
        $FilesPublicLenovo = $FilesPublicLenovo | Select-Object -Property Key,Size,LastModified | Out-GridView -Title "OSDrivers Lenovo: Select Drivers to Download" -PassThru
    }
    
    #Copy the Files
    if ($PublicCore) {
        $S3Bucket = "osdrivers-public"
        foreach ($S3File in $FilesPublicCore) {
            Copy-S3Object -BucketName $S3Bucket -LocalFile ($DownloadPath + "\" + $S3File.Key) -Key $S3File.Key -Region $AWSregion -AccessKey $AWSAccessKey -SecretKey $AWSSecretKey
        }    
    }
    
    if ($PublicVideo) {
        $S3Bucket = "osdrivers-public"
        foreach ($S3File in $FilesPublicVideo) {
            Copy-S3Object -BucketName $S3Bucket -LocalFile ($DownloadPath + "\" + $S3File.Key) -Key $S3File.Key -Region $AWSregion -AccessKey $AWSAccessKey -SecretKey $AWSSecretKey
        }
    }
    
    if ($PublicDell) {
        $S3Bucket = "osdrivers-public-dell"
        foreach ($S3File in $FilesPublicDell) {
            Copy-S3Object -BucketName $S3Bucket -LocalFile ($DownloadPath + "\" + $S3File.Key) -Key $S3File.Key -Region $AWSregion -AccessKey $AWSAccessKey -SecretKey $AWSSecretKey
        }
    }
    
    if ($PublicHP) {
        $S3Bucket = "osdrivers-public-hp"
        foreach ($S3File in $FilesPublicDell) {
            Copy-S3Object -BucketName $S3Bucket -LocalFile ($DownloadPath + "\" + $S3File.Key) -Key $S3File.Key -Region $AWSregion -AccessKey $AWSAccessKey -SecretKey $AWSSecretKey
        }
    }
    
    if ($PublicLenovo) {
        $S3Bucket = "osdrivers-public-lenovo"
        foreach ($S3File in $FilesPublicDell) {
            Copy-S3Object -BucketName $S3Bucket -LocalFile ($DownloadPath + "\" + $S3File.Key) -Key $S3File.Key -Region $AWSregion -AccessKey $AWSAccessKey -SecretKey $AWSSecretKey
        }
    }
}