r/PowerShell • u/Rulylake • Dec 09 '25
Question Make custom commands in Powershell
Can you make a custom command in powershell, and if so, how?
I want to make a command that does:
git add -A
git commit -m "catchup"
git pull
In one go.
Also, feel free to tell me if making a lot of commits with the same name to pull is bad practice, though i want this for small projects with friends :)
30
Upvotes
64
u/pertymoose Dec 09 '25
Open powershell
Restart powershell
3
u/ankokudaishogun Dec 09 '25
It is. Because it's a small project with friends it's the best place to start getting in the habit of adequately commenting the commits.
Even a simple one-liner helps understanding the progression.
You will be thankfull when you'll have to go back and find the commit source of some bug.
...wait shouldn't you use
git PUSHinstead?4
u/purplemonkeymad Dec 09 '25
Functions are probably what you want, check out the about_function* help pages for some formal documentation.
Your profile is a normal starting place for getting started with them, later you can look at modules to create groupings of functions.
3
u/sidEaNspAn Dec 09 '25
If you are going to be doing a bunch of these you might want to look at creating your own module and creating functions in that module.
The advantage to placing everything in a module is that it is way more portable if you need to switch to a different system. I also find it much easier to modify the functions and reuse them.
Most basically create a file: someModule.psm1
Add the function
Function <functionName> {
All the things that you want to do
}
Save the psm1 file and drop it in any of the file locations listed under $env:PSModulePath
1
u/Spoonie_Frenzy Dec 11 '25
About_functions ?
1
u/SrBlackVoid Dec 09 '25
Honestly, I would create an alias in Git for this one in your global config. Then you can call it in any of your shells (including PowerShell).
I have one set "git kaboom" which basically is a combination of git restore and git clean -fd
-1
u/lerun Dec 09 '25
Have a look at Crescendo?
https://learn.microsoft.com/en-gb/powershell/utility-modules/crescendo/overview?view=ps-modules
-2
u/arslearsle Dec 09 '25
Check out function/advanced functions
Here is a simple example that accept pipeline input:
function Get-StringNoNum
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true
)]
[String[]]
$InputString
)
$regex = "\D"
If($inputString -match $regex)
{
Write-Debug "Regular expression: [$($inputString)]"
Write-Verbose "Before [$($inputString)]"
$inputString = $inputString -replace $regex,''
Write-Verbose "After [$($inputString)]"
}
RETURN $InputString;
}
<#
#Example
@( 'abc123_:;', '456', '789' ) | foreach{
$_ | Get-StringNoNum -Verbose:
}#Foreach
#>