I'm very new to PowerShell and PowerShell scripting. While adding argument handling code to a Papyrus script compilation PowerShell script that I found at NexusMods.com, I started getting this parse-error: ParserError: C:\Program Files (x86)\GOG Galaxy\Games\Skyrim Anniversary Edition\Tools\Papyus Compiler\mtpc.ps1:
264 Line |
264 | Write-Host -ForegroundColor White "InputPath: '$InputPath'"
| ~~~~~~~~~~~~
| Unexpected token '$InputPath'"
Write-Host -ForegroundColor White "Input: '$Input'"
Write-Host
| -ForegroundColor White "In: '$In'"
Write-Host -ForegroundColor White "SourcePath: '$SourcePath'"
| Write-Host -ForegroundColor White "Source: '$Source'"
Write-Host -ForegroundColor White "Src:
| '$Src'" Write-Host -ForegroundColor White "InputsPath: '$InputsPath'"
Write-Host -ForegroundColor White
| "Inputs: '$Inputs'"
Write-Host -ForegroundColor White "Ins: '$Ins'"
Write-Host -ForegroundColor | White "SourcesPath: '$SourcesPath'"
Write-Host -ForegroundColor White "Sources: '$Sources'"
PS C:\Program Files (x86)\GOG Galaxy\Games\Skyrim Anniversary Edition\Tools\Papyus Compiler>
Here are the lines from the script that are causing the errors:
$InputsPath = ( "hi", " ", "there" )
$Inputs = ( "you", " ", "too" )
Write-Host -ForegroundColor White "InputPath: '$InputPath'"
Write-Host -ForegroundColor White "Input: '$Input'"
Write-Host -ForegroundColor White "In: '$In'"
These lines are followed by more Write-Host statements, but those aren't erroring.
The strange thing is that these lines worked before I added this IsStringArrayEmpty function, which is actually defined before the above code:
#
# Function IsStringArrayEmpty
#
# That verifies that the specified parameters aren't using
# more than one parameter name form at the same time.
#
function IsStringArrayEmpty {
[CmdletBinding()]
# Enables advanced function features
param(
[Parameter( ValueFromRemainingArguments = $true )]
[object[]] $AllArgs
)
try {
#
# Give $Array a value,
# so that something will
# show in the error message
# if an error occurs before
# $Array is assigned its
# real value.
#
$Array = 'Unknown"
#
# If there are any, but only one,
# named parameter with a value.
#
if( $( $AllArgs.Count ) -eq 2 ) {
#
# Assign the named parameters
# value, the value after the
# parameter named, to $Array
#
$Array = $( $AllArgs[ 1 ] )
}
elseif( $( $args.Count ) -eq 1 ) {
#
# Assign the first positional parameter
# to $array
#
$Array = $( $args[ 0 ] )
}
else {
throw # Unsuported number of arguments!
}
#
# Validate the paramete\`s value is now an
# $Array is a string Array
#
if( $Array -as [Sting[]] ) {
#
# Return True if the array exists and has
# elements else false.
#
return ( $Array -and $Array.Count -gt 0 )
}
throw # All other errors
}
catch {
# Any error
Write-Error `
-ErrorAction Stop `
-Message `
"IsArrayEmpty - " + `
"Only one parameter($Array) " + `
"of type array of strings is allowed!"
}
} # End of function IsStringArrayEmpty.
The IsStringArrayEmpty function is called as follows, after the code that is getting the parse-error:
$count = 0
if( -not( IsStringArrayEmpty $InputsPath ) ) { ++$count }
if( -not( IsStringArrayEmpty $Inputs ) ) { ++$count }
But with the script parse error occurring these lines aren't executing.
Thank You