70-740, Teil 5.2.1. Arbeitsgruppen, Einfachen und Mehrere Domänen- Cluster implementieren

70-740, Teil 5.2.1.

Arbeitsgruppen, Einfachen und Mehrere Domänen- Cluster implementieren

Ideen für die Recherche im Web:

youtube NLB Solutions failover cluster

Zum Nachschlagen:

https://docs.microsoft.com/de-de/windows-server/failover-clustering/failover-clustering-overview

https://docs.microsoft.com/de-de/windows-server/failover-clustering/whats-new-in-failover-clustering

https://docs.microsoft.com/de-de/windows-server/failover-clustering/fault-domains

https://www.youtube.com/channel/UCNzrVTbi4fe_PbYCJvhPQ8A/videos

https://www.youtube.com/watch?v=4bCeqfhoW0c

https://www.youtube.com/watch?v=CvRwTJCScQY

Übungen:

###

#Beispiel 1

###

$var_Pfad_zur_ISO_Datei = ‘C:\ISOs\W2016-14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_DE-DE.iso’

$var_DomainName = ‘mit.lernen’

$var_iSCSI = ‘MM-iSCSI’

$var_K1=’MM-K1′

$var_K2=’MM-K2′

$var_IPAddress_iSCSI = ‘192.168.178.216’ #IP-Adresse vom iSCSI-Server für den Failovercluster

$var_IPAddress_K1 = ‘192.168.178.217’ #IP-Adresse vom Knoten1 in dem Failovercluster

$var_IPAddress_K2 = ‘192.168.178.218’ #IP-Adresse vom Knoten2 in dem Failovercluster

$var_IPAddress_IscsiServerTarget1 = ‘IPAddress:’ + $var_IPAddress_K1

$var_IPAddress_IscsiServerTarget2 = ‘IPAddress:’ + $var_IPAddress_K2

$var_PrefixLength = ’24’

$var_DefaultGateway = ‘192.168.178.1’

$var_DnsClientServerAddress = ‘192.168.178.6’

$var_Kennwort_fuer_K1_Administrator = Read-Host -Prompt ‘Bitte Kennwort für K1\Administrator und/oder K2\Administrator und/oder iSCSI\Administrator eingeben’ -AsSecureString

$var_Credential_K1_Administrator = new-object -typename System.Management.Automation.PSCredential -argumentlist ‘K1\Administrator’,$var_Kennwort_fuer_K1_Administrator

$var_Kennwort_fuer_K2_Administrator = $var_Kennwort_fuer_K1_Administrator

$var_Credential_K2_Administrator = new-object -typename System.Management.Automation.PSCredential -argumentlist ‘K2\Administrator’,$var_Kennwort_fuer_K2_Administrator

$var_Kennwort_fuer_iSCSI_Administrator = $var_Kennwort_fuer_K1_Administrator

$var_Credential_iSCSI_Administrator = new-object -typename System.Management.Automation.PSCredential -argumentlist ‘iSCSI\Administrator’,$var_Kennwort_fuer_iSCSI_Administrator

$var_Kennwort_fuer_MIT_Administrator = Read-Host -Prompt ‘Bitte Kennwort für MIT\Administrator eingeben’ -AsSecureString

$var_Credential_MIT_Administrator = new-object -typename System.Management.Automation.PSCredential -argumentlist ‘MIT\Administrator’,$var_Kennwort_fuer_MIT_Administrator

$var_SwitchName=(Get-VMSwitch | Where-Object SwitchType -eq ‘External’).Name

$var_SwitchName

New-VHD –Path (‘c:\ISOs\’ + $var_iSCSI + ‘.vhdx’) –SizeBytes 100GB -Dynamic -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path (‘c:\ISOs\’ + $var_iSCSI + ‘T.vhdx’) –SizeBytes 1TB -Dynamic -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path (‘c:\ISOs\’ + $var_iSCSI + ‘U.vhdx’) –SizeBytes 1TB -Dynamic -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path (‘c:\ISOs\’ + $var_iSCSI + ‘V.vhdx’) –SizeBytes 1TB -Dynamic -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path (‘c:\ISOs\’ + $var_iSCSI + ‘W.vhdx’) –SizeBytes 1TB -Dynamic -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path (‘c:\ISOs\’ + $var_iSCSI + ‘X.vhdx’) –SizeBytes 1TB -Dynamic -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path (‘c:\ISOs\’ + $var_iSCSI + ‘Y.vhdx’) –SizeBytes 1TB -Dynamic -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path (‘c:\ISOs\’ + $var_iSCSI + ‘Z.vhdx’) –SizeBytes 1TB -Dynamic -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096

#https://docs.microsoft.com/en-us/powershell/module/hyper-v/new-vhd?view=win10-ps

New-VM -ComputerName . -Name $var_iSCSI -VHDPath (‘c:\ISOs\’ + $var_iSCSI + ‘.vhdx’) -Generation 2 -MemoryStartupBytes 2GB -SwitchName $var_SwitchName
#https://docs.microsoft.com/de-de/previous-versions/windows/powershell-scripting/hh848537(v=wps.640)

84..90 | %{
# Zum Vergleich A bis Z: 65..90 | %{[char]$_}

$var_Pfad = ‘c:\ISOs\’ +$var_iSCSI+[char]$_ + ‘.vhdx’

$var_Pfad

Add-VMHardDiskDrive -VMName $var_iSCSI -Path $var_Pfad

}

#https://docs.microsoft.com/en-us/powershell/module/hyper-v/add-vmharddiskdrive?view=win10-ps

Add-VMDvdDrive -VMName $var_iSCSI -Path $var_Pfad_zur_ISO_Datei

Get-VMDvdDrive -VMName $var_iSCSI

(Get-VMFirmware $var_iSCSI).BootOrder

$var_DVDDrive=Get-VMDvdDrive -VMName $var_iSCSI

Set-VMFirmware -VMName $var_iSCSI -FirstBootDevice $var_DVDDrive

(Get-VMFirmware $var_iSCSI).BootOrder

Set-VM -VMName $var_iSCSI –AutomaticStartAction Nothing

[System.Windows.MessageBox]::Show(‘Bitte, installieren Sie jetzt das Betriebssystem auf dem iSCSI-Server und anschliesend klicken Sie auf Ok.’)

#Betriebssystem manuell installieren
#oder Cmdlet Convert-WindowsImage
#alternativ unbeaufsichtigte Installation durchführen
#https://social.technet.microsoft.com/wiki/contents/articles/36609.windows-server-2016-unattended-installation.aspx

Get-VM $var_iSCSI

#Bei Bedarf: Start-VM iSCSI

Invoke-Command -VMName $var_iSCSI -ScriptBlock {Rename-Computer -NewName $using:var_iSCSI -LocalCredential $using:var_Credential_iSCSI_Administrator -Restart}

Get-VM $var_iSCSI

Invoke-Command -VMName $var_iSCSI -Credential $var_Credential_iSCSI_Administrator -ScriptBlock {

ipconfig /all

$var_InterfaceIndex=(Get-NetIPConfiguration).InterfaceIndex

$var_InterfaceIndex

Set-NetIPInterface -InterfaceIndex $var_InterfaceIndex -Dhcp Disabled

Remove-NetIPAddress -InterfaceIndex $var_InterfaceIndex -Confirm:$False

New-NetIPAddress -InterfaceIndex $var_InterfaceIndex -IPAddress $using:var_IPAddress_iSCSI -PrefixLength $using:var_PrefixLength –DefaultGateway $using:var_DefaultGateway

Set-DnsClientServerAddress -InterfaceIndex $var_InterfaceIndex -ServerAddresses ($using:var_DnsClientServerAddress)

Get-NetIPAddress -InterfaceIndex $var_InterfaceIndex -AddressFamily IPv4 | fl IPAddress, PrefixLength, InterfaceIndex, InterfaceAlias

Get-DnsClientServerAddress -InterfaceIndex $var_InterfaceIndex -AddressFamily IPv4

ipconfig /all

Add-Computer -DomainName $using:var_DomainName -LocalCredential $using:var_Credential_iSCSI_Administrator -Credential $using:var_Credential_MIT_Administrator -Restart
}

#Speicherpool konfigurieren

Invoke-Command -VMName $var_iSCSI -Credential $var_Credential_iSCSI_Administrator -ScriptBlock {

Get-StoragePool

Get-Disk | Where partitionstyle -eq ‘raw’ | ft Number, PartitionStyle, Size, ProvisioningType, FriendlyName

Get-PhysicalDisk | Sort-Object -Property DeviceID | ft DeviceID, CanPool, Size

$var_PhysicalDisks = (Get-PhysicalDisk -CanPool $True); $var_PhysicalDisks | Sort-Object -Property DeviceID | ft DeviceID, CanPool, Size

Get-StoragePool | fl FriendlyName

New-StoragePool -FriendlyName Speicherpool1 -StorageSubsystemFriendlyName ‘Windows Storage*’ -PhysicalDisks $var_PhysicalDisks -ResiliencySettingNameDefault Parity -ProvisioningTypeDefault Thin -Verbose

Get-StoragePool | fl FriendlyName

Get-VirtualDisk

New-VirtualDisk -FriendlyName vDisk1 -StoragePoolFriendlyName Speicherpool1 -ProvisioningType Thin -Size 1TB -ResiliencySettingName ‘Parity’ -PhysicalDiskRedundancy 2

Get-VirtualDisk

Get-Disk | Where partitionstyle -eq ‘raw’ | ft Number, PartitionStyle, Size, ProvisioningType, FriendlyName

Get-Disk | Where partitionstyle -eq ‘raw’ | Initialize-Disk -PartitionStyle GPT -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel ‘vDisk1Volume1’ -Confirm:$False

$var_DriveLetter = (Get-Volume | Where-Object FileSystemLabel -EQ ‘vDisk1Volume1’).DriveLetter

$var_DriveLetter

New-VirtualDisk -FriendlyName vDisk2 -StoragePoolFriendlyName Speicherpool1 -ProvisioningType Fixed -Size 1GB -ResiliencySettingName ‘Parity’ -PhysicalDiskRedundancy 2

Get-VirtualDisk

Get-Disk | Where partitionstyle -eq ‘raw’ | ft Number, PartitionStyle, Size, ProvisioningType, FriendlyName

Get-Disk | Where partitionstyle -eq ‘raw’ | Initialize-Disk -PartitionStyle GPT -PassThru | New-Partition -DriveLetter Q -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel ‘vDisk1Volume2’ -Confirm:$False

$var_DriveLetter = (Get-Volume | Where-Object FileSystemLabel -EQ ‘vDisk1Volume2’).DriveLetter

$var_DriveLetter

#iSCSI-Rolle installieren

Get-WindowsFeature *iscsi*

Get-WindowsFeature FS-iSCSITarget-Server

Install-WindowsFeature FS-iSCSITarget-Server -IncludeAllSubFeature -IncludeManagementTools

Get-Command new*iscsi*

$var_iSCSI_Pfad = $var_DriveLetter + ‘:\iSCSI\’

$var_iSCSI_Pfad

if(-not (Test-Path $var_iSCSI_Pfad)){
mkdir $var_iSCSI_Pfad
}

dir $var_iSCSI_Pfad

$var_iSCSI_Pfad_zur_Datei = $var_iSCSI_Pfad + ‘iSCSI-vDisk-1.vhdx’

New-IscsiVirtualDisk -Path $var_iSCSI_Pfad_zur_Datei -SizeBytes 1GB
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/new-iscsivirtualdisk?view=win10-ps

New-IscsiServerTarget -TargetName ‘iSCSI-Ziel-1’ -InitiatorId @($var_IPAddress_IscsiServerTarget1, $var_IPAddress_IscsiServerTarget2)
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/new-iscsiservertarget?view=win10-ps

Add-IscsiVirtualDiskTargetMapping -TargetName ‘iSCSI-Ziel-1’ -DevicePath $var_iSCSI_Pfad_zur_Datei
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/add-iscsivirtualdisktargetmapping?view=win10-ps

$var_iSCSI_Pfad = $var_DriveLetter + ‘:\iSCSI\’
$var_iSCSI_Pfad_zur_Datei = $var_iSCSI_Pfad + ‘iSCSI-vDisk-2.vhdx’
New-IscsiVirtualDisk -Path $var_iSCSI_Pfad_zur_Datei -SizeBytes 500GB
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/new-iscsivirtualdisk?view=win10-ps

New-IscsiServerTarget -TargetName ‘iSCSI-Ziel-2’ -InitiatorId @($using:var_IPAddress_IscsiServerTarget1, $using:var_IPAddress_IscsiServerTarget2)
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/new-iscsiservertarget?view=win10-ps

Add-IscsiVirtualDiskTargetMapping -TargetName ‘iSCSI-Ziel-2’ -DevicePath $var_iSCSI_Pfad_zur_Datei
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/add-iscsivirtualdisktargetmapping?view=win10-ps

}

#Failovercluster-Knoten vorbereiten

New-VHD –Path (‘c:\ISOs\’ + $var_K1 + ‘.vhdx’) –SizeBytes 100GB -Dynamic -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096

#https://docs.microsoft.com/en-us/powershell/module/hyper-v/new-vhd?view=win10-ps

