cloud/modules/_oobe.psm1

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
<#
.SYNOPSIS
    OSDCloud Cloud Module for functions.osdcloud.com
.DESCRIPTION
    OSDCloud Cloud Module for functions.osdcloud.com
.NOTES
    This module is designed for OOBE
.LINK
    https://raw.githubusercontent.com/OSDeploy/OSD/master/cloud/modules/_oobe.psm1
.EXAMPLE
    Invoke-Expression (Invoke-RestMethod -Uri 'https://raw.githubusercontent.com/OSDeploy/OSD/master/cloud/modules/_oobe.psm1')
#>

#=================================================
#region Functions
function osdcloud-SetWindowsDateTime {
    [CmdletBinding()]
    param ()
    Write-Host -ForegroundColor Yellow 'Verify the Date and Time is set properly including the Time Zone'
    Write-Host -ForegroundColor Yellow 'If this is not configured properly, Certificates and Domain Join may fail'
    Start-Process 'ms-settings:dateandtime' | Out-Null
    $ProcessId = (Get-Process -Name 'SystemSettings').Id
    if ($ProcessId) {
        Wait-Process $ProcessId
    }
}
function osdcloud-SetWindowsDisplay {
    [CmdletBinding()]
    param ()
    Write-Host -ForegroundColor Yellow 'Verify the Display Resolution and Scale is set properly'
    Start-Process 'ms-settings:display' | Out-Null
    $ProcessId = (Get-Process -Name 'SystemSettings').Id
    if ($ProcessId) {
        Wait-Process $ProcessId
    }
}
function osdcloud-SetWindowsLanguage {
    [CmdletBinding()]
    param ()
    Write-Host -ForegroundColor Yellow 'Verify the Language, Region, and Keyboard are set properly'
    Start-Process 'ms-settings:regionlanguage' | Out-Null
    $ProcessId = (Get-Process -Name 'SystemSettings').Id
    if ($ProcessId) {
        Wait-Process $ProcessId
    }
}
function osdcloud-AutopilotRegisterCommand {
    [CmdletBinding()]
    param (
        [System.String]
        $Command = 'Get-WindowsAutopilotInfo -Online -Assign'
    )
    Write-Host -ForegroundColor Cyan 'Registering Device in Autopilot in new PowerShell window ' -NoNewline
    $AutopilotProcess = Start-Process PowerShell.exe -ArgumentList "-Command $Command" -PassThru
    Write-Host -ForegroundColor Green "(Process Id $($AutopilotProcess.Id))"
    Return $AutopilotProcess
}
function osdcloud-AddCapability {
    [CmdletBinding(DefaultParameterSetName='Default')]
    param (
        [Parameter(Mandatory,ParameterSetName='ByName',Position=0)]
        [System.String[]]$Name
    )
    if ($Name) {
        #Do Nothing
    }
    else {
        $Name = Get-WindowsCapability -Online -ErrorAction SilentlyContinue | Where-Object {$_.State -ne 'Installed'} | Select-Object Name | Out-GridView -PassThru -Title 'Select one or more Capabilities' | Select-Object -ExpandProperty Name
    }
    if ($Name) {
        Write-Host -ForegroundColor Cyan "Add-WindowsCapability -Online"
        foreach ($Item in $Name) {
            $WindowsCapability = Get-WindowsCapability -Online -Name "*$Item*" -ErrorAction SilentlyContinue | Where-Object {$_.State -ne 'Installed'}
            if ($WindowsCapability) {
                foreach ($Capability in $WindowsCapability) {
                    Write-Host -ForegroundColor DarkGray $Capability.DisplayName
                    $Capability | Add-WindowsCapability -Online | Out-Null
                }
            }
        }
    }
}
New-Alias -Name 'AddCapability' -Value 'osdcloud-AddCapability' -Description 'OSDCloud' -Force
function osdcloud-NetFX {
    [CmdletBinding()]
    param ()
    $WindowsCapability = Get-WindowsCapability -Online -Name "*NetFX*" -ErrorAction SilentlyContinue | Where-Object {$_.State -ne 'Installed'}
    if ($WindowsCapability) {
        Write-Host -ForegroundColor Cyan "Add-WindowsCapability NetFX"
        foreach ($Capability in $WindowsCapability) {
            Write-Host -ForegroundColor DarkGray $Capability.DisplayName
            $Capability | Add-WindowsCapability -Online | Out-Null
        }
    }
}
New-Alias -Name 'NetFX' -Value 'osdcloud-NetFX' -Description 'OSDCloud' -Force
function osdcloud-Rsat {
    [CmdletBinding(DefaultParameterSetName='Default')]
    param (
        [Parameter(Mandatory,ParameterSetName='Basic')]
        [System.Management.Automation.SwitchParameter]$Basic,

        [Parameter(Mandatory,ParameterSetName='Full')]
        [System.Management.Automation.SwitchParameter]$Full,

        [Parameter(Mandatory,ParameterSetName='ByName',Position=0)]
        [System.String[]]$Name
    )
    if ($Basic) {
        $Name = @('ActiveDirectory','BitLocker','GroupPolicy','RemoteDesktop','VolumeActivation')
    }
    elseif ($Full) {
        $Name = 'Rsat'
    }
    elseif ($Name) {
        #Do Nothing
    }
    else {
        $Name = Get-WindowsCapability -Online -Name "*Rsat*" -ErrorAction SilentlyContinue | `
        Where-Object {$_.State -ne 'Installed'} | `
        Select-Object Name, DisplayName, Description | `
        Out-GridView -PassThru -Title 'Select one or more Rsat Capabilities to install' | `
        Select-Object -ExpandProperty Name
    }
    if ($Name) {
        Write-Host -ForegroundColor Cyan "Add-WindowsCapability -Online Rsat"
        foreach ($Item in $Name) {
            $WindowsCapability = Get-WindowsCapability -Online -Name "*$Item*" -ErrorAction SilentlyContinue | Where-Object {$_.State -ne 'Installed'}
            if ($WindowsCapability) {
                foreach ($Capability in $WindowsCapability) {
                    Write-Host -ForegroundColor DarkGray $Capability.DisplayName
                    $Capability | Add-WindowsCapability -Online | Out-Null
                }
            }
        }
    }
}
New-Alias -Name 'Rsat' -Value 'osdcloud-Rsat' -Description 'OSDCloud' -Force
function osdcloud-UpdateDrivers {
    [CmdletBinding()]
    param ()
    Write-Host -ForegroundColor Cyan 'Updating Windows Drivers in a minimized window'
    if (!(Get-Module PSWindowsUpdate -ListAvailable -ErrorAction Ignore)) {
        try {
            Install-Module PSWindowsUpdate -Force -Scope CurrentUser -SkipPublisherCheck
            Import-Module PSWindowsUpdate -Force -Scope Global
        }
        catch {
            Write-Warning 'Unable to install PSWindowsUpdate Driver Updates'
        }
    }
    if (Get-Module PSWindowsUpdate -ListAvailable -ErrorAction Ignore) {
        Start-Process -WindowStyle Minimized PowerShell.exe -ArgumentList "-Command Install-WindowsUpdate -UpdateType Driver -AcceptAll -IgnoreReboot" -Wait
    }
}
New-Alias -Name 'UpdateDrivers' -Value 'osdcloud-UpdateDrivers' -Description 'OSDCloud' -Force
function osdcloud-UpdateWindows {
    [CmdletBinding()]
    param ()
    Write-Host -ForegroundColor Cyan 'Updating Windows in a minimized window'
    if (!(Get-Module PSWindowsUpdate -ListAvailable)) {
        try {
            Install-Module PSWindowsUpdate -Force -Scope CurrentUser -SkipPublisherCheck
            Import-Module PSWindowsUpdate -Force -Scope Global
        }
        catch {
            Write-Warning 'Unable to install PSWindowsUpdate Windows Updates'
        }
    }
    if (Get-Module PSWindowsUpdate -ListAvailable -ErrorAction Ignore) {
        #Write-Host -ForegroundColor DarkGray 'Add-WUServiceManager -MicrosoftUpdate -Confirm:$false'
        Add-WUServiceManager -MicrosoftUpdate -Confirm:$false | Out-Null
        #Write-Host -ForegroundColor DarkGray 'Install-WindowsUpdate -UpdateType Software -AcceptAll -IgnoreReboot'
        #Install-WindowsUpdate -UpdateType Software -AcceptAll -IgnoreReboot -NotTitle 'Malicious'
        #Write-Host -ForegroundColor DarkGray 'Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -IgnoreReboot'
        Start-Process -WindowStyle Minimized PowerShell.exe -ArgumentList "-Command Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -IgnoreReboot -NotTitle 'Preview' -NotKBArticleID 'KB890830','KB5005463','KB4481252'" -Wait
    }
}
New-Alias -Name 'UpdateWindows' -Value 'osdcloud-UpdateWindows' -Description 'OSDCloud' -Force
#endregion
#=================================================