Skip to content

Instantly share code, notes, and snippets.

@juneb
Last active February 16, 2023 10:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juneb/43cf2e566e4c8003d6e19e48821b48eb to your computer and use it in GitHub Desktop.
Save juneb/43cf2e566e4c8003d6e19e48821b48eb to your computer and use it in GitHub Desktop.
Creates and opens a custom menu INF for PrimalScript and PowerShell Studio.
<#
.SYNOPSIS
Creates and opens a custom menu INF for PrimalScript and PowerShell Studio.
.DESCRIPTION
This script creates a CustomMenu.inf file, the file that PrimalScript and
PowerShell Studio use as the source for custom tools.
When you use the Program parameter, the script creates a CustomMenu.inf in
the default location, $env:SystemDrive\SAPIEN\<Program>\<latest>.
When you use the Path parameter, the script creates a CustomMenu.inf in the
the specified path. The resulting custom menu appears in the program only when
the specified path is the current path.
This script will not overwrite a current CustomMenu.inf file. If the file
exists, it just opens it.
.PARAMETER Path
Specifies a path for the CustomMenu.inf file. This parameter is mandatory.
.PARAMETER Program
Specifies a program. Select "PowerShell Studio" or "PrimalScript". This
parameter is mandatory.
.LINK
https://www.sapien.com/blog/2013/01/08/powershell-studio-2012-with-git-subversion-and-mercurial-oh-my/
https://www.sapien.com/blog/2015/10/01/powershell-studio-2015-new-custom-menu-features-git-template/
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.120
Created on: 5/2/2016 3:19 PM
Created by: June Blender
Organization: SAPIEN Technologies, Inc
Filename: New-CustomMenuItem.ps1
===========================================================================
#>
[CmdletBinding(DefaultParameterSetName = 'ProgramSet')]
param
(
[Parameter(ParameterSetName = 'PathSet',
Mandatory = $true)]
[ValidateScript({ Test-Path $_ })]
[string]
$Path,
[Parameter(ParameterSetName = 'ProgramSet',
Mandatory = $true)]
[ValidateSet('PowerShell Studio', 'PrimalScript')]
[String]
$Program
)
$Content = @'
[Menu]
1=Command Name 1;command line 1
2=Command Name 2;command line 2
[Application]
1=Command Name 1;command line 1
2=Command Name 2;command line 2
'@
switch ($PSCmdlet.ParameterSetName)
{
PathSet {
$CustomMenuPath = $Path
break;
}
ProgramSet {
if ($ProgramPath = Get-ChildItem "$env:SystemDrive\ProgramData\SAPIEN\$Program*")
{
($CustomMenuPath = $ProgramPath | Sort-Object Name -Descending | Select-Object -First 1).FullName
break;
}
else
{
throw "Can't find $Program directory in $env:SystemDrive\ProgramData\SAPIEN\."
}
}
}
if (!(Test-Path -Path $CustomMenuPath\CustomMenu.inf))
{
if (!(Set-Content -Value $Content -Path $CustomMenuPath\CustomMenu.inf -ErrorAction SilentlyContinue -PassThru))
{
throw "Cannot create CustomMenu.inf in $CustomMenuPath"
}
}
Invoke-Item $CustomMenuPath\CustomMenu.inf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment