Careful how you debug...
Tuesday, May 10, 2016 in
Powershell (Views:
1303)
I was writing a function today that seemed interesting. I was just debugging and if anyone else has issues with this, I hope it helps. When you debug your PowerShell using write-host, be careful of the return and all will be put into it. For example, this code:
I was simply trying to calculate the difference in 2 different times (the times were one second apart by a sleep command for testing - so consider this PS code...
$TimeDiff = New-TimeSpan $strStartTme $strEndTime
$TimeDiff
$TimeDiff.Hours
$TimeDiff.Minutes
$TimeDiff.Seconds
When I returned my variable to the function, I saw this...
00:00:01 0 0 1
Simply put, anything you write to the screen will be returned on the return command. So, use this with caution - as it sits, I only needed the trailing "1", not the rest.
Happy scripting and hope this helps someone else.
|