GPS.ps1 -type find -value places
or
GPS.ps1 find places
The first one is simpler
you only need to pass one parameter
but you can’t add a none value parameter like this
GPS.ps1 -calcroad
The second one is more complicated
but you can pass a none value parameter like this
GPS.ps1 -type calcroad
and you could pass the parameter without its name
So i am struggle to choose between two of them ,or anyother suggestion?
Not 100% sure I’ve grasped the question, but my feeling is you’re doing two different things in one script.
I would separate each action into its own function. Save the script containing the functions as a module file* (GPS.psm1), import the module, then call the individual functions with their own parameters.
Example
function Find-Place {
[CmdletBinding()]
param (
[Parameter()]
[string]
$PlaceName
)
"$PlaceName is in England."
}
function Add-Place {
[CmdletBinding()]
param (
[Parameter()]
[string]
$PlaceName
)
"$PlaceName has been added to the database with record id 42."
}
function Remove-Place {
[CmdletBinding()]
param (
[Parameter()]
[int]
$RecordId
)
"Record Id: $RecordId has been removed from the database."
}
function Get-Distance {
[CmdletBinding()]
param (
[Parameter()]
[string]
$Start,
[Parameter()]
[string]
$End
)
"The distance between $Start and $End is 19 miles"
}
PS E:\Temp\Test> Import-Module .\GPS.psm1
PS E:\Temp\Test> Add-Place -PlaceName 'Sunnydale'
Sunnydale has been added to the database with record id 42.
PS E:\Temp\Test> Remove-Place 42
Record Id: 42 has been removed from the database.
PS E:\Temp\Test> Get-Distance -Start 'London' -End 'Sydney'
The distance between London and Sydney is 19 miles
PS E:\Temp\Test>
*This is the simplest type of module, you could create a ‘proper’ module with a manifest and separate files for each function and a structure to separate public/private functions. I would encourage you to research this.