Linked Questions
27 questions linked to/from Is there a way to create an alias to a cmdlet in a way that it only runs if arguments are passed to the alias?
3 votes
0 answers
2k views
Powershell Set-Alias for long command [duplicate]
I'm trying to create a powershell alias for my ng build command which is fairly long. node --max_old_space_size=4096 .\node_modules\@angular\cli\bin\ng build --configuration=debug --watch Aliasing the ...
1 vote
0 answers
2k views
make new-alias run a specific python file [duplicate]
I have a python program that creates a numbered list up to the value i enter I have tried using new-alias numberlist "python C:\path\to\file\numberlist.py" to do this but it returns the ...
410 votes
22 answers
482k views
Using PowerShell to write a file in UTF-8 without the BOM
Out-File seems to force the BOM when using UTF-8: $MyFile = Get-Content $MyPath $MyFile | Out-File -Encoding "UTF8" $MyPath How can I write a file in UTF-8 with no BOM using PowerShell? ...
55 votes
10 answers
46k views
Pass function as a parameter
I've written function 'A' that will call one of a number of other functions. To save re-writing function 'A', I'd like to pass the function to be called as a parameter of function 'A'. For example: ...
17 votes
1 answer
14k views
PowerShell pass all parameters received in function, and handle parameters with spaces
I am a novice with PowerShell. In Msys2 (or Lnux), I have defined a function npp npp () { ${NPP_PATH} "$@" } such that if I call from the command prompt npp it launches Notepad++ (as ...
17 votes
1 answer
68k views
Powershell's equivalent to Linux/Unix 'ls -al'
Is there a PowerShell equivalent to the ls -al command in Linux/Unix? I tried to find something, but it said there wasn't an equivalent command in PowerShell.
9 votes
3 answers
2k views
How to use a function to get objects from a pipeline as strings?
Command that output the result in string instead of objects: ls | Out-String -Stream Output: Directory: C:\MyPath\dir1 Mode LastWriteTime Length Name ---- ...
4 votes
2 answers
3k views
Can you redirect Tee-Object to standard out?
I am writing a script and I want to pass the values but also see them displayed Get-Content data.txt | Tee-Object | data_processor.exe But Tee-Object always requests a file and I just want to see it ...
7 votes
1 answer
4k views
Powershell: What's the difference between Alias and Function?
Im setting up my powershell profile to create aliases of commonly used commands. On Microsoft's documentation it says, if I want to make an alias for a command with parameters, I should make the value ...
5 votes
3 answers
2k views
PowerShell Transcript is not capturing git output
I'm writing a script that will perform some git actions and I want to use Start-Transcript to monitor it. The transcript is however missing most of the git output. I've tried to pipe the git output ...
-4 votes
1 answer
6k views
Remove blank lines in powershell output... Generally
I am a newcomer to PS scripting. I have found that, generally speaking, PS adds a lot of newlines to output of its commands. I am giving below a couple of examples of what I found somewhat generalized ...
5 votes
2 answers
2k views
How to achieve @args splatting in an advanced function in Powershell?
Consider the following simple function: function Write-HostIfNotVerbose() { if ($VerbosePreference -eq 'SilentlyContinue') { Write-Host @args } } And it works fine: Now I want to ...
2 votes
1 answer
2k views
Add Write-Progress to Get-Job/Wait-Job
I'm using the below code to display the results of PowerShell Jobs with a timeout of 120 seconds. I would like to enhance this code by incorporating Write-Progress (based on number of jobs completed)....
2 votes
1 answer
2k views
What is the simplest way to make Alias in powershell?
I was wondering if there's any simple way to make aliases for powershell like cmd. For example: In cmd, doskey art=php artisan $* where $* is optional. Currently, I'm using the following alias in ...
1 vote
1 answer
1k views
Wrapper function for cmdlet - pass remaining parameters
I'm writing a function that wraps a cmdlet using ValueFromRemainingArguments (as discussed here). The following simple code demonstrates the problem: works function Test-WrapperArgs { Set-...
3 votes
2 answers
983 views
how can i do a alias in powershell to start notepad++
How can I do a alias in powershell to start notepad++ have Start notepad++ and have alias i wanna combinate that set-alias -name notepad -value start notepad++ but i get this error Set-Alias : A ...
2 votes
3 answers
996 views
What is the recommended way of calling external commands in PowerShell including error handling?
I would like to call external commands from PowerShell Core such as Git, Python or other proprietary executables, but I want the call to throw when the exit code is non-zero while respecting ...
3 votes
2 answers
1k views
Show content of hashtable when Pester test case fails
Problem When a Hashtable is used as input for Should, Pester outputs only the typename instead of the content: Describe 'test' { It 'test case' { $ht = @{ foo = 21; bar = 42 } $ht |...
4 votes
1 answer
493 views
How to create a wrapper for an advanced function cmdlet that uses dynamic parameters
I'm trying to create a wrapper (proxy) for Pester's Should cmdlet. Possible use cases include transparent logging of test input even in case of success and improve the way Pester logs objects of ...
2 votes
1 answer
590 views
Powershell: Forward arguments and pipeline input to alias function
How do I forward all pipeline input and arguments to a command inside an alias function. For example if I wanted to alias tail function tail { coreutils tail @args } works fine with tail -n 5 test....
2 votes
2 answers
675 views
How can I prepend a timestamp to every PowerShell output line?
I am trying to make PowerShell automatically prepend a timestamp to every line subsequent to invoking my custom ShowTimeStamps function. The function attempts to redirect output thru a filter that ...
4 votes
1 answer
440 views
Ways to detect an external program in the pipeline has exited
In a pipeline like GenerateLotsOfText | external-program | ConsumeExternalProgramOutput when external-program exits, the pipeline just keeps on running until GenerateLotsOfText completes. Suppose ...
2 votes
1 answer
435 views
How to splat Powershell arguments in the same manner that Python *args, **kwargs work
Both python and powershell support a form of splatting array and named arguments as function inputs, a very useful feature. However powershell seem to be internally inconsistent somewhat. I am trying ...
0 votes
1 answer
256 views
Powershell functions do not work with spaces
I am trying to set up an alias in Powershell. For some weird reason, they do not support spaces (arguments), so I have to create a function instead I ran this command: function glo { git log --oneline ...
1 vote
1 answer
198 views
PowerShell, the syntax of help-function
Exploring the difference between help and get-help I did: cd Function: get-content help all the input-parameter are defined like: [string]${Name} $=initiate a variable, {} a hashtable?? Thanks ...
1 vote
2 answers
100 views
Extend cd functionality while retaining Set-Location switches
I want to extend the functionality of cd but retain all of the existing parameters of Set-Location. So I created a function go which does a bunch of additional stuff and then aliased cd to it (I had ...
1 vote
1 answer
94 views
PowerShell - change DarkRed color
A little colorblindness problem: [ConsoleColor]::DarkRed (and also Red) is like nearly invisible for me. I have to select the text in order to be able to read it. I've been configuring some stuff in ...