New-VM -ComputerName . -Name $var_K1 -VHDPath (‘c:\ISOs\’ + $var_K1 + ‘.vhdx’) -Generation 2 -MemoryStartupBytes 2GB -SwitchName $var_SwitchName
#https://docs.microsoft.com/de-de/previous-versions/windows/powershell-scripting/hh848537(v=wps.640)

#https://docs.microsoft.com/en-us/powershell/module/hyper-v/add-vmharddiskdrive?view=win10-ps

Add-VMDvdDrive -VMName $var_K1 -Path ‘C:\ISOs\W2016-14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_DE-DE.iso’

Get-VMDvdDrive -VMName $var_K1

(Get-VMFirmware $var_K1).BootOrder

$var_DVDDrive=Get-VMDvdDrive -VMName $var_K1

Set-VMFirmware -VMName $var_K1 -FirstBootDevice $var_DVDDrive

(Get-VMFirmware $var_K1).BootOrder

Set-VM -VMName $var_K1 –AutomaticStartAction Nothing

New-VHD –Path (‘c:\ISOs\’ + $var_K2 + ‘.vhdx’) –SizeBytes 100GB -Dynamic -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096

#https://docs.microsoft.com/en-us/powershell/module/hyper-v/new-vhd?view=win10-ps

New-VM -ComputerName . -Name $var_K2 -VHDPath (‘c:\ISOs\’ + $var_K2 + ‘.vhdx’) -Generation 2 -MemoryStartupBytes 2GB -SwitchName $var_SwitchName
#https://docs.microsoft.com/de-de/previous-versions/windows/powershell-scripting/hh848537(v=wps.640)

#https://docs.microsoft.com/en-us/powershell/module/hyper-v/add-vmharddiskdrive?view=win10-ps

Add-VMDvdDrive -VMName $var_K2 -Path ‘C:\ISOs\W2016-14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_DE-DE.iso’

Get-VMDvdDrive -VMName $var_K2

(Get-VMFirmware $var_K2).BootOrder

$var_DVDDrive=Get-VMDvdDrive -VMName $var_K2

Set-VMFirmware -VMName $var_K2 -FirstBootDevice $var_DVDDrive

(Get-VMFirmware $var_K2).BootOrder

Set-VM -VMName $var_K2 –AutomaticStartAction Nothing

[System.Windows.MessageBox]::Show(‘Bitte, installieren Sie jetzt das Betriebssystem auf beiden Failovercluster-Knoten und anschliesend klicken Sie auf Ok.’)
#Betriebssystem manuell installieren
#oder Cmdlet Convert-WindowsImage
#alternativ unbeaufsichtigte Installation durchführen
#https://social.technet.microsoft.com/wiki/contents/articles/36609.windows-server-2016-unattended-installation.aspx

Get-VM $var_K1,$var_K2

$var_PSSession_K1 = New-PSSession -VMName $var_K1 -Credential $var_Credential_K1_Administrator ### noch zu Bereinigen

$var_PSSession_K2 = New-PSSession -VMName $var_K2 -Credential $var_Credential_K2_Administrator ### noch zu Bereinigen

Invoke-Command -VMName $var_K1 -Credential $var_Credential_K1_Administrator -ScriptBlock {Rename-Computer -NewName $using:var_K1 -Restart}

Invoke-Command -VMName $var_K2 -Credential $var_Credential_K2_Administrator -ScriptBlock {Rename-Computer -NewName $using:var_K2 -Restart}

Get-VM $var_K1,$var_K2

Invoke-Command -VMName $var_K1 -Credential $var_Credential_K1_Administrator -ScriptBlock {

ipconfig /all

$var_InterfaceIndex=(Get-NetIPConfiguration).InterfaceIndex

$var_InterfaceIndex

Set-NetIPInterface -InterfaceIndex $var_InterfaceIndex -Dhcp Disabled

Remove-NetIPAddress -InterfaceIndex $var_InterfaceIndex -Confirm:$False

New-NetIPAddress -InterfaceIndex $var_InterfaceIndex -IPAddress $Using:var_IPAddress_K1 -PrefixLength $Using:var_PrefixLength –DefaultGateway $Using:var_DefaultGateway

Set-DnsClientServerAddress -InterfaceIndex $var_InterfaceIndex -ServerAddresses ($Using:var_DnsClientServerAddress)

Get-NetIPAddress -InterfaceIndex $var_InterfaceIndex -AddressFamily IPv4 | fl IPAddress, PrefixLength, InterfaceIndex, InterfaceAlias

Get-DnsClientServerAddress -InterfaceIndex $var_InterfaceIndex -AddressFamily IPv4

ipconfig /all

Add-Computer -DomainName $Using:var_DomainName -LocalCredential $using:var_Credential_K1_Administrator -Credential $using:var_Credential_MIT_Administrator -Restart

}

Invoke-Command -VMName $var_K2 -Credential $var_Credential_K2_Administrator -ScriptBlock {

ipconfig /all

$var_InterfaceIndex=(Get-NetIPConfiguration).InterfaceIndex

$var_InterfaceIndex

Set-NetIPInterface -InterfaceIndex $var_InterfaceIndex -Dhcp Disabled

Remove-NetIPAddress -InterfaceIndex $var_InterfaceIndex -Confirm:$False

New-NetIPAddress -InterfaceIndex $var_InterfaceIndex -IPAddress $Using:var_IPAddress_K2 -PrefixLength $Using:var_PrefixLength –DefaultGateway $Using:var_DefaultGateway

Set-DnsClientServerAddress -InterfaceIndex $var_InterfaceIndex -ServerAddresses ($Using:var_DnsClientServerAddress)

Get-NetIPAddress -InterfaceIndex $var_InterfaceIndex -AddressFamily IPv4 | fl IPAddress, PrefixLength, InterfaceIndex, InterfaceAlias

Get-DnsClientServerAddress -InterfaceIndex $var_InterfaceIndex -AddressFamily IPv4

ipconfig /all

Add-Computer -DomainName $Using:var_DomainName -LocalCredential $using:var_Credential_K2_Administrator -Credential $using:var_Credential_MIT_Administrator -Restart

}

#iSCSI Initiator konfigurieren

Invoke-Command -VMName $var_K1 -Credential $var_Credential_K1_Administrator -ScriptBlock {

Get-Service -Name msiscsi

Set-Service -Name msiscsi -StartupType Automatic
#https://blogs.msdn.microsoft.com/san/2012/07/31/managing-iscsi-initiator-connections-with-windows-powershell-on-windows-server-2012/

Get-Service -Name msiscsi

Set-Service -Name msiscsi -Status Running

Get-Service -Name msiscsi

Get-NetFirewallServiceFilter -Service msiscsi | Get-NetFirewallRule | Select DisplayGroup,DisplayName,Enabled

Get-NetFirewallServiceFilter -Service msiscsi | Get-NetFirewallRule | Set-NetFirewallRule -Enabled True

Get-NetFirewallServiceFilter -Service msiscsi | Get-NetFirewallRule | Select DisplayGroup,DisplayName,Enabled

Get-IscsiTargetPortal

New-IscsiTargetPortal –TargetPortalAddress $using:var_IPAddress_iSCSI

Get-IscsiTargetPortal
#https://docs.microsoft.com/en-us/powershell/module/iscsi/new-iscsitargetportal?view=win10-ps

Get-IscsiTarget

Get-IscsiTarget | Connect-IscsiTarget -IsPersistent $true

Get-IscsiTarget | ft NodeAddress, IsConnected

Get-iSCSIConnection

Get-iSCSISession

Get-iSCSISession | Get-Disk | ft Size,OperationalStatus

Get-Disk | Where-Object IsOffline –Eq $True

Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk -IsOffline $false

Get-Disk | ft Size,OperationalStatus

Get-Disk|where {$_.PartitionStyle -eq ‘RAW’} | ft Number, Size, PartitionStyle

Get-Disk | Where partitionstyle -eq ‘raw’ | Initialize-Disk -PartitionStyle GPT -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -Confirm:$False

Get-Volume | ft

Get-WindowsFeature *cluster*

Install-WindowsFeature Failover-Clustering -IncludeManagementTools -IncludeAllSubFeature

}

Invoke-Command -VMName $var_K2 -Credential $var_Credential_K2_Administrator -ScriptBlock {

Get-Service -Name msiscsi

Set-Service -Name msiscsi -StartupType Automatic
#https://blogs.msdn.microsoft.com/san/2012/07/31/managing-iscsi-initiator-connections-with-windows-powershell-on-windows-server-2012/

Get-Service -Name msiscsi

Set-Service -Name msiscsi -Status Running

Get-Service -Name msiscsi

Get-NetFirewallServiceFilter -Service msiscsi | Get-NetFirewallRule | Select DisplayGroup,DisplayName,Enabled

Get-NetFirewallServiceFilter -Service msiscsi | Get-NetFirewallRule | Set-NetFirewallRule -Enabled True

Get-NetFirewallServiceFilter -Service msiscsi | Get-NetFirewallRule | Select DisplayGroup,DisplayName,Enabled

Get-IscsiTargetPortal

New-IscsiTargetPortal –TargetPortalAddress $using:var_IPAddress_iSCSI

Get-IscsiTargetPortal
#https://docs.microsoft.com/en-us/powershell/module/iscsi/new-iscsitargetportal?view=win10-ps

Get-IscsiTarget

Get-IscsiTarget | Connect-IscsiTarget -IsPersistent $true

Get-IscsiTarget | ft NodeAddress, IsConnected

Get-iSCSIConnection

Get-iSCSISession

Get-iSCSISession | Get-Disk | ft Size,OperationalStatus

Get-Disk | Where-Object IsOffline –Eq $True

Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk -IsOffline $false

Get-Disk | ft Size,OperationalStatus

Get-Disk|where {$_.PartitionStyle -eq ‘RAW’}

#Nur beim ersten Knoten noch folgende Cmdlet: Get-Disk | Where partitionstyle -eq ‘raw’ | Initialize-Disk -PartitionStyle GPT -PassThru | New-Partition -DriveLetter I -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel ‘Quorum’ -Confirm:$False

Get-WindowsFeature *cluster*

Install-WindowsFeature Failover-Clustering -IncludeManagementTools -IncludeAllSubFeature

}

Enter-PSSession -VMName $var_K1 -Credential $var_Credential_K1_Administrator

New-Cluster –Name Cluster1 –Node $var_K1, $var_K2 –StaticAddress 192.168.178.209

###

#Beispiel 2

###

$var_SwitchName=(Get-VMSwitch | Where-Object SwitchType -eq “External”).Name

$var_SwitchName

1..2 | % {

New-VHD –Path c:\ISOs\wd-f$_.vhdx –SizeBytes 100GB -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path c:\ISOs\wd-fA$_.vhdx –SizeBytes 200GB -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path c:\ISOs\wd-fB$_.vhdx –SizeBytes 200GB -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path c:\ISOs\wd-fC$_.vhdx –SizeBytes 200GB -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path c:\ISOs\wd-fD$_.vhdx –SizeBytes 200GB -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path c:\ISOs\wd-fE$_.vhdx –SizeBytes 200GB -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path c:\ISOs\wd-fZ$_.vhdx –SizeBytes 1GB -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
#https://docs.microsoft.com/en-us/powershell/module/hyper-v/new-vhd?view=win10-ps

New-VM -VHDPath c:\ISOs\wd-f$_.vhdx -ComputerName . -Generation 2 -MemoryStartupBytes 2GB -Name wd-f$_ -SwitchName $var_SwitchName
#https://docs.microsoft.com/de-de/previous-versions/windows/powershell-scripting/hh848537(v=wps.640)

Add-VMHardDiskDrive -VMName wd-f$_ -Path c:\ISOs\wd-fA$_.vhdx

Add-VMHardDiskDrive -VMName wd-f$_ -Path c:\ISOs\wd-fB$_.vhdx

Add-VMHardDiskDrive -VMName wd-f$_ -Path c:\ISOs\wd-fC$_.vhdx

Add-VMHardDiskDrive -VMName wd-f$_ -Path c:\ISOs\wd-fD$_.vhdx

Add-VMHardDiskDrive -VMName wd-f$_ -Path c:\ISOs\wd-fE$_.vhdx

Add-VMHardDiskDrive -VMName wd-f$_ -Path c:\ISOs\wd-fZ$_.vhdx
#https://docs.microsoft.com/en-us/powershell/module/hyper-v/add-vmharddiskdrive?view=win10-ps

Add-VMDvdDrive -VMName wd-f$_ -Path “C:\ISOs\14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_DE-DE.iso”

Get-VMDvdDrive -VMName wd-f$_

(Get-VMFirmware wd-f$_).BootOrder

$var_DVDDrive=Get-VMDvdDrive -VMName wd-f$_

Set-VMFirmware -VMName wd-f$_ -FirstBootDevice $var_DVDDrive

(Get-VMFirmware wd-f$_).BootOrder

Set-VM -VMName wd-f$_ –AutomaticStartAction Nothing

}

#Virtuelle Maschine starten und installieren
#Failover Cluster implementieren

#Auf dem Host iSCSI installieren

Get-WindowsFeature *iscsi*

Install-WindowsFeature FS-iSCSITarget-Server -IncludeAllSubFeature -IncludeManagementTools

Get-Command new*iscsi*

Get-Help New-IscsiVirtualDisk -ShowWindow

dir C:\iSCSI\

mkdir C:\iSCSI\

ls C:\iSCSI\

