Using the redirection operators as arguments to some commands generates an error # Use the new redirection tokens as a command argument echo 1> 1>> 3> 3>> 4> 4>> 5> 5>> 6> 6>> PS> echo 1> At line:1 char:8 + echo 1> + ~ Missing file specification after redirection operator. None You cannot set the IsFilter property on an unnamed script block. $sb = {$_*5} $sb.IsFilter = $true $sb2.IsFilter PS E:\> $sb.IsFilter = $true Operation is not valid due to the current state of the object. At line:1 char:1 + $sb.IsFilter = $true + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvalidOperation Use a named script block, such as {process {$_*5}} The iteration variable in a foreach statement does not have its own scope. [int[]]$n = 1,2,3 foreach ($n in 'z') {} Cannot convert value "z" to type "System.Int32[]". Error: "Cannot convert value "z" to type "System.Int32". Error: "Input string was not in a correct format."" Rename the loop iteration variable, or remove the type constraint on the foreach statement.
ERROR The following changes to error handling in Windows PowerShell 3.0 might affect scripts written in Windows PowerShell 2.0. Change Sample Error Message Workaround An expandable string with variable name is now an error. "<${}>" # expands to: <$> + "${}" + ~ Empty ${} variable reference, there should be a name between the braces. Use a variable name An expandable string with empty sub-expression now results in different output. "<$()>" # expands to: <$> No error message, result of sample is: <> Just use a '$' instead of $(). In an expandable string, an incomplete variable name is an error. $server = "msp42" $status = "online" "$server: $status" # output in V2: : online + "$server: $status" + ~~~~~~~~ Invalid variable reference. '$' was not followed by a valid variable name character. Consider using ${} to delimit the name. "${server}: $status" A parameter followed by the comma operator is treated as unary comma operator, which is not permitted when invoking a command. echo -InputObject ,1 + echo -InputObject ,1 + ~ Missing argument in parameter list. In most cases, the comma operator is a typographical error. Incorrectly typed array indices raise an exception. "abc"['def'] Cannot convert value "def" to type "System.Int32". Error: "Input string was not in a correct format." At line:1 char:1 + "abc"['def'] + ~~~~~~~~~~~~ Correct the script.
[ref] must be the final type in a type conversion sequence [object][ref] $x = 1 + [object][ref] $x = 1 + ~~~~~ Cannot use [ref] with other types in a type constraint. [ref] can't be used this way, instead write: [ref][object] $x = 1 Constant folding is not performed during parsing. 1/0 No parsing. The error is detected at runtime. No workaround. Invalid type in a trap statement causes a runtime exception, even when the trap is not hit. & {trap [foo]{}} Unable to find type [foo]: make sure that the assembly containing this type is loaded. Do not catch non-existent types Inline comments in strings generate an error $string = @" part of the string $(# comment) "@ At D:\work\a.ps1:3 char:14 + $(# comment) + ~ Missing closing ')' in subexpression. Do not place comments in code. InitialSessionState throws an exception if a referenced assembly is not found. PS > $iss = PS > $iss.Assemblies.Add("foo") PS > $iss.ThrowOnRunspaceOpenError = $true PS > $rs = PS > $rs.Open() Exception calling "Open" with "0" argument(s): "The assembly 'foo' was not loaded because no assembly was found. Please check the assembly name and try again." At line:1 char:1 + $rs.Open() + ~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DllNotFoundException Ensure any referenced assemblies exist