2020-12-01

快速調整 User Profile Disk 磁碟與分割區大小

快速調整 User Profile Disk 磁碟與分割區大小
紅色部份為應調整參數

$ExtendDiskSize = 16; #in GB

$DiskPartCommandFileName = ((Get-Location).Path + '\DiskPartCommand.txt');

$ExtendDiskSize = ($ExtendDiskSize*1024*1024*1024);
$VHDxs = Get-ChildItem -path 'C:\VirtualDisks\Pool' -Recurse -Filter "*.vhdx" | select FullName;

在不支援 Hyper-V 虛擬化技術的機器上安裝 Hyper-V Role for Powershell 指令使用

只不過想用個 Resize-VHD 指令
被罵說沒有 Hyper-V Role,但這台機器 (Azure VM) 又不支援巢狀虛擬化 (懶得去設定)
只好用指令裝起來,但要記得裝好重開機之前用第二行指令設定開機時不要跑 Hypervisor
不然應該會壞掉

dism /online /enable-feature /featurename:Microsoft-Hyper-V
bcdedit /set hypervisorlaunchtype off

2020-11-26

Rename VM Disk on Azure

$ResourceGroup = "ResourceGroupName"
$SourceDiskName = "OsDisk_12345678"
$TargetDiskName = "NewDiskName"
$VMName = "VMName"

$SourceDisk = Get-AzDisk -ResourceGroupName $ResourceGroup -DiskName $SourceDiskName

$DiskConfig = New-AzDiskConfig -SourceResourceId $SourceDisk.Id -Location $SourceDisk.Location -CreateOption Copy -DiskSizeGB $SourceDisk.DiskSizeGB -SkuName "Premium_LRS"
New-AzDisk -Disk $DiskConfig -DiskName $TargetDiskName -ResourceGroupName $ResourceGroup

$VM = Get-AzVm -ResourceGroupName $ResourceGroup -Name $VMName
$TargetDisk = Get-AzDisk -ResourceGroupName $ResourceGroup -Name $TargetDiskName
Set-AzVMOSDisk -VM $VM -ManagedDiskId $TargetDisk.Id -Name $TargetDisk.Name
Update-AzVM -ResourceGroupName $ResourceGroup -VM $VM

Remove-AzDisk -ResourceGroupName $ResourceGroup -DiskName $SourceDiskName -Force

2020-11-24

WVD Scale session hosts Without using Azure Automation

There is a lot of stuff to study to use Azure Automation.
Therefor I Write a simple PowerShell Script to manage the Scaling of WVD Pool.

You have to use the script with saved credential. (Reference)

######## Script Start ########

$ResourceGroupName = 'WVD_Infrastructure'; # ResourceGroup that contains HostPool 

$WorkDayTimeStart = '08:30';

$WorkDayTimeEnd = '18:30';


$WorkTimeAvailableSessionThreshold = 2; #New VM will Start if remain this session only

$RestTimeAvailableSessionThreshold = 0; #New VM will Start if remain this session only

$CredentailFileName = "AzCredential.txt";

2020-11-18

Get CPU Utilization Average of a VM in WVD HostPool in time period

$TimePeriod = 30;
$ResourceGroupName = 'ResourceGroupName';
$HostPoolName = 'HostPoolName';

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

$EndTime = Get-Date;
$StartTime = $EndTime.addminutes(-$TimePeriod)

Get-AzWvdUserSession -ResourceGroupName $ResourceGroupName -HostPoolName $HostPoolName | select UserPrincipalName,ActiveDirectoryUserName,ApplicationType,Name,SessionState

$HostPool = $(Get-AzWvdSessionHost -ResourceGroupName $ResourceGroupName -HostPoolName $HostPoolName);

ForEach ($HostName in $HostPool) {
$CPUUtilizationSum = 0;
        $HostCPUUtilization = Get-AzMetric -ResourceId $HostName.ResourceId -MetricNames "Percentage CPU"  -TimeGrain 00:01:00 -DetailedOutput -StartTime $StartTime -EndTime $EndTime; $HostCPUUtilization.Data.Average.ForEach({$CPUUtilizationSum += [int]$_;}); $CPUUtilizationAverage = ($CPUUtilizationSum / $HostCPUUtilization.Data.Average.Length) write-host ('' + $HostName.Name + "`t" + $CPUUtilizationAverage);
};


2020-11-10

PTC ProE / WildFire / Cero Browser Default Page Setting and RDP Lag

Default Page Setting:

    Put these into config.pro

        web_browser_homepage about:blank
        enable_3dmodelspace_browser_tab no
        enable_partcommunity_tab no
        enable_resource_browser_tab no

Lag in RDP (Remote Desktop Protocol) Session

    Set the graphics option to win32_gdi by shortcut:

        ...\bin\proe.exe -g:win32_gdi

    Or put these into config.pro

        graphics win32_gdi

Azure WVD User Profile Disk FSLogix Service Registry Settings Note

HKEY_LOCAL_MACHINE\SOFTWARE\FSLogix\Profiles

Enabled
VHDLocations
VolumeType
SizeInMBs (Hexadecimal)
IsDynamic
KeepLocalDir
DeleteLocalProfileWhenVHDShouldApply
FlipFlopProfileDirectoryName
PreventLoginWithFailure
PreventLoginWithTempProfile

For more information, please refer to this article

Convert Certification (.cer / .crt) to Base64

Convert-CertificateBinaryToBase64 -Sourcefile 'C:\Cert\Certification.cer' -DestinationFile 'C:\Cert\CertificationCER.txt'

Convert-CertificateBinaryToBase64 -Sourcefile 'C:\Cert\Certification.crt' -DestinationFile 'C:\Cert\CertificationCRT.txt'

function Convert-CertificateBinaryToBase64 {
Param( [String]$SourceFile, [String]$DestinationFile )
$Cert = Get-Content "$SourceFile" -Encoding Byte
$Content = @(

    '-----BEGIN CERTIFICATE-----'
    [System.Convert]::ToBase64String($Cert, 'InsertLineBreaks')
    '-----END CERTIFICATE-----'
);
$Content | Out-File -FilePath "$DestinationFile" -Encoding ASCII
};

Update Azure-NSG (Network Security Group) Policy with PowerShell

 Prerequest

  1. Install-Module -Name Az
  2. Connect-AzAccount
  3. NSG Name begin with OOOO_ (Notice there is a '_' after NSG Name)

Behavior:

  1. Search the old NSG with 'NSG Name_'
  2. Ensure there is only ONE NSG with 'NSG Name_'
  3. Create a new NSG with 'NSG Name_' plus Date Time and priority start from 201 (can be adjust)
  4. Check if the new NSG created successfully
  5. Find All NICs connect to the Old NSG
  6. Migrate All NICs found to the New NSG
  7. Remove Old NSG
Sample:
  1. Allow outbound connect to Azure WVD Service
  2. Allow outbound connect to 192.168.0.1
  3. Allow inbound connect from 192.168.0.1 only

Connect-AzAccount with Saved Encryped Credential in Powershell

# First Create Credential File

$CredentailFileName = "AzCredential.txt";

$Credential = Get-Credential

$UserName =[Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($Credential.UserName))
$Password = ConvertFrom-SecureString -SecureString $Credential.Password -Key (1..16)

($UserName,$Password) | Set-Content -Path $CredentailFileName