-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlserver2.ps1
More file actions
61 lines (46 loc) · 1.69 KB
/
Copy pathsqlserver2.ps1
File metadata and controls
61 lines (46 loc) · 1.69 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
function New-PowerLabSqlServer {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Name,
[Parameter(Mandatory)]
[pscredential]$DomainCredential,
[Parameter(Mandatory)]
[pscredential]$VMCredential,
[Parameter()]
[string]$VMPath = 'C:\PowerLab\VMs',
[Parameter()]
[int64]$Memory = 4GB,
[Parameter()]
[string]$Switch = 'PowerLab',
[Parameter()]
[int]$Generation = 2,
[Parameter()]
[string]$DomainName = 'powerlab.local',
[Parameter()]
[string]$AnswerFilePath = "C:\Program Files\WindowsPowerShell\Modules\PowerLab\SqlServer.ini"
)
## Build the VM
$vmParams = @{
Name = $Name
Path = $VmPath
Memory = $Memory
Switch = $Switch
Generation = $Generation
}
New-PowerLabVm @vmParams
Install-PowerLabOperatingSystem -VmName $Name
Start-VM -Name $Name
Wait-Server -Name $Name -Status Online -Credential $VMCredential
$addParams = @{
DomainName = $DomainName
Credential = $DomainCredential
Restart = $true
Force = $true
}
Invoke-Command -VMName $Name -ScriptBlock { Add-Computer @using:addParams } -Credential $VMCredential
Wait-Server -Name $Name -Status Offline -Credential $VMCredential
Wait-Server -Name $Name -Status Online -Credential $DomainCredential
$tempFile = Copy-Item -Path $AnswerFilePath -Destination "C:\Program Files\WindowsPowerShell\Modules\PowerLab\temp.ini" -PassThru
Install-PowerLabSqlServer -ComputerName $Name -AnswerFilePath $tempFile.FullName -DomainCredential $DomainCredential
}