Get-PublicOSDrivers.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<#
.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/18/2018
 VERSION:    1.1.0.2
#>


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
        }
    }
}