32 or 64 bit version of product: 64
Operating system: Windows 10 Build 14393
32 or 64 bit OS: 64
Create the following code in a .ps1
Code: Select all
function Get-RandomPassword {
param
(
[Parameter(Mandatory = $false)]
[ValidateRange(3, 256)]
[Alias('L')]
[int]$Length = 15
)
$pswd = $null
$alphabet = $null
for ([int]$a = 35; $a –le 126; $a++) {
$alphabet += , [char][byte]$a
}
for ($loop = 1; $loop –le $length; $loop++) {
$pswd += ($alphabet | Get-Random)
}
return $pswd
}
Code: Select all
. "c:\Data\PowerShell\test\Get-RandomPassword.ps1"
Get-RandomPassword -Length 30
- 64 bit code for PowerShell v5
Resolve and include external scripts
Code: Select all
[5CG6301YZ5][21/09/2017 09:49:21]PS:27 C: ..\x64 ► .\RandomPassword.exe
Line 29: At line:28 char:24
+ for ([int]$a = 35; $a ?le 126; $a++) {
+ ~~~
Unexpected token '?le' in expression or statement.
At line:28 char:31
+ for ([int]$a = 35; $a ?le 126; $a++) {
+ ~
Missing closing ')' after expression in 'for' statement.
At line:15 char:29
+ function Get-RandomPassword {
+ ~
Missing closing '}' in statement block or type definition.
At line:28 char:37
+ for ([int]$a = 35; $a ?le 126; $a++) {
+ ~
Unexpected token ')' in expression or statement.
At line:32 char:24
+ for ($loop = 1; $loop ?le $length; $loop++) {
+ ~~~
Unexpected token '?le' in expression or statement.
At line:32 char:35
+ for ($loop = 1; $loop ?le $length; $loop++) {
+ ~
Missing closing ')' after expression in 'for' statement.
At line:32 char:44
+ for ($loop = 1; $loop ?le $length; $loop++) {
+ ~
Unexpected token ')' in expression or statement.
At line:36 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.
This same error occurs with other pieces of dot loaded code, not just the one shown here. But not all dot loaded code is affected, most compiles and runs correctly.
I also tried a combination of 32 bit code; PowerShell 3; and Windows script engine settings; all with the same result.
Thanks
G