Related to the previous article, as part of creating the files, I need to create a separate folder as well, so that the generated reports will be stored in the folder. To make sure that the folder is already available, and if not, create a new folder, a simple two liner script will be sufficient. Though it is too small, wanted to share with the community.
$LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
################# Set the Current Path as Execution Path ####################
$scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
Set-Location $scriptBase
############# set the Error Preference ################
$ErrorActionPreference = "Stop"
# Create Log File Folder
if(!(TEST-PATH ".Logs-$LogTime"))
{
NEW-ITEM ".Logs-$LogTime" -type Directory
}
Happy Coding,
Sathish Nadarajan.
Leave a comment