forked from OSDeploy/OSD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OSD.psm1
99 lines (92 loc) · 6.53 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
90
91
92
93
94
95
96
97
98
99
$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 Clear-LocalDisk -Value Clear-Disk.fixed -Force -ErrorAction SilentlyContinue
New-Alias -Name Clear-USBDisk -Value Clear-Disk.usb -Force -ErrorAction SilentlyContinue
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-OSDCloud.winpe -Value Edit-OSDCloudWinPE -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-LocalDisk -Value Get-Disk.fixed -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-LocalPartition -Value Get-Partition.fixed -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-LocalVolume -Value Get-Volume.fixed -Force -ErrorAction SilentlyContinue
#New-Alias -Name Get-OSDCloud.template -Value Get-OSDCloudTemplate -Force -ErrorAction SilentlyContinue
#New-Alias -Name Get-OSDCloud.workspace -Value Get-OSDCloudWorkspace -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-OSDDisk -Value Get-Disk.osd -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-OSDPartition -Value Get-Partition.osd -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-OSDSessions -Value Get-SessionsXml -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-OSDVolume -Value Get-Volume.osd -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-USBDisk -Value Get-Disk.usb -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-USBPartition -Value Get-Partition.usb -Force -ErrorAction SilentlyContinue
New-Alias -Name Get-USBVolume -Value Get-Volume.usb -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 New-OSDBoot.usb -Value New-Bootable.usb -Force -ErrorAction SilentlyContinue
#New-Alias -Name New-OSDCloud.iso -Value New-OSDCloudISO -Force -ErrorAction SilentlyContinue
#New-Alias -Name New-OSDCloud.template -Value New-OSDCloudTemplate -Force -ErrorAction SilentlyContinue
#New-Alias -Name New-OSDCloud.usb -Value New-OSDCloudUSB -Force -ErrorAction SilentlyContinue
#New-Alias -Name New-OSDCloud.workspace -Value New-OSDCloudWorkspace -Force -ErrorAction SilentlyContinue
#New-Alias -Name Save-OSDCloud.usb -Value Update-OSDCloudUSB -Force -ErrorAction SilentlyContinue
#New-Alias -Name Save-OSDCloudDriverPack.usb -Value Update-OSDCloudUSB -Force -ErrorAction SilentlyContinue
New-Alias -Name Select-USBDisk -Value Select-Disk.usb -Force -ErrorAction SilentlyContinue
New-Alias -Name Select-USBVolume -Value Select-Volume.usb -Force -ErrorAction SilentlyContinue
#New-Alias -Name Set-OSDCloud.workspace -Value Set-OSDCloudWorkspace -Force -ErrorAction SilentlyContinue
#New-Alias -Name Update-OSDCloud.usb -Value Update-OSDCloudUSB -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
#=================================================
#Export-ModuleMember
Export-ModuleMember -Function * -Alias *
# Get module strings
$Global:OSDModuleResource = Get-ModuleResource