0

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"
user1953403
  • 103
  • 3

1 Answers1

3

Your command contains an invisible character following 2, which is why 2 isn't recognized as an integer, and the same problem analogously affects the end of the second pause statement line.

The invisible character in question is ZERO WIDTH SPACE, U+200B.

This answer contains function Debug-String, which can help you detect such problems.

A simple fix is to delete place the cursor at the end of the affected lines and pressing Backspace; when in doubt, delete and re-type each affected line.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    That did the trick. I thought I checked for control characters already, this is the first time that Notepad++ didn't display a character for me. Much obliged for the expertise. – user1953403 Aug 12 '21 at 03:30
  • Glad to hear it, @user1953403; my pleasure. – mklement0 Aug 12 '21 at 03:33