dsccommunity / dsccommunity/ComputerManagementDsc

VirtualMemory: $pageFileName in Set-Resource block ends up null via Join-Path when setting new page file

Open
#233 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs investigation question
Dominant language
PowerShell
Stars
338
Forks
80
PR merge metrics
No merged PRs in 30d

Description

Details of the scenario you tried and the problem that is occurring

Hello, please forgive any missteps of mine in common practices around contributing to open source projects. I read through the contributing guidelines, but this is still my first time.

I'm trying to put together a short DSC config to be able to change the drive letter of the temporary storage drive attached to Azure VMs when they're first provisioned. The drive is set as the D: drive letter and has the page file assigned to it by default. So in order to change it, I must clear the page file, change the drive letter, and re-assign the page file. I'm performing this via the Azure DSC VM extension.

During testing, I encountered an error stating the parameter PageFileName could not be processed as it was a null or empty string.

After some further testing with editing my local copy of the VirtualMemory resource code, I found that it is the Join-Path cmdlet that populates the $pageFileName variable in the Set-TargetResource block which is returning a null value for some reason. When I tested a replacement line:

$pageFileName = $driveInfo.Name + 'pagefile.sys'

The resource functioned as expected.

Verbose logs showing the problem
Suggested solution to the issue

The replacement line I mentioned does function, but I do understand the value in using Join-Path. I'm at a loss as to why it would be returning a null value the way it's written. When I tested Join-Path outside of DSC, it functioned as expected using the driveInfo.Name value.

The DSC configuration that is used to reproduce the issue (as detailed as possible)
Configuration AzureDiskPagingConfig
{
    Import-DscResource -ModuleName ComputerManagementDsc
    Import-DscResource -ModuleName StorageDsc
    Import-DscResource -ModuleName PSDscResources

    Node $AllNodes.NodeName
    {
        LocalConfigurationManager
        {
            RebootNodeIfNeeded = $true
            ActionAfterReboot = 'ContinueConfiguration'
        }

        WaitForDisk Disk0
        {
            DiskId = 0
            RetryIntervalSec = 10
            RetryCount = 10
        }

        Disk OSVolume
        {
            DiskId = 0
            DriveLetter = 'C'
            PartitionStyle = 'MBR'
            AllowDestructive = $true
            DependsOn = '[WaitForDisk]Disk0'
        }

        WaitForDisk Disk1
        {
            DiskId = 1
            RetryIntervalSec = 10
            RetryCount = 10
        }

        VirtualMemory ClearPagingSettings
        {
            Type = 'NoPagingFile'
            Drive = $Node.OldDriveLetter
            DependsOn = '[WaitForDisk]Disk1'
        }

        Script TempVolume
        {
            GetScript = {
                @{
                    GetScript  = $GetScript
                    SetScript  = $SetScript
                    TestScript = $TestScript
                    Result     = (Get-Partition -DiskNumber 1).DriveLetter
                }
            }
            SetScript = {
                $partition = Get-WmiObject -Class Win32_Volume -Filter "Label = 'Temporary Storage'"
                Set-WmiInstance -InputObject $partition -Arguments @{DriveLetter = $using:Node.NewDriveLetter; Label = 'Temporary Storage'}
                $partition = Get-WmiObject -Class Win32_Volume -Filter "Label = 'Temporary Storage'"
                Write-Verbose "Set Temporary Storage drive to $($partition.DriveLetter)"
            }
            TestScript = {
                $partition = Get-WmiObject -Class Win32_Volume -Filter "Label = 'Temporary Storage'"
                if (!$partition) { Return $true }
                $testPath = "$($partition.DriveLetter)\DATALOSS_WARNING_README.txt"
                if (!(Test-Path -Path $testPath)) { Return $true }
                Return $false
            }
        }

        WaitForDisk Disk1PostChange
        {
            DiskId = 1
            RetryIntervalSec = 10
            RetryCount = 10
            DependsOn = '[Script]TempVolume'
        }

        VirtualMemory PagingSettings
        {
            Type = 'SystemManagedSize'
            Drive = $Node.NewDriveLetter
            DependsOn = '[WaitForDisk]Disk1PostChange'
        }
    }
}

@{
    AllNodes = @(
        @{
            NodeName = "*"
            OldDriveLetter = "D:"
            NewDriveLetter = "T:"
        },
        @{
            NodeName = 'localhost'
        }
    )
}
The operating system the target node is running

OsName : Microsoft Windows Server 2016 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture : 64-bit
WindowsBuildLabEx : 14393.3085.amd64fre.rs1_release.190703-1816
OsLanguage : en-US
OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

PSVersion 5.1.14393.3053
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.3053
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

6.4.0.0 - recently installed via install-module

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the VirtualMemory resource's Set-TargetResource block and reproduce the Azure DSC configuration on the stated Windows Server 2016 and PowerShell 5.1 versions. Inspect the Join-Path inputs used for $pageFileName and verify the resource can clear and then assign the page file without a null or empty PageFileName error.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.