Empty Dumping variable

Hi,

I am using a script to dump all variables from a TS:

# Determine where to do the logging 
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment 
$logPath = $tsenv.Value("_SMSTSLogPath") 
$logFile = "$logPath\$($myInvocation.MyCommand).log" 

# Start the logging 
Start-Transcript $logFile 

# Write all the variables and their values 
$tsenv.GetVariables() | % { Write-Host "$_ = $($tsenv.Value($_))" } 

# Stop logging 
Stop-Transcript 

I paused the TS and open x:\windows\temp\smstslog\dumpvar.ps1.log and see:

From x:\windows\temp\smstslog\smsts.log, I get all variables appearing but nothing in dumpvar.log... grrrr

Any idea?

September 1st, 2015 11:25am

Well power shell doesn't log write-host in the transcript.

for that you need Write-Output

Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 11:29am

Hi,

The problem is the same. The result is unchange.

# Determine where to do the logging 
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment 
$logPath = $tsenv.Value("_SMSTSLogPath") 
$logFile = "$logPath\$($myInvocation.MyCommand).log" 

# Start the logging 
Start-Transcript $logFile 

# Write all the variables and their values 
#$tsenv.GetVariables() | % { Write-Host "$_ = $($tsenv.Value($_))" } 
$tsenv.GetVariables() | % { Write-output "$_ = $($tsenv.Value($_))" } 

# Stop logging 
Stop-Transcript 

September 1st, 2015 12:49pm

I could be wrong, but I don't think Start-Transcript is supposed to work within a script like this.

Why not simply use out-file instead of transcripting though?

Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 1:17pm

Why do you need to dump all of the var into a txt file if you saw the output properly in log.

Are you looking for a specific variable ?

Also you could simply use something like this $tsenv.GetVariables() | out-file x:\var.txt

No need to use the complex transcript and log file location.

September 1st, 2015 1:17pm

Hi,

The out-file is just providing variable names and not the content.

Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 1:44pm

Hi,

Sound Start-Transcscript begin with PowerShell 5 and I am using PowerShell 4.... So I will need to workaround.

September 1st, 2015 2:05pm

Start-transcript started from powershell version 3 

https://technet.microsoft.com/en-us/library/hh849687(v=wps.620).aspx

And you need to add the value so you get the actual value i meant for you to send the output to a file after you list the value it was a simple example and not to be taken as his.

can'T test right now but simply adding a output file after or configuring a specific file in the transcript

Start-Transcript "x:\var.txt"

Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 2:20pm

Hi,

This is doing the job:

$tsenv.GetVariables() | % { Write-output "$_ = $($tsenv.Value($_))" } | sort | out-file $logFile

September 1st, 2015 2:38pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics