Created
          April 22, 2019 21:57 
        
      - 
      
- 
        Save noahpeltier/970e66026d509b7ee002bf2539e07440 to your computer and use it in GitHub Desktop. 
    Will write contents to a log with a time stamp -Error switch for writing to a seperate log for errors if need
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Function Write-Log() { | |
| [CmdletBinding()] | |
| Param( | |
| [switch]$Error, | |
| [string]$Message | |
| ) | |
| if ($Error) { | |
| $timestamp = (get-date -uformat "%Y%m%d-%H.%M.%S -").ToString() | |
| Add-content -path $ErrorLog -Value "$timestamp : $Message" | |
| } | |
| Else { | |
| $timestamp = (get-date -uformat "%Y%m%d-%H.%M.%S -").ToString() | |
| Add-content -path $LogFile -Value "$timestamp : $Message" | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment