PowerShell studio compiling exe with slash to pass in parameters

Use this forum to ask questions after your subscription maintenance expires or before you buy. Need information on licensing or pricing? Questions about a trial version? This is the right place for you. No scripting questions, please.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
This topic is 1 year and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
chenzilong326
Posts: 3
Last visit: Fri Oct 28, 2022 8:24 am

PowerShell studio compiling exe with slash to pass in parameters

Post by chenzilong326 »

Code: Select all

function New-WordTree
{
	[CmdletBinding()]
	param
	(
		[Parameter(Mandatory = $true)]
		[String]$Word,
		[int]$Number = 1,
		[Switch]$AddSpace
	)
	$space = ''
	if ($AddSpace)
	{
		$space = ' '
	}
	
	1 .. $Number | ForEach-Object {
		"$word$space" * $_
	}
}

for ($i = 0; $i -lt $EngineArgs.count;)
{
	# A parameter name (-…) followed by a value (no -)
	if ($EngineArgs[$i] -like '-*' -and $EngineArgs[$i + 1] -and $EngineArgs[$i + 1] -notlike '-*')
	{
		#Add the parameter and its value to $params
		$params.Add($EngineArgs[$i], $EngineArgs[$i + 1])
		
		#Skip to the next parameter ($i = $i + 2)
		$i += 2
	} elseif ($EngineArgs[$i] -eq '-AddSpace')
	{
		$params['-AddSpace'] = $True
		
		#Go to the next item. Don't skip. ($i = $i + 1)
		$i++
	} else
	{
		throw $FormatError
	}
}

$params = @{
}
if (!$EngineArgs)
{
	New-WordTree -Word Help
} else
{
	#< parsing For-loop >
	
	if ($params.Count -gt 0)
	{
		New-WordTree @params
	}
}
https://info.sapien.com/index.php/packa ... table-file

https://photos.app.goo.gl/n8w5s3b866qCQwto6

.\New-WordTree.exe /Word PowerShell /Number 3 /AddSpace

Line 44: ScriptHalted


Try to use the sample tutorial to pass in the slash parameter why would it look like this, is there something wrong?
User avatar
brittneyr
Site Admin
Posts: 1649
Last visit: Mon Mar 18, 2024 1:47 pm
Answers: 38
Been upvoted: 30 times

Re: PowerShell studio compiling exe with slash to pass in parameters

Post by brittneyr »

First, you are getting $params twice. The second time you are trying to get params as a hash table. Inside the hash table, there is a comment saying to put the parsing loop there instead of above as you have it.
Second, you are passing your parameters with slashes, but in code you are parsing for dashes.

Please read the article again carefully.
Brittney
SAPIEN Technologies, Inc.
This topic is 1 year and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.