Instantly share code, notes, and snippets.

Embed
What would you like to do?
Write out to file. Append.
<# Example start to create file #>
$log_path = "C:\Backup Archive Logs\" + (get-date -format yyyy-MM-dd);
# create that directory if it doesn't exist yet
if( (Test-Path $log_path) -eq $false) {
mkdir $log_path;
# file name
$file_name = $log_path + "\log.txt";
# create file
New-Item $file_name -type file;
# Adding content - Use Add-Content command. Each call makes new line, or use `n.
Add-Content $file_name ("Log starting: " + (Get-Date)) ;
# Add line break for output file
Add-Content $file_name ("") ;
# Make tab-separated header corresponding to output
Add-Content $file_name ("Action`tInstance Name`tDatabase Name`tSize`tSource`tDestination") ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment