forked from cloudbase/windows-imaging-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirstLogon.ps1
72 lines (62 loc) · 2.88 KB
/
FirstLogon.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
$ErrorActionPreference = "Stop"
function getVirtioDriversFolder(){
$architectureMapping = @{}
$architectureMapping['32-bit']='X86'
$architectureMapping['64-bit']='AMD64'
$osVersionMapping = @{}
$osVersionMapping[0]='VISTA'
$osVersionMapping[1]='WIN7'
$osVersionMapping[2]='WIN8'
$osVersionMapping[3]='WIN8'
$osArchitecture = (Get-WmiObject Win32_OperatingSystem).OSArchitecture
$archFolder = $architectureMapping[$osArchitecture]
$osVersion = [int]::Parse((Get-WmiObject Win32_OperatingSystem).Version[2])
$versionFolder = $osVersionMapping[$osVersion]
if (! $versionFolder) { throw "Unsupported Windows version" }
$virtIOPath = Join-Path -Path $versionFolder -ChildPath $archFolder
$drive = (gwmi Win32_CDROMDrive | where {(Test-Path (join-path -Path $_.Drive -ChildPath $virtIOPath ))}).Drive
if (! $drive) { throw "VirtIO drivers not found" }
return join-path -Path $drive -ChildPath $virtIOPath | join-path -ChildPath "*.inf"
}
$logonScriptPath = "$ENV:SystemRoot\Temp\Logon.ps1"
try
{
$Host.UI.RawUI.WindowTitle = "Downloading Logon script..."
$baseUrl = "https://raw.github.com/cloudbase/windows-openstack-imaging-tools/master"
(new-object System.Net.WebClient).DownloadFile("$baseUrl/Logon.ps1", $logonScriptPath)
$virtPlatform = (gwmi Win32_ComputerSystem).Model
Write-Host "Virtual platform: $virtPlatform"
# TODO: Add XenServer / XCP
switch($virtPlatform)
{
"VMware Virtual Platform"
{
# Note: this command will generate a reboot.
# "/qn REBOOT=ReallySuppress" does not seem to work properly
$Host.UI.RawUI.WindowTitle = "Installing VMware tools..."
E:\setup64.exe `/s `/v `/qn `/l `"$ENV:Temp\vmware_tools_install.log`"
if (!$?) { throw "VMware tools setup failed" }
}
{($_ -eq "KVM") -or ($_ -eq "Bochs")}
{
$Host.UI.RawUI.WindowTitle = "Downloading VirtIO drivers script..."
$virtioScriptPath = "$ENV:Temp\InstallVirtIODrivers.js"
$url = "https://raw.github.com/cloudbase/windows-openstack-imaging-tools/master/InstallVirtIODrivers.js"
(new-object System.Net.WebClient).DownloadFile($url, $virtioScriptPath)
$virtioDriversPath = getVirtioDriversFolder
Write-Host "Installing VirtIO drivers from: $virtioDriversPath"
& cscript $virtioScriptPath $virtioDriversPath
if (!$?) { throw "InstallVirtIO failed" }
del $virtioScriptPath
shutdown /r /t 0
}
}
}
catch
{
$host.ui.WriteErrorLine($_.Exception.ToString())
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
# Prevents the setup from proceeding
if ( Test-Path $logonScriptPath ) { del $logonScriptPath }
throw
}