Batch Enable-VMReplication in PowerShell 3.0

hyper-v_replicaToday was the last day I user wizard Hyper-V to activate the VM replication .. Why? Since today i did something i should have done a long time ago.. I made a script for enable VM replication for all machines on one server. The script going to selecting all ”running” machines, that not have replication enabled at the moment. Happy POSH:ing!

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
 
$ReplicaServer = "LAB-HYPERV02"
$StartTime = "20:00"
$ReplicaServerPort  = 80
$ReplicaServerAuthType = "Kerberos"
$ReplicationFrequencySec = 15*60 # 15x60 equals 900 secunds = 15 minutes.
 
$InitialReplicationDelayMinutes = 30
$InitialReplicationStartTime = Get-Date $StartTime
 
$AutoResynchronizeIntervalStart = "18:30:00"
$AutoResynchronizeIntervalEnd = "06:00:00"
 
#$VMHostInfo = Get-VMHost -ComputerName $ReplicaServer
$ReplicaServerInfo = Get-VMReplicationServer -ComputerName $ReplicaServer
$ReplicaDestPath = $ReplicaServerInfo.DefaultStorageLocation
 
 
$VMs = Get-VM | ? { ($PSItem.ReplicationState -eq "Disabled") -AND ($PSItem.State -eq "Running")}
 
$VMsDiskSizeTotal = (($VMs | % { Get-VMHardDiskDrive -VMName $PSItem.Name | Get-VHD }) | measure -Property FileSize -Sum).Sum
$ReplicaServerDiskSizeFree = (Invoke-Command -ArgumentList $ReplicaDestPath -ScriptBlock {param($ReplicaDestPath) Get-Volume -DriveLetter $($ReplicaDestPath.Substring(0,1))} -ComputerName $ReplicaServer).SizeRemaining
 
 
 
#Check Diskspace before replication.
Write "Checking disk space on $ReplicaServer : $($VMsDiskSizeTotal/1TB) TB Selected for replication. $($ReplicaServerDiskSizeFree/1TB) TB Avalible on destination server"
if ( ($ReplicaServerDiskSizeFree) -AND ($VMsDiskSizeTotal -le $ReplicaServerDiskSizeFree) )
    {
 
    Write "Checking disk space avalible on $ReplicaServer"    
 
    foreach ($VM in $VMs)
        {
 
        Write "Enabeling VM Replication on VM $($VM.Vmname)"
 
        Enable-VMReplication `
            -VMName $VM.VMName `
            -ReplicaServerName $ReplicaServer `
            -ReplicaServerPort $ReplicaServerPort `
            -AuthenticationType $ReplicaServerAuthType `
            -ReplicationFrequencySec $ReplicationFrequencySec `
            -AutoResynchronizeEnabled $true `
            -AutoResynchronizeIntervalStart $AutoResynchronizeIntervalStart `
            -AutoResynchronizeIntervalEnd $AutoResynchronizeIntervalEnd `
            -CompressionEnabled $true `
            -RecoveryHistory 0 `
            -Confirm:$false
 
        Write "Enabeling Intitial Replication on  $($VM.VMname) at $InitialReplicationStartTime"
        Start-VMInitialReplication -VMName $VM.VMName -InitialReplicationStartTime $InitialReplicationStartTime
        $InitialReplicationStartTime = $InitialReplicationStartTime.AddMinutes($InitialReplicationDelayMinutes)
 
        # Debug
        #break
 
        }
    }
    else
        {
        Write "Checking disk space not avalible on $ReplicaServer . script failed."
        }
Posted in Hyper-V, Powershell | Leave a comment

Import-VMsFromFolder – Batch import VMs from folder in Hyper-V!

Ever needed to batch import VMs in Hyper-V based on a folder path? Here is the PowerShell solution for you!
(with some built-in error handling)

Disclaimer: This script is provided ”AS IS” with no warranties

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
<#
.Synopsis
   Import VMs to Hyper-V from path.
.EXAMPLE
   Import-VMsFromFolder -Path 'D:\VMs\Virtual Machines'
#>
 
function Import-VMsFromFolder
{
    [CmdletBinding()]
    Param
    (
        # Specify VM Path.
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        $Path
    )
 
    $VmConfigFiles = (Get-ChildItem -Path $Path -Filter *.xml).FullName    
    $ExistingVMs = (Get-VM).Name
 
    foreach ($VmConfigFile in $VmConfigFiles) {
 
        [xml]$VMXML = Get-Content $VmConfigFile
        $SelectedVM = $VMXML.configuration.properties.name.'#Text'
 
        if ($ExistingVMs -contains $SelectedVM) {
            Write "$SelectedVM - Already Imported"
        } 
            else {
                Write "$SelectedVM : Selecting from $path"
                $VMInfo = Compare-VM -Path $VmConfigFile
 
                if ($VMInfo.Incompatibilities) {
                    Write-Error "$SelectedVM - IMPORTRESULT: NOT IMPORTED : $($VMInfo.Incompatibilities.message)"
                } 
                    else {
                        Import-VM -Path $VmConfigFile -Verbose
                    }
            }      
    }
 
}
Posted in Hyper-V, Powershell | Leave a comment

Get-ADComputerLastLogon

Finding old computers in Active Directory can be a bit difficult at times, but it’s a necessary evil. I threw together a small PowerShell script to assist in the search. You’ll also find some examples of how it can be used.

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
function Get-ADComputerLastLogon {
[CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true)]
        [string] $OU
    )
 
# Query AD
Write-Verbose "Querying OU $OU"
$ADQueryComputers = Get-ADComputer -Filter * -SearchBase $OU -Properties Name, lastLogonTimestamp, operatingSystem
 
$ADComputerFinal=@()
Foreach ($ADQueryComputer in $ADQueryComputers) {
 
    # Set Vars
    $ComputerName = $ADQueryComputer.Name
    $ComputerOS = $ADQueryComputer.operatingSystem
    $ComputerLastLogin = [datetime]::FromFileTimeUtc($ADQueryComputer.lastLogonTimestamp)
    $ComputerLastLoginTimeInDays = $(((Get-Date) - $ComputerLastLogin).Days)
 
    # Add to Final Var
    $ADComputer = [pscustomobject]@{
        Computer = $ComputerName
        OS = $ComputerOS
        LastLogonDays = [int]$ComputerLastLoginTimeInDays
    }
 
    $ADComputerFinal += $ADComputer
}
$ADComputerFinal
}

Usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Set OU
$OU = "OU=Laptops,OU=Computers,OU=Company,DC=lab,DC=local"            
 
# Just list all computers and last logon time in $OU
Get-ADComputerLastLogon -OU $OU
 
# Get computer last logon time if it's more then 100 days.
Get-ADComputerLastLogon -OU $OU | Where-Object LastLogonDays -gt 100
 
# Get computer last logon time if it's less then 50 days.
Get-ADComputerLastLogon -OU $OU | Where-Object LastLogonDays -lt 50
 
# Get specific computer
Get-ADComputerLastLogon -OU $OU | Where-Object Computer -match "LAB-SRV001"
 
# Get all computers running Windows Enterprise Edition if last logon time is less then 100 days
Get-ADComputerLastLogon -OU $OU | Where-Object { $_.OS -Match "Enterprise" -AND $_.LastLogonDays -lt "100" }
 
# count all the computers that have not signed in on the last 100 days
(Get-ADComputerLastLogon -OU $OU | Where-Object LastLogonDays -gt 100).Count
Posted in Powershell | Leave a comment

Introducing unofficial PowerShell module for HP G6 Servers (Without iLo requirements)

Capture

My first thought of this project was to create an HP PowerShell module that was not depending on the HP iLo to run. The benefit of this would be to avoid having to deal autentiering of iLo to make simpler system checks on machines. This makes a big difference for people with HP G6 servers because the official HP PowerShell module ”only” supports iLo3 / 4.

So let me pressent PSHPQ which instead is entirely dependent on WMI to run.
Since the PSHPQ using HP-specific WMI namespace, you need to download the HP Insight Management WBEM Providers (cp016286) which includes these namespace.

Yes … there is still much to be desired here. But for the purpose of inventory and reporting in smaller and older environments it works great!

In the next article will hopefully explain more about the cmdlets themselves .. I will also try to give some examples of how I use it.

Download-PSHPQ

Posted in Powershell | Leave a comment

Restore-HostVmReplication Check all VMs replicationstatus and restores them

140205

Okaay.. So i made a small script to restore VM replication (for all VMs on the host) if it’s in a failed state. And for some reasons, sometimes they are..

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
Function Restore-HostVmReplication {
    [CmdletBinding()]
    param()
 
Write-Verbose "Importing Hyper-V Module"
Import-Module Hyper-V -verbose:$false
 
$VmReplicationError = Get-VMReplication | ? Health -NE "Normal"
 
    If ($VmReplicationError) {
        Write-Verbose "VM Replication error was found"
 
        Foreach ($VM in $VmReplicationError) {
            Write-Verbose "Trying to restore VM Replication on $($VM.Name)"
            Resume-VMReplication -VMName $VM.Name
 
            if (Get-VMReplication -VMName $VM.Name | Where-Object Health -EQ "Normal") {
                Write-Verbose "VM Replicationstatus was restored to Normal on $($VM.Name)"
 
            } else {
                Write-Verbose "VM Replicationstatus was not restored to Normal on $($VM.Name)"
            }
        }
 
    } else {
        Write-Verbose "VM Replication is up and running on all VMs"
        }
 
}
1
2
# Example
Restore-HostVmReplication -Verbose
Posted in Hyper-V, Powershell | Leave a comment

Get-HPDiskAndArrayStatus – Hämta status på dina HP diskar, raid kontroller och maila dig om något är fel!

Dev 1.0

Satte ihop detta i helgen. Kan nog komma väl till pass för er som kör HP servrar och inte har fina dyra övervakningssystem på plats, men endå vill övervaka diskar och kontroller i era/kunders servrar.

Samt att få mail direkt när något går fel.
Det enda ni behöver göra är att ladda ner HP Insight Management WBEM Providers för er server för att få tillgång till HP’s WMI providers. För ML350 G6 t.ex. här (cp016286.exe)

Untitled

Hela scriptet finns att ladda ner här
Schemalägg sedan scriptet att köra en gång i timman, per dag eller vad ni nu vill.
Nästa funktion tänkte jag blir att maila varningar om diskarna varit aktiva i X antal dagar (3år = 1 095 dagar?), Vad tror ni om det? Kom gärna med ideer, feedback och önskemål!

Posted in IT Tips & Trix, Powershell | Leave a comment

Install-RemoteVM När du vill sitta lugnt på din stol och rulla ut VM’s till olika Hyper-V hostar. (WS12R2, MDT2013)

Install-RemoteVM är ett script för att rulla ut VM’s på olika Hyper-V hostar, remote, automatiserat och med kopplingar till AD, WDS och MDT/MDTDB. Riktar även ett stort tack till Micke Nyström för inspirationen jag hämtat från hans Out Of Band install of Windows Server 2012 R2 Using MDT,WDS and PowerShell inlägg och tillhörande script som gör de samma med fysiska HP servrar. Powershell is king :)

Finns att ladda ner här

Eller läsa här:

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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<#
 #############################################################################
 #  Created:	2014-01-02
 #  version:	v1.0
 #  Author:	Henrik Toft, inspired by the deploymentbunny...
 #  Homepage:	http://www.toft.se/
 #  Disclaimer:	This script is provided "AS IS" with no warranties
 #############################################################################
 #
 #
 ############################ EXAMPELS #######################################
 
# Example 1: Script is generating static VM Physical Address
Install-RemoteVM -VMName SRV133 -VMRam 2048MB -VMNetwork LAN -VMCpu 1 -VMDiskSize 100GB -VMHost LAB-VMHOST01 -MDTServer LAB-MDT01 -MDTDataBaseInstance ADK -MDTDataBase MDT -TaskSequence WS12R2-01
 
# Example 2: User specifies static VM Physical Address
Install-RemoteVM -VMName SRV134 -VMRam 2048MB -VMNetwork LAN -VMCpu 1 -VMDiskSize 100GB -VMMacAddress "00:15:5A:AA:AA:11" -VMHost LAB-VMHOST01 -MDTServer LAB-MDT01 -MDTDataBaseInstance ADK -MDTDataBase MDT -TaskSequence WS12R2-01
 
 #############################################################################
 #>
 
Function Install-RemoteVM{
        Param(
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$VMHost,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$VMName,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$VMRam,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$VMNetwork,
        [parameter(mandatory=$false)][ValidateNotNullOrEmpty()]$VMMacAddress,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$VMCpu,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$VMDiskSize,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$MDTServer,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$MDTDataBaseInstance,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$MDTDataBase,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$TaskSequence
        ) 
 
        ## Check for Hyper-V PowerShell Module
        if ($(Get-WindowsFeature Hyper-V-PowerShell).InstallState -like "Available") {Install-WindowsFeature Hyper-V-PowerShell -Verbose}
 
        ## Check if VM exist
        $VM = Get-VM $VMName -ComputerName $VmHost -ErrorAction SilentlyContinue
        if ($VM) {
            Write-Verbose "$VMName already exist..." -Verbose
            break
            }
 
        ## Define New-PhysicalAddress Function
        Function New-PhysicalAddress{
        param(
        [int] $len = 12,
        [string] $chars = "0123456789ABCFEF"
        )
        $bytes = new-object "System.Byte[]" $len
        $rnd = new-object System.Security.Cryptography.RNGCryptoServiceProvider
        $rnd.GetBytes($bytes)
        $macraw = ""
        for( $i=0; $i -lt $len; $i++ ) {$macraw += $chars[ $bytes[$i] % $chars.Length ]}
        $PhysicalAddress = "0"+"0"+":"+"1"+"5"+":"+$macraw[4]+$macraw[5]+":"+$macraw[6]+$macraw[7]+":"+$macraw[8]+$macraw[9]+":"+$macraw[10]+$macraw[11]
        Write-Output $PhysicalAddress
        }
 
        ## Import modules
        try {Import-Module "C:\Scripts\MDTDB.psm1" -ErrorAction Stop} catch {Write-Warning "Error occured: $_"}
        try {Import-Module WDS -ErrorAction Stop} catch {Write-Warning "Error occured: $_"}
 
        ## Check if script static mac or user static mac should be used.
        if ($VMMacAddress) {Write-Host "Static MacAddress: $VMMacAddress was specified by user"}
            else {
            $VMMacAddress = New-PhysicalAddress
            Write-Host "Static MacAddress: $VMMacAddress was specified by script"            }
 
        # Create VM
        $VmVhdLocation = (Get-VmHost -ComputerName $VmHost).VirtualHardDiskPath
        New-VHD -ComputerName $VmHost –Path "$VmVhdLocation\$($VMName).vhdx" -SizeBytes $VMDiskSize -Verbose
        New-VM -ComputerName $VmHost –Name $VMName –MemoryStartupBytes $VMRam –VHDPath "$VmVhdLocation\$($VMName).vhdx" -SwitchName $VMNetwork -Generation 2 -Verbose
        Set-VM -ComputerName $VmHost -VmName $VMName -DynamicMemory -ProcessorCount $VMCpu -MemoryMaximumBytes $VMRam -Verbose
        Set-VMNetworkAdapter -ComputerName $VmHost -VMName $VMName -StaticMacAddress $VMMacAddress -Verbose
        Write-Verbose "VM $VMName was created" -Verbose
 
        # Get/Set Vars
        $VMidGuid = $(Get-Vm $vmname -ComputerName $VMHost).Id
        $VMidMac = $VMMacAddress -replace ':','-'        
 
        # Print Vars
        Write-Host "VMHost = $VMHost"
        Write-Host "VMName = $VMName"
        Write-Host "VMRam = $VMRam"
        Write-Host "VMNetwork = $VMNetwork"
        Write-Host "VMMacAddress = $VMMacAddress"
        Write-Host "VMCpu Count = $VMCpu"
        Write-Host "VMDiskSize = $VMDiskSize"
        Write-Host "MDTServer = $MDTServer"
        Write-Host "MDTDataBaseInstance = $MDTDataBaseInstance"
        Write-Host "MDTDataBase = $MDTDataBase"
        Write-Host "TaskSequence = $TaskSequence"
        Write-Host "GUID = $VMidGuid"
        Write-Host "VmVhdLocation = $VmVhdLocation"
 
    # PreStage in WDS
    # note to self.. do something about this if if mess.. 
    $WDSComputer = Get-WdsClient -DeviceName $VMName
    if ($WDSComputer.DeviceName -EQ "$VMName"){
        Write-Host "$VMName was found in WDS. Checking MacAddress"
        if ($WDSComputer.DeviceID -Match "$VMidMac") {
        Write-Host "Prestaged in WDS. DeviceName and MacAddress are correct" -ForegroundColor Yellow
        }
        else{
            Write-Host "Reinstating in WDS, adding" -ForegroundColor Yellow
            Remove-WdsClient -DeviceName $VMName
            Sleep -Seconds 1
            New-WdsClient -DeviceID $VMidMac -DeviceName $VMName -PxePromptPolicy OptOut -BootImagePath "Boot\x64\Images\LiteTouchPE_x64.wim" -ErrorAction Stop -JoinDomain $false
            }
        }
    else
        {
        Write-Host "$VMname is not prestaged in WDS, adding"
        New-WdsClient -DeviceID $VMidMac -DeviceName $VMName -PxePromptPolicy OptOut -BootImagePath "Boot\x64\Images\LiteTouchPE_x64.wim" -ErrorAction Stop -JoinDomain $false
        }
 
    # Prestage in MDT
    connect-mdtdatabase -sqlserver $MDTServer -instance $MDTDataBaseInstance -database $MDTDataBase -Verbose
    $MDTComputerSettings = @{OSInstall='YES';OSDComputerName="$VMName";TaskSequenceID="$TaskSequence";SkipTaskSequence='YES';SkipComputerName='YES';SkipApplications='YES';SkipDomainMembership='YES'}
    Write-Host "Checking $VMMacAddress"
    $MDTComputer = Get-MDTComputer | Where-Object -Property "MacAddress" -Like -Value $VMMacAddress
    if ($MDTComputer.MacAddress -EQ "$VMMacAddress")
        {
        Write-Host "Prestaged in DB"
        Write-Host "Update record"
        Set-MDTComputer -id $MDTComputer.ID -settings $MDTComputerSettings
        }
    else
        {
        Write-Host "Not Prestaged in DB"
        New-MDTComputer -macAddress $VMMacAddress -description $VMName -settings $MDTComputerSettings
        }
 
    # Start VM
    Start-Vm -ComputerName $vmhost -Name $vmname -Verbose
 
}
 
# SCRIPT MAC
#Install-RemoteVM -VMName SRV133 -VMRam 1024MB -VMNetwork LAN -VMCpu 1 -VMDiskSize 100GB -VMHost LAB-VMHOST01 -MDTServer LAB-MDT01 -MDTDataBaseInstance ADK -MDTDataBase MDT -TaskSequence WS12R2-01
 
# USER MAC
#Install-RemoteVM -VMName SRV134 -VMRam 2048MB -VMNetwork LAN -VMCpu 1 -VMDiskSize 100GB -VMMacAddress "00:15:5A:AA:AA:11" -VMHost LAB-VMHOST01 -MDTServer LAB-MDT01 -MDTDataBaseInstance ADK -MDTDataBase MDT -TaskSequence WS12R2-01
Posted in Deployment, Powershell | Leave a comment

Komplett MDT konfiguration med powershell

Till er som saknat ett powershellscript för att sätta upp alla grundkonfiguration i MDT ink. databaskoppling!
Scriptet förutsätter att man har installerat ADK 8.1 och MDT först.

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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<#
 #############################################################################
 #  Created:	2014-01-01
 #  version:	v1.1
 #  Author:	Henrik Toft
 #  Homepage:	http://www.toft.se/
 #  Disclaimer:	This script is provided "AS IS" with no warranties
 #############################################################################
#>
 
## Vars
$SQLServer = "LAB-MDT01"
$SQLInstance = "ADK"
$SQLDatabase = "MDT"
$Netlib = "DBNMPNTW"
$MDTShareName = "DS01"
$MDTRoot = "C:\MDT\DS01"
$WDSRoot = "C:\WDS"
$ISORoot = "C:\ISOS"
$MDTShare = "\\LAB-MDT01\DS01"
$CSPath = "$MDTRoot\Control\CustomSettings.ini"
$BSPath = "$MDTRoot\Control\Bootstrap.ini"
$DSDescription = "DS01 - LabProduction"
$DomainName = "LAB"
$DomainUser = "Administrator"
$DomainPassword = "P@ssw0rd"
 
 
## Import MDT Module
Import-Module "C:\Program Files\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"
 
## Setup Directories
New-Item -Type Directory $MDTRoot
New-Item -Type Directory $WDSRoot
New-Item -Type Directory $ISORoot
 
# Share DS
New-SmbShare -Path $MDTRoot -Name $MDTShareName -ReadAccess Everyone
 
## Setup DeploymentShare DS01
New-PSDrive -Name "DS001" -PSProvider "MDTProvider" -Root $MDTRoot -Description $DSDescription -NetworkPath $MDTShare -Verbose | add-MDTPersistentDrive -Verbose
 
## Build CustomSettings.ini for LAB-MDT01
Function Build-CustomSettings {
 
if (Test-path $CSPath) {Remove-Item -Path $CSPath -Force}
New-Item -Path $CSPath -type file
 
Add-Content -path $CSPath -value  "[Settings]"
Add-Content -path $CSPath -value  "Priority=CSettings, CPackages, CApps, CAdmins, CRoles, Locations, LSettings, LPackages, LApps, LAdmins, LRoles, MMSettings, MMPackages, MMApps, MMAdmins, MMRoles, RSettings, RPackages, RApps, RAdmins, Default"
Add-Content -path $CSPath -value  "Properties=MyCustomProperty"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[Default]"
Add-Content -path $CSPath -value  "OSInstall=YES"
Add-Content -path $CSPath -value  "SkipBDDWelcome=YES"
Add-Content -path $CSPath -value  "SkipCapture=NO"
Add-Content -path $CSPath -value  "SkipAdminPassword=YES"
Add-Content -path $CSPath -value  "SkipApplications=YES"
Add-Content -path $CSPath -value  "SkipAppsOnUpgrade=YES"
Add-Content -path $CSPath -value  "SkipProductKey=YES"
Add-Content -path $CSPath -value  "SkipDomainMembership=YES"
Add-Content -path $CSPath -value  "SkipComputerName=YES"
Add-Content -path $CSPath -value  "SkipUserData=YES"
Add-Content -path $CSPath -value  "SkipTaskSequence=NO"
Add-Content -path $CSPath -value  "SkipLocaleSelection=YES"
Add-Content -path $CSPath -value  "SkipSummary=YES"
Add-Content -path $CSPath -value  "SkipBitLocker=YES"
Add-Content -path $CSPath -value  "KeyboardLocale=sv-SE"
Add-Content -path $CSPath -value  "UserLocale=sv-SE"
Add-Content -path $CSPath -value  "UILanguage=sv-SE"
Add-Content -path $CSPath -value  "SkipTimeZone=YES"
Add-Content -path $CSPath -value  "TimeZoneName=W. Europe Standard Time"
Add-Content -path $CSPath -value  "HideShell=NO"
Add-Content -path $CSPath -value  "ApplyGPOPack=NO"
Add-Content -path $CSPath -value  "DomainAdmin=Administrator"
Add-Content -path $CSPath -value  "DomainAdminDomain=lab"
Add-Content -path $CSPath -value  "DomainAdminPassword=P@ssw0rd"
Add-Content -path $CSPath -value  "JoinDomain=lab.labben.se"
Add-Content -path $CSPath -value  "MachineObjectOU=OU=LabServers,OU=MACHINES,OU=LAB,DC=lab,DC=labben,DC=se"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[CSettings]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=ComputerSettings"
Add-Content -path $CSPath -value  "Parameters=UUID, AssetTag, SerialNumber, MacAddress"
Add-Content -path $CSPath -value  "ParameterCondition=OR"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[CPackages]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=ComputerPackages"
Add-Content -path $CSPath -value  "Parameters=UUID, AssetTag, SerialNumber, MacAddress"
Add-Content -path $CSPath -value  "ParameterCondition=OR"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[CApps]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=ComputerApplications"
Add-Content -path $CSPath -value  "Parameters=UUID, AssetTag, SerialNumber, MacAddress"
Add-Content -path $CSPath -value  "ParameterCondition=OR"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[CAdmins]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=ComputerAdministrators"
Add-Content -path $CSPath -value  "Parameters=UUID, AssetTag, SerialNumber, MacAddress"
Add-Content -path $CSPath -value  "ParameterCondition=OR"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[CRoles]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=ComputerRoles"
Add-Content -path $CSPath -value  "Parameters=UUID, AssetTag, SerialNumber, MacAddress"
Add-Content -path $CSPath -value  "ParameterCondition=OR"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[Locations]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=Locations"
Add-Content -path $CSPath -value  "Parameters=DefaultGateway"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[LSettings]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=LocationSettings"
Add-Content -path $CSPath -value  "Parameters=DefaultGateway"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[LPackages]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=LocationPackages"
Add-Content -path $CSPath -value  "Parameters=DefaultGateway"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[LApps]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=LocationApplications"
Add-Content -path $CSPath -value  "Parameters=DefaultGateway"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[LAdmins]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=LocationAdministrators"
Add-Content -path $CSPath -value  "Parameters=DefaultGateway"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[LRoles]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=LocationRoles"
Add-Content -path $CSPath -value  "Parameters=DefaultGateway"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[MMSettings]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=MakeModelSettings"
Add-Content -path $CSPath -value  "Parameters=Make, Model"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[MMPackages]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=MakeModelPackages"
Add-Content -path $CSPath -value  "Parameters=Make, Model"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[MMApps]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=MakeModelApplications"
Add-Content -path $CSPath -value  "Parameters=Make, Model"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[MMAdmins]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=MakeModelAdministrators"
Add-Content -path $CSPath -value  "Parameters=Make, Model"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[MMRoles]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=MakeModelRoles"
Add-Content -path $CSPath -value  "Parameters=Make, Model"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[RSettings]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=RoleSettings"
Add-Content -path $CSPath -value  "Parameters=Role"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[RPackages]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=RolePackages"
Add-Content -path $CSPath -value  "Parameters=Role"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[RApps]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=RoleApplications"
Add-Content -path $CSPath -value  "Parameters=Role"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[RAdmins]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=RoleAdministrators"
Add-Content -path $CSPath -value  "Parameters=Role"
}
Build-CustomSettings
 
## Build Bootstrap.ini
Function Build-Bootstrap {
 
if (Test-path $BSPath) {Remove-Item -Path $BSPath -Force}
New-Item -Path $BSPath -type file
 
Add-Content -path $BSPath -value  "[Settings]"
Add-Content -path $BSPath -value  "Priority=Default"
Add-Content -path $BSPath -value  "`r"
Add-Content -path $BSPath -value  "[Default]"
Add-Content -path $BSPath -value  "DeployRoot=$MDTShare"
Add-Content -path $BSPath -value  "SkipBDDWelcome=YES"
Add-Content -path $BSPath -value  "UserDomain=$DomainName"
Add-Content -path $BSPath -value  "UserID=$DomainUser"
Add-Content -path $BSPath -value  "UserPassword=$DomainPassword"
}
Build-Bootstrap
 
## Configure SQL Server
$wmi = new-object ("Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer") "$env:computername"
 
# Enable the TCP protocol
$uri = "ManagedComputer[@Name='$env:computername']/ ServerInstance[@Name='$SQLInstance']/ServerProtocol[@Name='Tcp']"
$Tcp = $wmi.GetSmoObject($uri)
$Tcp.IsEnabled = $true
$Tcp.Alter()
$Tcp
 
# Enable the Named Pipes protocol
$uri = "ManagedComputer[@Name='$env:computername']/ ServerInstance[@Name='$SQLInstance']/ServerProtocol[@Name='Np']"
$Np = $wmi.GetSmoObject($uri)
$Np.IsEnabled = $true
$Np.Alter()
$Np
 
# Enable SQL Browser
Get-Service SQLBrowser | Set-Service -StartupType Automatic -Verbose
Get-Service SQLBrowser | Start-Service -Verbose
 
# Configure Firewall
New-NetFirewallRule -Name "Allow SqlServr" -DisplayName "Allow SqlServr" -Program "C:\Program Files (x86)\Microsoft SQL Server\MSSQL11.ADK\MSSQL\Binn\sqlservr.exe" -Enabled True -Profile Domain -Action Allow
New-NetFirewallRule -Name "Allow SqlBrowser" -DisplayName "Allow SqlBrowser" -Program "C:\Program Files (x86)\Microsoft SQL Server\90\Shared\sqlbrowser.exe" -Enabled True -Profile Domain -Action Allow
New-NetFirewallRule -Name "Allow SqlBrowser UDP 1434" -DisplayName "Allow SqlBrowser UDP 1434" -LocalPort 1434 -Protocol UDP -Action Allow -Profile Domain
 
## Setup MDT Database
New-MDTDatabase -path "DS001:" -SQLServer $SQLServer -Instance $SQLInstance -Netlib $Netlib -Database $SQLDatabase -SQLShare $MDTShareName -Verbose
 
## Build DS01
Update-MDTDeploymentShare -path "DS001:" -Verbose
 
## Configure WDS
if ($(Get-WindowsFeature WDS).InstallState -like "Available") {
    Write-Verbose "WDS Service is not installed. installing WDS..." -Verbose
    Install-WindowsFeature WDS -IncludeAllSubFeature -IncludeManagementTools -Verbose
    Write-Verbose "Server needs to reboot, reboot the server before running the script again" -Verbose
    break
    }
    elseif ($(Get-WindowsFeature WDS).InstallState -like "Installed") {
    Write-Verbose "WDS Service already installed. no need to install it" -Verbose
    }
    else {Write-Verbose "WDS Service state could not be determined" -Verbose}
 
Invoke-Expression "wdsutil /initialize-server /reminst:$WDSRoot"
Invoke-Expression "wdsutil /Set-Server /AnswerClients:all"
Invoke-Expression "wdsutil /Set-Server /pxepromptpolicy /known:noprompt"
Import-WdsBootImage -Path $MDTRoot\Boot\LiteTouchPE_x64.wim -NewImageName "LiteTouch x64" -SkipVerify
Posted in Deployment, Powershell | Leave a comment

New-TVM, Återskapa VM’s i Hyper-V om och om igen för lab/lek/test

En liten julklapp från mig till alla er som skapar många VM’s om och om igen för lab/lek/test osv.

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
# Re-Create VM in Hyper-V over and over again..
# By Toft 2013/12/25
$VmVhdLocation = "D:\VMs\Virtual Hard Disks"
 
Function New-TVM
    {
        Param(
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$VMName,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$VMRam,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$VMNetwork,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$VMMacAddress,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()]$VMCpu
        ) 
 
        $VM = Get-VM $VMName -ErrorAction SilentlyContinue
 
            if ($VM) {
                if (Get-Process vmconnect -ErrorAction SilentlyContinue | ? MainWindowTitle -match $VmName) {Get-Process vmconnect | ? MainWindowTitle -match $VmName | Stop-Process -Verbose}
                    else {Write-Verbose  "No vmconnect window for $VmName was found" -Verbose}
                for ($a=1; $a -lt 100; $a++) {
                    Write-Progress -Activity "$VMName already exist..." -PercentComplete $a -CurrentOperation "$a% complete" -Status "last chance to abort..."
                    Start-Sleep -Milliseconds 40
                    }
                if ($VM.State -eq "Running") {
                    Stop-VM -Name $VMName -TurnOff -Verbose
                    }
                $VM.Harddrives | Remove-Item -Verbose
                Remove-VM -Name $VMName -Force -Verbose  
                    }
        New-VHD –Path "$VmVhdLocation\$($VMName).vhdx" -SizeBytes 100GB
        Sleep -Milliseconds 300
        New-VM –Name $VMName –MemoryStartupBytes $VMRam –VHDPath "$VmVhdLocation\$($VMName).vhdx" -SwitchName $VMNetwork -Generation 2
        Set-VM $VMName -DynamicMemory -ProcessorCount $VMCpu
        Set-VMNetworkAdapter -VMName $VMName -StaticMacAddress $VMMacAddress
        Start-VM -Name $VMName
        Write-Verbose "VM $VMname was created" -Verbose
 
        # Connect vm
        vmconnect.exe localhost $VMName
}
 
