Put this at the top of your file:
$Logfile = "D:\Apps\Logs\$(gc env:computername).log"
Function LogWrite
{
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}
Then replace your Write-host
calls with LogWrite
.
More Related Contents:
- String handling from Powershell script
- Powershell script to delete 15 days old .txt files [duplicate]
- How to create a zip archive with PowerShell?
- How to run an EXE file in PowerShell with parameters with spaces and quotes
- Fastest Way to get a uniquely index item from the property of an array
- PowerShell IE9 ComObject has all null properties after navigating to webpage
- PowerShell script to check an application that’s locking a file?
- PowerShell script runs when pasted into the PowerShell window, but not when run from shortcut
- Lambda Expression in Powershell
- save PSCredential in the file
- How do I write a PowerShell script that accepts pipeline input?
- PowerShell’s Invoke-RestMethod equivalent of curl -u (Basic Authentication)
- How do I Start a job of a function i just defined?
- Remove files and foldes on Azure before a new deploy from VSTS
- Pass object[] into a function in PowerShell
- try, catch doesent seem to work
- Specifying *.xls filter in Get-ChildItem also returns *.xlsx results
- Inserting a date into SQL
- PowerShell – get process ID of called application
- Delete all files and folders but exclude a subfolder
- Start-Process with PowerShell.exe exhibits different behavior with embedded single quotes and double quotes
- Can the following Nested foreach loop be simplified in PowerShell?
- Add Write-Progress to Get-Job/Wait-Job
- How to send email with PowerShell
- powershell function switch param with string array
- Boolean literals in PowerShell
- How to uninstall an app that another user installed?
- Uploading file to HTTP via Powershell
- Strange behavior for PowerShell Length after ForEach method
- Unix newlines to Windows newlines (on Windows)