70-740, Teil 3.1.7. Virtuelle Computer mit Windows PowerShell Direct konfigurieren

70-740, Teil 3.1.7.

Virtuelle Computer mit Windows PowerShell Direct konfigurieren

Ideen für die Recherche im Web:

technet new-vm

Zum Nachschlagen:

https://docs.microsoft.com/de-de/virtualization/hyper-v-on-windows/quick-start/create-virtual-machine

https://docs.microsoft.com/de-de/windows-server/virtualization/hyper-v/manage/manage-windows-virtual-machines-with-powershell-direct?view=vsts

https://docs.microsoft.com/en-us/powershell/module/hyper-v/copy-vmfile?view=win10-ps

Übungen:

#Beispiel 1

Get-VM

Start-VM pm-core1

Get-VM pm-core1

Enter-PSSession -VMName pm-core1

Exit-PSSession

Invoke-Command -VMName pm-core1 -ScriptBlock {Get-NetAdapter | fl NetworkAddresses}

$var_PSSession_pm_core1 = New-PSSession -VMName pm-core1

dir C:\ISOs\Windows2016.ISO

Invoke-Command -Session $var_PSSession_pm_core1 -ScriptBlock {dir C:\ISOs\}

Copy-Item -ToSession $var_PSSession_pm_core1 -Path C:\ISOs\14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_DE-DE.ISO -Destination C:\ISOs\

###

#Beispiel 2

New-VHD –Path c:\ISOs\wd-core1.vhdx –SizeBytes 100GB -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path c:\ISOs\wd-core1A.vhdx –SizeBytes 200GB -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path c:\ISOs\wd-core1B.vhdx –SizeBytes 200GB -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
New-VHD –Path c:\ISOs\wd-core1C.vhdx –SizeBytes 200GB -LogicalSectorSizeBytes 4096 -PhysicalSectorSizeBytes 4096
#https://docs.microsoft.com/en-us/powershell/module/hyper-v/new-vhd?view=win10-ps

$var_SwitchName=(Get-VMSwitch).Name

$var_SwitchName

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

Add-VMHardDiskDrive -VMName wd-core1 -Path c:\ISOs\wd-core1A.vhdx

Add-VMHardDiskDrive -VMName wd-core1 -Path c:\ISOs\wd-core1B.vhdx

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

Add-VMDvdDrive -VMName wd-core1 -Path ‘C:\ISOs\14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_DE-DE.iso’

Get-VMDvdDrive -VMName wd-core1

(Get-VMFirmware wd-core1).BootOrder

$var_DVDDrive=Get-VMDvdDrive -VMName wd-core1

Set-VMFirmware -VMName wd-core1 -FirstBootDevice $var_DVDDrive

(Get-VMFirmware wd-core1).BootOrder

Set-VM -VMName wd-core1 –AutomaticStartAction Nothing

#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

Invoke-Command -VMName dv-core1 -Credential $Credential -ScriptBlock {ipconfig}

Invoke-Command -VMName dv-core1 -Credential $Credential -ScriptBlock {Get-NetIPAddress}

Invoke-Command -VMName dv-core1 -Credential $Credential -ScriptBlock {(Get-ComputerInfo).osName}

Enter-PSSession -VMName dv-core1 -Credential $Credential

Get-ComputerInfo

Exit-PSSession

Enter-PSSession -Session $var_pssession1_jb

hostname

Exit-PSSession

dir C:\Users\Administrator\Desktop\Lernmaterial\Windows2016.ISO

Invoke-Command -VMName dv-core1 -Credential $Credential -ScriptBlock {dir C:\ISOs\}

Copy-VMFile -VMName dv-core1 -SourcePath “C:\Users\Administrator\Desktop\Lernmaterial\Windows2016.ISO” -DestinationPath “C:\ISOs\Windows2016.ISO” -CreateFullPath -FileSource Host

###

#Beispiel 3

$VM_Name=Read-Host -Prompt (“Geben Sie bitte den VM-Namen ein.”)

New-VM -NewVHDPath C:\ISOs\$VM_Name.vhdx -NewVHDSizeBytes 100GB -Generation 2 -Name $VM_Name -Path C:\ISOs\ -SwitchName Switch1

Get-VMScsiController -VMName $VM_Name | Add-VMDvdDrive -Path C:\ISOs\Windows2016.ISO

Set-VM $VM_Name -AutomaticStartAction Nothing -AutomaticStopAction Save -MemoryStartupBytes 2GB -StaticMemory

$DVD_Drive = Get-VMDvdDrive -VMName $VM_Name

Set-VMFirmware -VMName $VM_Name -FirstBootDevice $DVD_Drive

Start-VM $VM_Name

Get-VM

Enter-PSSession -VMName dv-core1

hostname

Exit-PSSession

dir C:\Users\Administrator\Desktop\Lernmaterial\Windows2016.ISO

Invoke-Command -VMName dv-core1 -Credential $Credential -ScriptBlock {dir C:\ISOs\}

Copy-VMFile -VMName dv-core1 -SourcePath “C:\Users\Administrator\Desktop\Lernmaterial\Windows2016.ISO” -DestinationPath “C:\ISOs\Windows2016.ISO” -CreateFullPath -FileSource Host