Add content to a file

# Update-FileContents.ps1

#Full path of the file
$file = 'c:\temp\important_file.txt'

# If the file exists, append a new GUID value in the file.
if ([System.IO.File]::Exists($file)) {
try {
$newValue = ((New-Guid).Guid)
Add-Content -Path $file -Value $newValue -ErrorAction STOP
Write-Host "The file [$file] has been updated with [$newValue]" -ForegroundColor Yellow
} catch {
throw $_.Exception.Message
}
}

# If the file does not exist, show a message and do nothing.
else {
Write-Host "The file [$file] could not be updated because it does not exist." -ForegroundColor Red
}