HyperVTools.psm1



(ls $PSScriptRoot\Functions).FullName | foreach { . $_ }



#------------------------------



#------------------------------


#------------------------------



function New-UnattendedWindowsInstall {

    robocopy F:\ E:\Install\Windows_en_2004 /MIR /W:1 /R:1

    dism /Get-WimInfo /WimFile:E:\Install\Windows_en_2004\sources\install.esd

    dism /Export-Image /SourceImageFile:E:\Install\Windows_en_2004\sources\install.esd /SourceIndex:6 /DestinationImageFile:E:\Install\Windows_en_2004\sources\install.wim /Compress:Max /CheckIntegrity



}




#
# Examples
#

<#
$VMImageName = "Windows10-2004-NL-Image"
$Path = "F:\Hyper-V"
$IsoFile = "D:\OneDrive - JaapTerlouw\ISO\Windows_nl_2004.iso"
 
 
 
$VMName = "TestF"
$Path = "F:\Hyper-V"
$AutopilotJSONfile = "E:\AutopilotConfigurationFiles\G17 - GGZOB\AutopilotConfigurationFile.json"
$ImageVHD = "E:\Hyper-V\Windows10-2004-NL-Image\Virtual Hard Disks\Windows10-2004-NL-Image.vhdx"
 
 
# New-HyperVImage -VMName $VMImageName -Path $Path -IsoFile $IsoFile -StartVM -Connect
 
# New-HyperVAutopilotVM -VMName $VMName -Path $Path -AutopilotJSONfile $AutopilotJSONfile -ImageVHD $ImageVHD -StartVM -Connect
 
 
 
 
#Move-VMStorage -Name HMP-Testzolder5 -DestinationStoragePath 'E:\Hyper-V\HMP-TestZolder5' -AsJob
#>


function Invoke-Prepare-GuestVM {
    
    cd\
    #net user Admin Admin

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 

    Set-ExecutionPolicy RemoteSigned -Force
    Install-PackageProvider -Name NuGet -Force
    Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

    $env:Path += ";C:\Program Files\WindowsPowerShell\Scripts"
    Install-Script Get-WindowsAutopilotInfo
    Install-Module WindowsAutopilotIntune
    #Install-Module AzureAD

    
    #--------

    
    net user admin /delete
    C:\Windows\System32\Sysprep\sysprep.exe /generalize /oobe /shutdown

}

function Start-Online-Autopilot {

    Start-Process powershell
    
    Get-WindowsAutopilotInfo.ps1 -Online -GroupTag "SharedUD" -AssignedComputerName "G17-TestJaap3" -AssignedUser "enrollment@ggzob365.onmicrosoft.com"

    Stop-Computer

}

function Invoke-RAMAutopilotHashUpload {
    #cd\
    #net user Admin Admin
    
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    $username = "admin@ggzob365.onmicrosoft.com"
    $password = ConvertTo-SecureString -String "1234" -AsPlainText -Force

    $Creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $password



    #Set-ExecutionPolicy RemoteSigned -Force
    Install-PackageProvider -Name NuGet -Force
    Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

    $env:Path += ";C:\Program Files\WindowsPowerShell\Scripts"
    Install-Script Get-WindowsAutopilotInfo
    Install-Module WindowsAutopilotIntune
    #Install-Module AzureAD

    Connect-MSGraph -Credential $Creds

    Get-WindowsAutopilotInfo.ps1 -Online -GroupTag "VM" -Credential $Creds


}
#Invoke-RAMAutopilotHashUpload




function Set-VMNotesSerialNumber {

    $SerialNr = Invoke-Command -VMName Test01 -Credential (Get-Credential -Message s -UserName Admin1) -ScriptBlock { (Get-ComputerInfo).BiosSeralNumber }
    return $SerialNr
    
}




###########################################################
###########################################################

function Get-Losse-HyperVCommandos {
    
    Set-VMProcessor -VMName vm_name -ExposeVirtualizationExtensions $true

}