forked from OSDeploy/OSD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OSD.psm1
89 lines (81 loc) · 5.46 KB
/
OSD.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
$Classes = @(Get-ChildItem -Path "$PSScriptRoot\Classes\*.ps1")
$Private = @(Get-ChildItem -Path "$PSScriptRoot\Private\*.ps1" -Recurse -ErrorAction SilentlyContinue)
#Determine the current state of the OS
$ImageState = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State' -ErrorAction Ignore).ImageState
#Can't load these functions in Specialize Phase
if ($ImageState -eq 'IMAGE_STATE_SPECIALIZE_RESEAL_TO_OOBE') {
$Public = @(Get-ChildItem -Path ("$PSScriptRoot\Public\*.ps1") -Recurse -ErrorAction SilentlyContinue | Where-Object {$_.Name -notmatch 'ScreenPNG'} | Where-Object {$_.Name -notmatch 'Clipboard'})
foreach ($Import in @($Public + $Private)) {
Try {. $Import.FullName}
Catch {Write-Error -Message "Failed to import function $($Import.FullName): $_"}
}
}
else {
#MSCatalog
try {
if (!([System.Management.Automation.PSTypeName]'HtmlAgilityPack.HtmlDocument').Type) {
if ($PSVersionTable.PSEdition -eq "Desktop") {
Add-Type -Path "$PSScriptRoot\Types\Net45\HtmlAgilityPack.dll"
} else {
Add-Type -Path "$PSScriptRoot\Types\netstandard2.0\HtmlAgilityPack.dll"
}
}
} catch {
$Err = $_
throw $Err
}
$Public = @(Get-ChildItem -Path ("$PSScriptRoot\Public\*.ps1") -Recurse -ErrorAction SilentlyContinue)
foreach ($Import in @($Public + $Private + $Classes)) {
Try {. $Import.FullName}
Catch {Write-Error -Message "Failed to import function $($Import.FullName): $_"}
}
}
Export-ModuleMember -Function $Public.BaseName
#=================================================
#WinPE
if ($env:SystemDrive -eq 'X:') {
[System.Environment]::SetEnvironmentVariable('APPDATA', (Join-Path $env:USERPROFILE 'AppData\Roaming'),[System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('HOMEDRIVE', $env:SystemDrive,[System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('HOMEPATH', (($env:USERPROFILE) -split ":")[1],[System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('LOCALAPPDATA', (Join-Path $env:USERPROFILE 'AppData\Local'),[System.EnvironmentVariableTarget]::Machine)
$VolatileEnvironment = "HKCU:\Volatile Environment"
if (-NOT (Test-Path -Path $VolatileEnvironment)) {
New-Item -Path $VolatileEnvironment -Force
New-ItemProperty -Path $VolatileEnvironment -Name "APPDATA" -Value (Join-Path $env:USERPROFILE 'AppData\Roaming') -Force
New-ItemProperty -Path $VolatileEnvironment -Name "HOMEDRIVE" -Value $env:SystemDrive -Force
New-ItemProperty -Path $VolatileEnvironment -Name "HOMEPATH" -Value (($env:USERPROFILE) -split ":")[1] -Force
New-ItemProperty -Path $VolatileEnvironment -Name "LOCALAPPDATA" -Value (Join-Path $env:USERPROFILE 'AppData\Local') -Force
}
}
#=================================================
#Alias
New-Alias -Name Copy-ModuleToFolder -Value Copy-PSModuleToFolder -Force -ErrorAction SilentlyContinue
New-Alias -Name Dismount-WindowsImageOSD -Value Dismount-MyWindowsImage -Force -ErrorAction SilentlyContinue
New-Alias -Name Edit-ADKwinpe.wim -Value Edit-AdkWinPEWIM -Force -ErrorAction SilentlyContinue
New-Alias -Name Edit-WindowsImageOSD -Value Edit-MyWindowsImage -Force -ErrorAction SilentlyContinue
New-Alias -Name Find-InOSDModule -Value Find-TextInModule -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-OSDSessions -Value Get-SessionsXml -Force -ErrorAction SilentlyContinue
New-Alias -Name Mount-OSDWindowsImage -Value Mount-MyWindowsImage -Force -ErrorAction SilentlyContinue
New-Alias -Name Mount-WindowsImageOSD -Value Mount-MyWindowsImage -Force -ErrorAction SilentlyContinue
New-Alias -Name New-ADK.iso -Value New-AdkISO -Force -ErrorAction SilentlyContinue
New-Alias -Name Update-OSDWindowsImage -Value Update-MyWindowsImage -Force -ErrorAction SilentlyContinue
New-Alias -Name Update-WindowsImageOSD -Value Update-MyWindowsImage -Force -ErrorAction SilentlyContinue
New-Alias -Name Clear-Disk.usb -Value Clear-USBDisk -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-Disk.fixed -Value Get-LocalDisk -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-Partition.fixed -Value Get-LocalDiskPartition -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-Partition.osd -Value Get-OSDPartition -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-Disk.osd -Value Get-OSDDisk -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-Volume.fixed -Value Get-LocalDiskVolume -Force -ErrorAction SilentlyContinue
New-Alias -Name Clear-Disk.fixed -Value Clear-LocalDisk -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-Volume.osd -Value Get-OSDVolume -Force -ErrorAction SilentlyContinue
New-Alias -Name New-Bootable.usb -Value New-BootableUSBDrive -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-Partition.usb -Value Get-USBPartition -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-Volume.usb -Value Get-USBVolume -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-Disk.usb -Value Get-USBDisk -Force -ErrorAction SilentlyContinue
New-Alias -Name Select-Disk.usb -Value Invoke-SelectUSBDisk -Force -ErrorAction SilentlyContinue
New-Alias -Name Select-Volume.usb -Value Invoke-SelectUSBVolume -Force -ErrorAction SilentlyContinue
#=================================================
#Export-ModuleMember
Export-ModuleMember -Function * -Alias *
# Get module strings
$Global:OSDModuleResource = Get-ModuleResource