Score:0

Custom script extension for drive letter override in Azure VM creation

ch flag

I am able to run the below script within the VM without any error

gwmi win32_pagefilesetting
$pf=gwmi win32_pagefilesetting
$pf.Delete()
Restart-Computer –Force
Get-Partition -DriveLetter "D" | Set-Partition -NewDriveLetter "T"
$TempDriveLetter = "T"
$TempDriveLetter = $TempDriveLetter + ":"
$drive = Get-WmiObject -Class win32_volume -Filter “DriveLetter = '$TempDriveLetter'”
#re-enable page file on new Drive
$drive = Get-WmiObject -Class win32_volume -Filter “DriveLetter = '$TempDriveLetter'”
Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{ Name = "$TempDriveLetter\pagefile.sys"; MaximumSize = 0; }
Restart-Computer -Force

and when I am trying to run the script via a custom script extension, I am getting the following error: Error screenshot

Script reference: https://stackoverflow.com/questions/58015765/drive-letter-override-in-azure-vm-creation

Score:0
fi flag

You can achieve this using the PowerShell DSC extension. The following DSC code will assign the T: letter to the first data disk, set the page file and reboot the server.

Configuration SetPageFile {

Import-DscResource -ModuleName ComputerManagementDsc
Import-DscResource -ModuleName StorageDSC

Node localhost {

    LocalConfigurationManager {
        RebootNodeIfNeeded = $true
    }

    WaitforDisk Disk2
    {
        DiskId           = 2
        RetryIntervalSec = 30
        RetryCount       = 3
    }

    Disk Disk2 {
        DiskId      = 2
        DriveLetter = 'T'
        DependsOn   = '[WaitForDisk]Disk2'
    }

    VirtualMemory PagingSettings
    {
        Type        = 'CustomSize'
        Drive       = 'T'
        InitialSize = '2048'
        MaximumSize = '2048'
        DependsOn   = '[Disk]Disk2'
    }
}

}

Add the extension to the VM specifying the following settings

enter image description here

You can find the zip file in my GitHub repo. Upload it to a storage account and select it when you click on "Browse" in the VM extension configuration.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.