...Because someone's gotta tell the story...


To return to the main Blog List, click Full Blog Listing.


Site Updates

Careful how you debug...

Tuesday, May 10, 2016 in Powershell (Views: 1508)
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

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.


Related Blogs You May Be Interested In:

To leave a comment, please log in and/or register.