New-TVM -VMName LAB-DC01 -VMRam 2048MB -VMNetwork LAN -VMMacAddress "00:15:5A:AA:AA:01" -VMCpu 1
New-TVM -VMName LAB-DC02 -VMRam 2048MB -VMNetwork LAN -VMMacAddress "00:15:5A:AA:AA:02" -VMCpu 1
 
New-TVM -VMName LAB-RDS01 -VMRam 2048MB -VMNetwork LAN -VMMacAddress "00:15:5A:AA:AA:03" -VMCpu 1
New-TVM -VMName LAB-FS01 -VMRam 2048MB -VMNetwork LAN -VMMacAddress "00:15:5A:AA:AA:04" -VMCpu 1
New-TVM -VMName LAB-WEB01 -VMRam 2048MB -VMNetwork LAN -VMMacAddress "00:15:5A:AA:AA:05" -VMCpu 1
New-TVM -VMName LAB-RRAS01 -VMRam 2048MB -VMNetwork LAN -VMMacAddress "00:15:5A:AA:AA:06" -VMCpu 1
 
New-TVM -VMName LAB-CLIENT01 -VMRam 2048MB -VMNetwork LAN -VMMacAddress "00:15:5A:AA:AA:11" -VMCpu 1
New-TVM -VMName LAB-CLIENT02 -VMRam 2048MB -VMNetwork LAN -VMMacAddress "00:15:5A:AA:AA:12" -VMCpu 1
New-TVM -VMName LAB-CLIENT03 -VMRam 2048MB -VMNetwork LAN -VMMacAddress "00:15:5A:AA:AA:13" -VMCpu 1
Posted in Powershell | Leave a comment

WS12 Skapa NIC Team och ärv statiska IP inställningar

Satt med en lösning idag för att automatisera NIC teaming på X antal maskiner som redan hade statiska IP adresser satta på ett nätverkskort.
Slängde då ihop ett script som läser ut IP inställningarna på NIC:et med statiska inställningar, sparar dem, skapar team:et och sätter sedan samma IP inställningar på de nya team:et.
Håll till godo :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Skapa NIC Team och ärv statiska IP inställningar..
# Sätt Team Namn
$TeamName = "LAN"
 
# Definiera team medlemar, i detta fallet vet jag vilka kort det är.
$TeamMember01 = Get-NetAdapter -ifIndex 12
$TeamMember02 = Get-NetAdapter -ifIndex 13
 
# Hämta nätverkskortet där statiskt ip redan är satt
$StaticIpNIC = Get-NetIPAddress | where PrefixOrigin -like Manual
 
# Sätt variabler för IP,GW och DNS
$IP = (Get-NetIPConfiguration -ifIndex $StaticIpNIC.ifindex).IPv4Address.IPAddress
$GW = (Get-NetIPConfiguration -ifIndex $StaticIpNIC.ifindex).IPv4DefaultGateway.NextHop
$DNS = (Get-NetIPConfiguration -ifIndex $StaticIpNIC.ifindex).DNSServer.ServerAddresses
 
# Skapa nytt team
New-NetLbfoTeam -Name $TeamName -TeamMembers $TeamMember01.Name, $TeamMember02.Name -Confirm:$false
 
# Sätt IP,GW och DNS på de nya teamet.
New-NetIPAddress -InterfaceAlias $TeamName -IPAddress $IP -DefaultGateway $GW -PrefixLength 24
Set-DnsClientServerAddress -InterfaceAlias $TeamName -ServerAddresses $DNS
Posted in Deployment, Powershell | Leave a comment