Skip to content

ReplaceText: Exception calling "Matches" error when text file is blank/empty #38

@bcwilhite

Description

@bcwilhite

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

When using the ReplaceText DSC resource in order to Append Text to a blank/empty text file, the resource throws an error "Exception calling "Matches" with "2" argument(s): "Value cannot be null. Parameter name: input"

Verbose logs showing the problem

image

Suggested solution to the issue

Enable the resource to handle blank/empty file scenarios. The issue occurs due to $fileContent having a null value, which is expected when the file is blank.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

configuration BlankFileScenario
{
    Import-DscResource -ModuleName FileContentDsc

    node localhost
    {
        ReplaceText "BlankEmpty File"
        {
            Path        = 'C:\Dev\blankFile.txt' #blank file -> Get-Content should be true when compared to $null
            Search      = 'search'
            Type        = 'Text'
            Text        = 'replacement'
            AllowAppend = $true
        }
    }
}

The operating system the target node is running

Windows Server 2012 R2

Version and build of PowerShell the target node is running

5.1.14409.1018

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

1.1.0.108

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThe issue is a bug.help wantedThe issue is up for grabs for anyone in the community.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions