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

Other Issue:

How to make scroll wheel zoom work in Windows 10






Or Set Mapkeys:

mapkey zi @MAPKEY_NAMEZoom in;@MAPKEY_LABEL>Zoom in;\
mapkey(continued) ~ Activate `main_dlg_cur` `ProCmdViewZoomIn.view`;
mapkey zo @MAPKEY_NAMEZoom out;@MAPKEY_LABEL>Zoom out;\
mapkey(continued) ~ Activate `main_dlg_cur` `ProCmdViewZoomOut.view`;
mapkey $F2 @MAPKEY_NAMEDefine Zoom box;@MAPKEY_LABEL>Zoom In;%zi;
mapkey $F3 @MAPKEY_NAMEZoom Out;@MAPKEY_LABEL>Zoom Out;%zo;


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

2020-11-03

Hp Server Windows Server CPU Loading 0%

遇到了莫名其妙的問題來記錄一下

因為 VM 效能突然變得超差,幾乎無反應無法運作
檢查發現 Hyper-V Host 出現 CPU Loading 0% 的情況
這台是 HP Server 運作 Windows Server