New-IscsiVirtualDisk -Path C:\iSCSI\iSCSI-vDisk-1.vhdx -SizeBytes 100GB
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/new-iscsivirtualdisk?view=win10-ps

New-IscsiServerTarget -TargetName „iSCSI-Ziel-1“ -InitiatorId @(„IPAddress:10.10.3.201“,„IPAddress:10.10.3.201“)
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/new-iscsiservertarget?view=win10-ps

Add-IscsiVirtualDiskTargetMapping -TargetName „iSCSI-Ziel-1“ -DevicePath „C:\iSCSI\iSCSI-vDisk-1.vhdx“
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/add-iscsivirtualdisktargetmapping?view=win10-ps

#Knoten vorbereiten

Invoke-Command -VMName wd-f1 -ScriptBlock {Rename-Computer -NewName wd-f1 -Restart}

Invoke-Command -VMName wd-f2 -ScriptBlock {Rename-Computer -NewName wd-f2 -Restart}

get-vm

1..2 | % {

Enter-PSSession -VMName wd-f$_

ipconfig /all

$var_InterfaceIndex=(Get-NetIPConfiguration).InterfaceIndex

Set-NetIPInterface -InterfaceIndex $var_InterfaceIndex -Dhcp Disabled

Remove-NetIPAddress -InterfaceIndex $var_InterfaceIndex

Remove-NetRoute -DestinationPrefix 0.0.0.0/0

New-NetIPAddress -InterfaceIndex $var_InterfaceIndex -IPAddress 10.10.3.20$_ -PrefixLength 8 –DefaultGateway 10.0.3.1

Set-DnsClientServerAddress -InterfaceIndex $var_InterfaceIndex -ServerAddresses („10.3.3.1“)

get-netipaddress -AddressFamily IPv4

ipconfig /all

Add-Computer -DomainName “multi.media” -Restart

}

#iSCSI Initiator konfigurieren

1..2 | % {

Get-VM wd-f2 | ft Name, State

Enter-PSSession -VMName wd-f$_

Get-Service -Name msiscsi

Set-Service -Name msiscsi -StartupType Automatic
#https://blogs.msdn.microsoft.com/san/2012/07/31/managing-iscsi-initiator-connections-with-windows-powershell-on-windows-server-2012/

Get-Service -Name msiscsi

Set-Service -Name msiscsi -Status Running

Get-Service -Name msiscsi

Get-NetFirewallServiceFilter -Service msiscsi | Get-NetFirewallRule | Select DisplayGroup,DisplayName,Enabled

Get-NetFirewallServiceFilter -Service msiscsi | Get-NetFirewallRule | Set-NetFirewallRule -Enabled True

Get-NetFirewallServiceFilter -Service msiscsi | Get-NetFirewallRule | Select DisplayGroup,DisplayName,Enabled

Get-IscsiTargetPortal

New-IscsiTargetPortal –TargetPortalAddress 10.10.3.1

Get-IscsiTargetPortal
#https://docs.microsoft.com/en-us/powershell/module/iscsi/new-iscsitargetportal?view=win10-ps

Get-IscsiTarget

Get-IscsiTarget | Connect-IscsiTarget -IsPersistent $true

Get-IscsiTarget | ft NodeAddress, IsConnected

Get-iSCSIConnection

Get-iSCSISession

Get-iSCSISession | Get-Disk | ft Size,OperationalStatus

Get-Disk | Where-Object IsOffline –Eq $True

Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk -IsOffline $false

Get-Disk | ft Size,OperationalStatus

Get-Disk|where {$_.PartitionStyle -eq “RAW”}

Get-Disk|where {$_.PartitionStyle -eq “RAW”}|Initialize-Disk -PartitionStyle MBR

Get-Disk

New-Partition -DiskNumber 7 -DriveLetter I -IsActive -UseMaximumSize

Format-Volume -DriveLetter I

Exit-PSSession

}

1..2 | % {

Enter-PSSession -VMName wd-f$_

get-command *cluster*

Get-WindowsFeature *cluster*

Install-WindowsFeature Failover-Clustering -IncludeManagementTools -IncludeAllSubFeature

get-command *cluster*

Exit-PSSession

}

Get-WindowsFeature *Cluster* | ft -AutoSize

Install-WindowsFeature RSAT-Clustering-Mgmt, RSAT-Clustering-PowerShell

New-Cluster –Name wd-cluster1 –Node wd-f1, wd-f2 –StaticAddress 10.10.3.10 -NoStorage

####

#https://social.technet.microsoft.com/wiki/contents/articles/36609.windows-server-2016-unattended-installation.aspx

$User_Name=“netz\willi.dukart“

$Secure=Read-Host -AsSecureString

$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User_Name,$Secure

Invoke-Command -ComputerName jb -Credential $Credential -ScriptBlock {ipconfig}

$var_pssession1_jb =New-PSSession -ComputerName jb

Invoke-Command -Session $var_pssession1_jb -ScriptBlock {ipconfig}

Invoke-Command -Session $var_pssession1_jb -ScriptBlock {$var_ip=Get-NetIPAddress -InterfaceIndex 17}

Invoke-Command -Session $var_pssession1_jb -ScriptBlock {$var_ip.IPv4Address}

Invoke-Command -ComputerName localhost, jb -Credential $Credential -ScriptBlock {ipconfig}

Invoke-Command -ComputerName localhost, jb -Credential $Credential -ScriptBlock {(Get-ComputerInfo).osName}

Get-VM

###

#Beispiel 3

###

$mountResult = Mount-DiskImage -ImagePath „C:\ISOs\Windows2016.iso“ -PassThru

$mountResult | Get-Volume

$driveLetter = (($mountResult | Get-Volume).DriveLetter) + „:\“

$isoPath=$driveLetter + „NanoServer\NanoServerImageGenerator“

$isoPath

If(Test-Path „C:\NanoServerImageGenerator“)
{
}
else
{
Copy-Item $isoPath -Destination C:\ -Recurse
}

cd C:\NanoServerImageGenerator

Get-ExecutionPolicy
# Bei Bedarf: Set-ExecutionPolicy RemoteSigned
# https://technet.microsoft.com/de-de/library/ee176961.aspx

Import-Module .\NanoServerImageGenerator -Verbose

#get-help New-NanoServerImage -ShowWindow

#get-help New-NanoServerImage -Online

dir $driveLetter

Get-VMSwitch

(Get-VMSwitch | Where-Object -Property SwitchType -EQ External).Name
$var_VMSwitch_Name = (Get-VMSwitch | Where-Object {$_.SwitchType -eq ‘External’}).Name

Rename-VMSwitch -Name $var_VMSwitch_Name -NewName ‘Management’

New-VMSwitch -Name Storage -SwitchType Private

