WOW! Whatever the PowerShell team did to the latest version of PowerShell Version 5 kicked my butt!!!!! Many things that used to work in my scripts, no longer worked. It took me seven hours to fix all the issues the latest V5 found in this script.
Version 1.20 22-Apr-2016
- Fixed numerous issues discovered with the latest update to PowerShell V5
- Color variables needed to be [long] and not [int] except for $wdColorBlack which is 0
- Changed from using arrays to populating data in tables to strings
- Fixed several incorrect variable names that kept PDFs from saving in Windows 10 and Office 2013
- Fixed the rest of the $Var -eq $Null to $Null -eq $Var
- Removed a couple of invalid $Table references
- Removed blocks of old commented out code
- Removed the 10 second pauses waiting for Word to save and close.
One of the testers for another script was having issues getting a PDF file created in Windows 10 with Office 2013. There were no issues with prior versions of Windows or PowerShell. I built a test VM with Windows 10 and Office 2013 both 64-bit. Sure enough, I had the same problem – no PDF. I was able to create a Word document but when I looked at the report a lot of the data was missing and most of the colors used for the Word tables were gone. Whiskey Tango Foxtrot?????
I added an $error.clear() at the top of the script and then $error as the last line. Holy Crap Batman!!! Over 2000 lines were copied into Notepad++. There were just over 500 errors!!!
There were several typos in variable names (like $D0main instead of $Domain) that even though I had Strictmode enabled had never been flagged. One of the bad variables was one that kept the PDF file from being saved.
The most confusing to this non-programmer/developer was “invalid type casting”. It took me a good while to figure out that meant all but one of my color variables needed to be cast/defined as [long] and not [int]. Why that makes a difference I have no idea. Only the $wdColorBlack variable, which is 0, had to stay [int] or it got the “invalid casting” error.
I spent several hours cleaning up the rest of all the remaining fixable errors listed by $error. Now to go through all the other scripts and fix the same issues so you can use the scripts with the latest version of PowerShell 5.
What really puzzles me is that all these issues have been in the various scripts since Word support was added in January 2013. How the scripts actually worked beats the heck out of me.
I want to give a HUGE shout out to an extremely thorough and persistent tester David M. for sticking through and helping me find a bunch of other issues in the scripts and causing me seven hours of work.
There are so many changes to the script I bumped the version number to 1.20.
You can always find the most current script by going to http://carlwebster.com/where-to-get-copies-of-the-documentation-scripts/