diff --git a/source/Classes/002.FileSystemObject.ps1 b/source/Classes/002.FileSystemObject.ps1 index 33f1d65..1f682cf 100644 --- a/source/Classes/002.FileSystemObject.ps1 +++ b/source/Classes/002.FileSystemObject.ps1 @@ -186,6 +186,15 @@ class FileSystemObject Reasons = @() } + if ($this.Type -eq [objectType]::directory -and -not [string]::IsNullOrWhiteSpace($this.Contents)) + { + Write-Verbose -Message "Type is directory, yet parameter Contents was used." + $returnable.Reasons += @{ + Code = "File:File:ParameterMismatch" + Phrase = "Type is directory, yet parameter Contents was used." + } + } + $object = Get-Item -ErrorAction SilentlyContinue -Path $this.DestinationPath -Force if ($null -eq $object -and $this.Ensure -eq [ensure]::present) { diff --git a/source/Examples/Resources/FileSystemObject/1-FileSystemObject_CreateFileWithContent_Config.ps1 b/source/Examples/Resources/FileSystemObject/1-FileSystemObject_CreateFileWithContent_Config.ps1 new file mode 100644 index 0000000..7266d0e --- /dev/null +++ b/source/Examples/Resources/FileSystemObject/1-FileSystemObject_CreateFileWithContent_Config.ps1 @@ -0,0 +1,31 @@ +<#PSScriptInfo +.VERSION 1.0.0 +.GUID e479ea7f-0427-40a5-96ab-17215511b05f +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT DSC Community contributors. All rights reserved. +.TAGS DSCConfiguration +.LICENSEURI https://github.com/dsccommunity/FileSystemDsc/blob/main/LICENSE +.PROJECTURI https://github.com/dsccommunity/FileSystemDsc +.ICONURI https://dsccommunity.org/images/DSC_Logo_300p.png +.RELEASENOTES +First release. +#> + +#Requires -Module FileSystemDsc + +Configuration FileSystemObject_CreateFileWithContent_Config +{ + Import-DscResource -ModuleName FileSystemDsc + + node localhost + { + FileSystemObject MyFile + { + DestinationPath = 'C:\inetpub\wwwroot\index.html' + Contents = 'My PageDSC is the best' + Type = 'file' + Ensure = 'present' + } + } +}