Question:
Instead of typing PsIsContainer, I would like to be able to use either “dir” or “folder” strings. Is there a way in PowerShell that allows me to substitute one string for another, as in this case?
Answer:
I think you could get close to what you’re afer by predefining a couple of scriptblocks e.g.:
1 2 3 4 5 |
$IsDir = {$_.PsIsContainer} $IsFile = {!$_.PsIsContainer} dir | Where $IsDir dir | Where $IsFile |
Good news in PowerShell V3. This is supported natively e.g.:
1 2 3 4 5 |
dir -directory dir -ad dir -file dir -af |