Skip to content

Instantly share code, notes, and snippets.

@benf101 benf101/output to file.ps1 Secret
Created Aug 4, 2016

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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.