New-VMSwitch -Name Heartbeat -SwitchType Private

New-VMSwitch -Name LiveMigration -SwitchType Private

$Secure = Read-Host -AsSecureString
#https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/convertto-securestring?view=powershell-5.1

1..2 | % {

$User_Name=“wdc$_“+“\administrator“

$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User_Name,$Secure

New-NanoServerImage -DeploymentType Guest -Edition Datacenter -TargetPath .\wdc$_.vhdx -Clustering -Storage -ComputerName wdc$_ -DomainName kaffee.pause -EnableRemoteManagementPort -InterfaceNameOrIndex Ethernet -Ipv4Address 10.110.4.$_ -Ipv4Dns 10.10.4.1 -Ipv4Gateway 10.0.4.1 -Ipv4SubnetMask 255.0.0.0 -MaxSize 100GB -MediaPath $driveLetter -ReuseDomainNode -AdministratorPassword $Secure
#https://docs.microsoft.com/en-us/powershell/module/nanoserverimagegenerator/new-nanoserverimage?view=win10-ps

New-VM -VHDPath C:\NanoServerImageGenerator\wdc$_.vhdx -Generation 2 -MemoryStartupBytes 2GB -Name wdc$_ -SwitchName Management
#https://technet.microsoft.com/de-de/library/hh848537.aspx

Add-VMNetworkAdapter -VMName wdc$_ -Name Storage -SwitchName Storage

Add-VMNetworkAdapter -VMName wdc$_ -Name Heartbeat -SwitchName Heartbeat

Add-VMNetworkAdapter -VMName wdc$_ -Name LiveMigration -SwitchName LiveMigration

New-VHD –Path C:\NanoServerImageGenerator\wdfAc$_.vhdx –SizeBytes 100GB -Dynamic

Add-VMHardDiskDrive -VMName wdc$_ -Path C:\NanoServerImageGenerator\wdfAc$_.vhdx

New-VHD –Path C:\NanoServerImageGenerator\wdfBc$_.vhdx –SizeBytes 100GB -Dynamic

Add-VMHardDiskDrive -VMName wdc$_ -Path C:\NanoServerImageGenerator\wdfBc$_.vhdx

New-VHD –Path C:\NanoServerImageGenerator\wdfCc$_.vhdx –SizeBytes 100GB -Dynamic

Add-VMHardDiskDrive -VMName wdc$_ -Path C:\NanoServerImageGenerator\wdfCc$_.vhdx

Start-VM -VMName wdc$_

}

Get-VM wdc*

if ((Get-WindowsFeature RSAT-Clustering).InstallState -eq ‘Available’)
{
Install-WindowsFeature RSAT-Clustering, RSAT-Clustering-PowerShell, RSAT-Clustering-Mgmt, RSAT-Clustering-CmdInterface, RSAT-Clustering-AutomationServer
}
###

#$Secure = Read-Host -AsSecureString

#$User_Name=“kaffee“+“\administrator“

#$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User_Name,$Secure

2..2 | % {

$User_Name=”wdc$_” + “\administrator“

$User_Name

$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User_Name,$Secure

$ps_wdc=New-PSSession -VMName wdc$_ -Credential $Credential

$var_Management = (Get-VMNetworkAdapter -VMName wdc$_ | Where-Object {($_.SwitchName -like ‘Management’)})

$var_Storage = Get-VMNetworkAdapter -VMName wdc$_ | Where-Object {($_.SwitchName -like ‘Storage’)}

$var_Heartbeat = Get-VMNetworkAdapter -VMName wdc$_ | Where-Object {($_.SwitchName -like ‘Heartbeat’)}

$var_LiveMigration = Get-VMNetworkAdapter -VMName wdc$_ | Where-Object {($_.SwitchName -like ‘LiveMigration’)}

$var_Management.MacAddress

Invoke-Command -Session $ps_wdc -ScriptBlock {

Get-NetAdapter | Where-Object {($_.MacAddress.replace(“-“,””) -like ($Using:var_Management.MacAddress))} | ft InterfaceIndex, Name, InterfaceDescription, MacAddress

$var_ifIndex=Get-NetAdapter | Where-Object {($_.MacAddress.replace(“-“,””) -like ($Using:var_Management.MacAddress))}

Get-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex

Set-NetIPInterface -InterfaceIndex $var_ifIndex.InterfaceIndex -Dhcp Disabled

Remove-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex -Confirm:$false

New-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex -IPAddress 10.110.4.11$_ -PrefixLength 8 #–DefaultGateway 10.0.4.1

Set-NetRoute -InterfaceIndex $var_ifIndex.InterfaceIndex –DestinationPrefix ‘0.0.0.0/0’ -NextHop ‘10.0.4.1’

Set-DnsClientServerAddress -InterfaceIndex $var_ifIndex.InterfaceIndex -ServerAddresses („10.8.4.1“)

#Set-NetIPAddress –InterfaceIndex $var_ifIndex.InterfaceIndex –IPAddress 10.110.4.11 –PrefixLength 8 -InterfaceAlias ‘Management’

Get-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex

}

Invoke-Command -Session $ps_wdc -ScriptBlock {Get-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex}

$var_Storage.MacAddress

Invoke-Command -Session $ps_wdc -ScriptBlock {

Get-NetAdapter | Where-Object {($_.MacAddress.replace(“-“,””) -like ($Using:var_Storage.MacAddress))} | ft InterfaceIndex, Name, InterfaceDescription, MacAddress

$var_ifIndex=Get-NetAdapter | Where-Object {($_.MacAddress.replace(“-“,””) -like ($Using:var_Storage.MacAddress))}

Get-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex

Set-NetIPInterface -InterfaceIndex $var_ifIndex.InterfaceIndex -Dhcp Disabled

Remove-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex -Confirm:$false

New-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex -IPAddress 10.110.4.12$_ -PrefixLength 8

Set-DnsClientServerAddress -InterfaceIndex $var_ifIndex.InterfaceIndex -ServerAddresses („10.8.4.1“)

#Set-NetIPAddress –InterfaceIndex $var_ifIndex.InterfaceIndex –IPAddress 10.110.4.12 –PrefixLength 8 -InterfaceAlias ‘Storage’

Get-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex

}

Invoke-Command -Session $ps_wdc -ScriptBlock {Get-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex}

$var_Heartbeat.MacAddress

Invoke-Command -Session $ps_wdc -ScriptBlock {

Get-NetAdapter | Where-Object {($_.MacAddress.replace(“-“,””) -like ($Using:var_Heartbeat.MacAddress))} | ft InterfaceIndex, Name, InterfaceDescription, MacAddress

$var_ifIndex=Get-NetAdapter | Where-Object {($_.MacAddress.replace(“-“,””) -like ($Using:var_Heartbeat.MacAddress))}

Get-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex

Set-NetIPInterface -InterfaceIndex $var_ifIndex.InterfaceIndex -Dhcp Disabled

Remove-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex -Confirm:$false

New-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex -IPAddress 10.110.4.13$_ -PrefixLength 8

Set-DnsClientServerAddress -InterfaceIndex $var_ifIndex.InterfaceIndex -ServerAddresses („10.8.4.1“)

#Set-NetIPAddress –InterfaceIndex $var_ifIndex.InterfaceIndex –IPAddress 10.110.4.13 –PrefixLength 8 -InterfaceAlias ‘Heartbeat’

Get-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex

}

Invoke-Command -Session $ps_wdc -ScriptBlock {Get-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex}

$var_LiveMigration.MacAddress

Invoke-Command -Session $ps_wdc -ScriptBlock {

Get-NetAdapter | Where-Object {($_.MacAddress.replace(“-“,””) -like ($Using:var_LiveMigration.MacAddress))} | ft InterfaceIndex, Name, InterfaceDescription, MacAddress

$var_ifIndex=Get-NetAdapter | Where-Object {($_.MacAddress.replace(“-“,””) -like ($Using:var_LiveMigration.MacAddress))}

Get-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex

Set-NetIPInterface -InterfaceIndex $var_ifIndex.InterfaceIndex -Dhcp Disabled

Remove-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex -Confirm:$false

New-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex -IPAddress 10.110.4.14$_ -PrefixLength 8

Set-DnsClientServerAddress -InterfaceIndex $var_ifIndex.InterfaceIndex -ServerAddresses („10.8.4.1“)

#Set-NetIPAddress –InterfaceIndex $var_ifIndex.InterfaceIndex –IPAddress 10.110.4.14 –PrefixLength 8 -InterfaceAlias ‘LiveMigration’

Get-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex

}

Invoke-Command -Session $ps_wdc -ScriptBlock {Get-NetIPAddress -InterfaceIndex $var_ifIndex.InterfaceIndex}

}

