diff --git a/LANCommander.PowerShell/Cmdlets/Write-ReplaceContentInFile.cs b/LANCommander.PowerShell/Cmdlets/Write-ReplaceContentInFile.cs index 3a96f72..5160e91 100644 --- a/LANCommander.PowerShell/Cmdlets/Write-ReplaceContentInFile.cs +++ b/LANCommander.PowerShell/Cmdlets/Write-ReplaceContentInFile.cs @@ -20,12 +20,17 @@ namespace LANCommander.PowerShell.Cmdlets protected override void ProcessRecord() { - var contents = File.ReadAllText(FilePath); - var regex = new Regex(Pattern, RegexOptions.Multiline); + if (File.Exists(FilePath)) + { + var contents = File.ReadAllText(FilePath); + var regex = new Regex(Pattern, RegexOptions.Multiline); - var result = regex.Replace(contents, Substitution); + contents = regex.Replace(contents, Substitution); - WriteObject(result); + File.WriteAllText(FilePath, contents); + + WriteObject(contents); + } } } }