forked from AutomatedLab/AutomatedLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemp.txt
More file actions
119 lines (78 loc) · 3.64 KB
/
Temp.txt
File metadata and controls
119 lines (78 loc) · 3.64 KB
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
$hostOsVersion = [double](Get-CimInstance -ClassName Win32_OperatingSystem).Version.Substring(0,3)
$partitionStyle = 'MBR'
if ($hostOsVersion -ge 6.3 -and $availableOperatingSystem.Version -ge 6.2)
{
$partitionStyle = 'GPT'
}
New-LWReferenceVHDX -IsoOsPath $availableOperatingSystem.IsoPath `
-ReferenceVhdxPath $baseDiskPath `
-OsName $availableOperatingSystem.OperatingSystemName `
-SizeInGb $lab.Target.ReferenceDiskSizeInGB `
-PartitionStyle $partitionStyle
AL Troubleshooting Lab, Replace Machine with ComputerName
AL Worker has redundant functions
New-LWReferenceVHDX
Checkpoint-LWVM Move To VMWorker
Remove-LWVMSnapshot Move To VMWorker
Install-LWDHCP Move To ADDSWorker
VM Worker
Write-Verbose " $Computer has now restarted" to
Write-Verbose " $Computer has now restarted $((Get-Date).ToLongTimeString())"
VM Worker ~130
if ($Generation -eq 1)
{
Set-VMBios -VMName $Name -EnableNumLock
}
if ($Generation -eq 2)
{
Add-VMDvdDrive -VMName $Name
}
VMWorker ~65
Mount-DiskImage -ImagePath $path
$VhdDisk = Get-DiskImage -ImagePath $path | Get-Disk
$VhdPart = Get-Partition -DiskNumber $VhdDisk.Number | Where-Object { $_.Type -eq 'Basic' -or $_.IsActive }
New-VMSwitch -Name Prod -NetAdapterName ((Get-NetAdapter|? { $_.Status -eq "Up" -and $_.Virtual = $false)[0].Name)
Script for applying patches to a VHD:
http://gallery.technet.microsoft.com/scriptcenter/839ee6f0-196f-4ed7-ac55-8e753c5d5ebe
$patchingFolder = New-Item -Path c:\patching -ItemType Directory
$image = Mount-WindowsImage -ImagePath D:\Test2\WindowsServer2012Base.vhdx -Path c:\patching -Index 1
$updates = Get-ChildItem -Path D:\glb -Filter *.cab
$installedPackages = @()
foreach ($update in $updates)
{
$updateReady= Get-WindowsPackage -PackagePath $update.FullName -Path $patchingFolder
if ($updateReady.State -eq "Installed")
{
Write-Verbose "($($UpdateReady.Description) is already installed"
}
elseif ($updateReady.Applicable -eq $true)
{
$installedPackages += Add-WindowsPackage -PackagePath $update.FullName -Path $patchingFolder
}
}
Dismount-WindowsImage -Path $patchingFolder.FullName -Save
$patchingFolder | Remove-Item -Confirm:$false
------------------------------------------------------------------------------------------------------------------------------------------------
Function Install-MSU
{
param ($MSUFile, $RemoteComputer)
#Create local temp folder for updates
Remove-Item -Path "$($env:temp)\TempUpdates" -Recurse -EA 0
New-Item -ItemType Directory -Path "$($env:temp)\TempUpdates"
#Copy updates for VMs to the local temp folder for updates
Copy $MSUFile -Destination "$($env:temp)\TempUpdates"
New-Item -ItemType Directory -Path "$($env:temp)\TempUpdates\Extracted"
#Extract MSU file:
Expand -F:* "$($env:temp)\TempUpdates\$($MSUFile | split-path -leaf)" "$($env:temp)\TempUpdates\Extracted"
#Send the extracted files (the entire folder) to the client computer
$RemoteClient = New-PSSession -ComputerName $RemoteComputer -Credential $installationCredential
Send-Directory -Source "$($env:temp)\TempUpdates\Extracted" -Destination 'C:\Updates' -Session $RemoteClient
#Remotely start installation of Remote Server Administration Tools
$ScriptBlock= `
{
$CabFile = (Get-ChildItem -path C:\Updates\*.cab -Exclude WSUSSCAN.cab).fullname
Start-Process -FilePath 'DISM.exe' -ArgumentList "/Online /Add-Package /PackagePath:C:\Updates\$CabFile /NoRestart /Quiet" -Wait
Restart-Computer -Force
}
Invoke-Command -Session $RemoteClient -ScriptBlock $ScriptBlock
}