-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-cloudinit_disc.ps1
50 lines (47 loc) · 1.32 KB
/
create-cloudinit_disc.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
$ErrorActionPreference = "Stop"
$GuestAdminPassword = "P@ssw0rd"
$path = 'c:\temp'
$work = Join-Path $path -ChildPath 'work'
$oscd_path = Join-Path $path -ChildPath 'oscdimg.exe'
$unc_path = '\\nas1.magiccityit.com\os_iso\oscdimg.exe'
$metadata_iso = Join-Path $path -ChildPath 'metadata.iso'
try{
if (!(Test-Path $oscd_path)){
cp $unc_path $oscd_path -Verbose
}
if (Test-Path $metadata_iso){
Remove-Item $metadata_iso -Force
}
}
catch{
exit 1
}
$metadata = @"
instance-id: $((get-vm -Name $env:vm_name).VMId)
local-hostname: $($env:vm_name)
"@
$userdata = @"
#cloud-config
password: $($GuestAdminPassword)
runcmd:
- [ useradd, -m, -p, "", magicadmin ]
- [ chage, -d, 0, magicadmin ]
"@
try{
if (!(Test-Path $work)){
md $work -Verbose
}
if (Test-Path "$($work)\meta-data"){
rm "$($work)\meta-data"
}
if (Test-Path "$($work)\user-data"){
rm "$($work)\user-data"
}
sc "$($work)\meta-data" ([byte[]][char[]] "$metadata") -Encoding Byte -Verbose
sc "$($work)\user-data" ([byte[]][char[]] "$userdata") -Encoding Byte -Verbose
Start-Process $oscd_path -ArgumentList $work,$metadata_iso,"-j2 -lcidata" -Wait -Verbose
Add-VMDvdDrive -VMName $env:vm_name -Path $metadata_iso -Verbose
}
catch{
exit 1
}