I'm working on a system admin script that pulls from two large/complex modules - one for error logging/reporting, and one that acts as a library for server's API. I'm getting some very strange errors that make me think the environment is being put into a bad state by something deep in those libraries. They seem to persist even after I restart the ISE/host and strip out all the complex code. Here's my current test:
set-psdebug -trace 2
pause
pause
# Initialize Paths and Filenames
$Network_Share = "\\EC2AMAZ-R2G8HFL\Backup"
pause
Outputs:
PS D:\Scripts\Scripts_7-6> D:\Scripts\Scripts_7-6\test8-11.ps1
Set-PSDebug : Cannot bind parameter 'Trace'. Cannot convert value "2" to type "System.Int32". Error: "Input string was not in a correct format."
At D:\Scripts\Scripts_7-6\test8-11.ps1:1 char:20
+ set-psdebug -trace 2
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Set-PSDebug], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.SetPSDebugCommand
Press Enter to continue...:
pause : The term 'pause' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\Scripts\Scripts_7-6\test8-11.ps1:5 char:1
+ pause
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (pause:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
: The term '' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\Scripts\Scripts_7-6\test8-11.ps1:8 char:1
+
+ ~
+ CategoryInfo : ObjectNotFound: (:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Press Enter to continue...:
PS D:\Scripts\Scripts_7-6>
If I'm reading this right, it is throwing errors about "2" not being an Int32 compatible value, the second "pause" not being a recognized command (although the first and third work as expected!) and finally that the blank line on line 8 is being interpreted as a command (although the blank lines on 2, 4, and 10 are not).
Something has really thrown my environment for a loop, and I'm not sure where to even start to untangle this. Can anyone point me towards some resources that will help me figure out what's going on?
edit: Adding the syntax for Set-PSDebug
PS D:\Scripts\Scripts_7-6>> Help Set-PSDebug
NAME
Set-PSDebug
SYNOPSIS
Turns script debugging features on and off, sets the trace level, and toggles strict mode.
SYNTAX
Set-PSDebug [-Off] [<CommonParameters>]
Set-PSDebug [-Step] [-Strict] [-Trace <Int32>] [<CommonParameters>]
DESCRIPTION
The Set-PSDebug cmdlet turns script debugging features on and off, sets the trace level, and toggles strict mode.
When the Trace parameter is set to 1, each line of script is traced as it is executed. When the parameter is set to 2, variable assignments, function calls, and script calls are also traced. If the Step parameter is specified, you are prompted before each line of the script is executed.
RELATED LINKS
Online Version: http://go.microsoft.com/fwlink/p/?linkid=289612
Debug-Process
Set-PSBreakpoint
Set-StrictMode
Write-Debug
about_Debuggers
REMARKS
To see the examples, type: "get-help Set-PSDebug -examples".
For more information, type: "get-help Set-PSDebug -detailed".
For technical information, type: "get-help Set-PSDebug -full".
For online help, type: "get-help Set-PSDebug -online"