November 2018
Intermediate to advanced
566 pages
17h 15m
English
The main idea here seems to be the verbose logging of actions. Modify the script to look like the following:
function New-LogFile { param ( # The path to the log file [Parameter(Mandatory=$false)] [string] $Path = "$HOME/random/LogDir", # The name of the log file [Parameter(Mandatory=$false)] [string] $Name = 'MyLog.log' ) try { Write-Verbose "Creating the file, $Name at $Path." New-Item "$Path/$Name" -ItemType File -ErrorAction Stop } catch [System.IO.DirectoryNotFoundException] { Write-Verbose "System.IO.DirectoryNotFoundException encountered." Write-Verbose "Creating the directory, $Path." New-Item $Path -ItemType Directory -Force Write-Verbose "Calling the function." New-LogFile } catch { Write-Verbose "Catch-all. There ...Read now
Unlock full access