Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

Start-Transcript output to file only and not to file and console

$
0
0

Hello

When running a PowerShell script using Start-Transcript with in the script, is it possible stop the console output once Start-Transcript is running.

I cannot use powershell.exe -file myfile.ps1 2> C:\logfile.txt

or

powershell.exe -file myfile.ps1 2>&1 C:\logfile.txt

As the name of the log file is created witin myscript.ps1 and is different everytime.

I have gotten around the issue thus far by creating a little function like so, then sending output to the function for logging.

function log {Param($message)
$message | out-file -FilePath $logfilename -append
{

log $(
"Some text"
get-service
$Disk = [wmi]'Win32_LogicalDisk="c:"'
$Disk.FreeSpace
)

However this is a bit tedious and I simply wanted a Start and Stop Transcript at the start and end of the script file with no console output.

Any Advice most welcome

Thanks all

Ernie

 

 


Viewing all articles
Browse latest Browse all 10624

Trending Articles