Get-VMNetworkAdapter -VMName wdc1, wdc2

New-Cluster -name wdNanoCluster1 -Node wdc1, wdc2 -StaticAddress 10.110.4.10 -NoStorage

Invoke-Command -VMName wdc$_ -Credential $Credential -ScriptBlock {Get-NetFirewallRule -DisplayGroup „*Remote*“ | ft DisplayName, Enabled}

Invoke-Command -VMName wdc$_ -Credential $Credential -ScriptBlock {Get-NetFirewallRule -DisplayGroup „*Remote*“ | Enable-NetFirewallRule}

Invoke-Command -VMName wdc$_ -Credential $Credential -ScriptBlock {Get-NetFirewallRule –Name “FPS-ICMP4-ERQ-Out” | Enable-NetFirewallRule}

###

#Beispiel 4

###

$mountResult = Mount-DiskImage -ImagePath “D:\WindowsServer2016.iso” -PassThru

$mountResult | Get-Volume

$driveLetter = (($mountResult | Get-Volume).DriveLetter) + “:\”

$isoPath=$driveLetter + “NanoServer\NanoServerImageGenerator”

$isoPath

If(Test-Path “C:\NanoServerImageGenerator”)
{
}
else
{
Copy-Item $isoPath -Destination C:\ -Recurse
}

cd C:\NanoServerImageGenerator

Get-ExecutionPolicy
# Bei Bedarf: Set-ExecutionPolicy RemoteSigned
# https://technet.microsoft.com/de-de/library/ee176961.aspx

Import-Module .\NanoServerImageGenerator -Verbose

#get-help New-NanoServerImage -ShowWindow

#get-help New-NanoServerImage -Online

dir $driveLetter

Get-VMSwitch

New-VMSwitch -Name Management -SwitchType Private
New-VMSwitch -Name Storage -SwitchType Private
New-VMSwitch -Name Heartbeat -SwitchType Private
New-VMSwitch -Name LiveMigration -SwitchType Private
Get-VMSwitch

$Secure = Read-Host -AsSecureString
#https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/convertto-securestring?view=powershell-5.1

1..3 | % {
New-NanoServerImage -DeploymentType Guest -Edition Datacenter -TargetPath .\wdc$_.vhdx -Clustering -Compute -ComputerName wdc$_ -Containers -DomainName gemuetliche.pause -EnableRemoteManagementPort -InterfaceNameOrIndex Management -Ipv4Address 10.104.4.$_ -Ipv4Dns 10.4.4.1 -Ipv4Gateway 10.0.4.1 -Ipv4SubnetMask 255.255.255.0 -MaxSize 100GB -MediaPath $driveLetter -Package Microsoft-NanoServer-DNS-Package -ReuseDomainNode -Storage -AdministratorPassword $Secure
#https://docs.microsoft.com/en-us/powershell/module/nanoserverimagegenerator/new-nanoserverimage?view=win10-ps

New-VM -VHDPath C:\NanoServerImageGenerator\wdc$_.vhdx -Generation 2 -MemoryStartupBytes 1GB -Name wdc$_ -SwitchName Management
#https://technet.microsoft.com/de-de/library/hh848537.aspx

Add-VMNetworkAdapter -VMName wdc$_ -Name Storage -SwitchName Storage
Add-VMNetworkAdapter -VMName wdc$_ -Name Heartbeat -SwitchName Heartbeat
Add-VMNetworkAdapter -VMName wdc$_ -Name LiveMigration -SwitchName LiveMigration

New-VHD –Path C:\NanoServerImageGenerator\wdfAc$_.vhdx –SizeBytes 10GB
Add-VMHardDiskDrive -VMName wdc$_ -Path C:\NanoServerImageGenerator\wdfAc$_.vhdx
New-VHD –Path C:\NanoServerImageGenerator\wdfBc$_.vhdx –SizeBytes 10GB
Add-VMHardDiskDrive -VMName wdc$_ -Path C:\NanoServerImageGenerator\wdfBc$_.vhdx
New-VHD –Path C:\NanoServerImageGenerator\wdfCc$_.vhdx –SizeBytes 10GB
Add-VMHardDiskDrive -VMName wdc$_ -Path C:\NanoServerImageGenerator\wdfCc$_.vhdx
Start-VM -VMName wdc$_

$User_Name=”wdc$_”+”\administrator”
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User_Name,$Secure
Invoke-Command -VMName wdc$_ -Credential $Credential -ScriptBlock {Get-NetFirewallRule -DisplayGroup „*Remote*“ | ft DisplayName, Enabled}
Invoke-Command -VMName wdc$_ -Credential $Credential -ScriptBlock {Get-NetFirewallRule -DisplayGroup „*Remote*“ | Enable-NetFirewallRule}
Invoke-Command -VMName wdc$_ -Credential $Credential -ScriptBlock {Get-NetFirewallRule –Name “FPS-ICMP4-ERQ-Out” | Enable-NetFirewallRule}
}
###
New-Cluster -name wdNanoCluster1 -Node wdc1, wdc2 -StaticAddress 10.104.4.100 -S2D

###

###

#Beispiel 5

###

Get-VM
Start-VM ag-core1,ag-core2
.\HOSTNAME.EXE
Get-WindowsFeature *iscsi*
Install-WindowsFeature FS-iSCSITarget-Server -IncludeAllSubFeature -IncludeManagementTools
Get-Command new*iscsi*
Get-Help New-IscsiVirtualDisk -ShowWindow
New-IscsiVirtualDisk -Path C:\iSCSI\iSCSI-Target-1.vhdx -SizeBytes 500MB -UseFixed
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/new-iscsivirtualdisk?view=win10-ps
New-IscsiServerTarget -TargetName “iSCSI-Ziel-1” -InitiatorId @(“IPAddress:10.101.2.201″,”IPAddress:10.101.2.202”)
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/new-iscsiservertarget?view=win10-ps
Add-IscsiVirtualDiskTargetMapping -TargetName “iSCSI-Ziel-1” -DevicePath “C:\iSCSI\iSCSI-Target-1.vhdx”
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/add-iscsivirtualdisktargetmapping?view=win10-ps
New-IscsiVirtualDisk -Path C:\iSCSI\iSCSI-Target-2.vhdx -SizeBytes 100GB
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/new-iscsivirtualdisk?view=win10-ps
New-IscsiServerTarget -TargetName “iSCSI-Ziel-2” -InitiatorId @(“IPAddress:10.101.2.201″,”IPAddress:10.101.2.202”)
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/new-iscsiservertarget?view=win10-ps
Add-IscsiVirtualDiskTargetMapping -TargetName “iSCSI-Ziel-2” -DevicePath “C:\iSCSI\iSCSI-Target-2.vhdx”
#https://docs.microsoft.com/en-us/powershell/module/iscsitarget/add-iscsivirtualdisktargetmapping?view=win10-ps

1..2 | % {
Enter-PSSession -VMName ag-core$_
#Invoke-Command
Set-Service -Name msiscsi -StartupType Automatic
#https://blogs.msdn.microsoft.com/san/2012/07/31/managing-iscsi-initiator-connections-with-windows-powershell-on-windows-server-2012/
Get-Service -Name msiscsi
Set-Service -Name msiscsi -Status Running
Get-Service -Name msiscsi
Get-NetFirewallServiceFilter -Service msiscsi | Get-NetFirewallRule | Select DisplayGroup,DisplayName,Enabled
Get-NetFirewallServiceFilter -Service msiscsi | Get-NetFirewallRule | Set-NetFirewallRule -Enabled True
Get-NetFirewallServiceFilter -Service msiscsi | Get-NetFirewallRule | Select DisplayGroup,DisplayName,Enabled
New-IscsiTargetPortal –TargetPortalAddress 10.1.2.1
#https://docs.microsoft.com/en-us/powershell/module/iscsi/new-iscsitargetportal?view=win10-ps
Get-IscsiTarget | Connect-IscsiTarget #-IsMultipathEnabled $true -IsPersistent $true
Get-IscsiTarget | ft NodeAddress, IsConnected
Get-iSCSIConnection
Get-iSCSISession
Get-iSCSISession | Get-Disk | ft Size,OperationalStatus
Get-Disk | Where-Object IsOffline –Eq $True
Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk -IsOffline $false
Get-Disk | ft Size,OperationalStatus
Exit-PSSession
}

#Bei Bedarf
#Auf beiden Knoten Cmdlet “iscsicpl” ausführen und die Einstellungen mit Hilfe von  iSCSI-Initiator konfigurieren.

#Bei Bedarf
#Auf beiden Knoten “diskpart” aufrufen und die Einstellungen anpassen
#diskpart
#list disk
#select disk 1
#online disk
#attributes disk clear readonly
#create partition primary
#select partition 1
#format fs=ntfs label=(Zeuge) quick
#list partition
#list disk
#select disk 2
#online disk
#attributes disk clear readonly
#create partition primary
#select partition 1
#format fs=ntfs label=(Daten) quick
#list partition

Get-WindowsFeature *cluster*

Invoke-Command -ComputerName ag-core1,ag-core2 -ScriptBlock {Install-WindowsFeature failover-clustering -IncludeAllSubFeature -IncludeManagementTools}

#Bei Bedarf
Stop-VM -Name ag-core1,ag-core2 -Confirm -Force
Get-VM ag-core1,ag-core2

Get-VMProcessor -VMName * | ft VMName, ExposeVirtualizationExtensions

Set-VMProcessor -VMName ag-core1,ag-core2 -ExposeVirtualizationExtensions $true

Get-VMProcessor -VMName ag-core1,ag-core2 | ft VMName, ExposeVirtualizationExtensions

Get-VMMemory ag-core1,ag-core2 | ft VMName, DynamicMemoryEnabled

#Bei Bedarf
Set-VMMemory ag-core1,ag-core2 -DynamicMemoryEnabled $false
Get-VMMemory ag-core1,ag-core2 | ft VMName, DynamicMemoryEnabled

Get-VMMemory -VMName ag-core1,ag-core2 | fl VMName, Startup
#Bei Bedarf
#Mindestens 4GB
Set-VM -name ag-core1,ag-core2 –MemoryStartupBytes 4GB
Get-VMMemory -VMName ag-core1,ag-core2 | fl VMName, Startup

Get-VMNetworkAdapter -VMName ag-core1,ag-core2 | ft VMName, MacAddressSpoofing
#Bei Bedarf
Get-VMNetworkAdapter -VMName ag-core1,ag-core2 | Set-VMNetworkAdapter -MacAddressSpoofing On
Get-VMNetworkAdapter -VMName ag-core1,ag-core2 | ft VMName, MacAddressSpoofing

Start-VM -Name ag-core1,ag-core2 -Confirm

Get-VM -Name ag-core1,ag-core2

Invoke-Command -ComputerName ag-core1,ag-core2 -ScriptBlock {Install-WindowsFeature Hyper-V -IncludeAllSubFeature -IncludeManagementTools}

Restart-VM msclustercore1,msclustercore2

Get-VM msclustercore1,msclustercore2

Install-WindowsFeature RSAT-Clustering-PowerShell, RSAT-Clustering-Mgmt

get-command test*cluster*
Test-Cluster -Node msclustercore1,msclustercore2 -Include Storage
get-command new*cluster*
New-Cluster -Name mscluster1 -Node msclustercore1,msclustercore2 -StaticAddress 10.202.4.200