Skip to main content
ubuntuask.com

Back to all posts

What Does "-" Do In Powershell?

Published on
3 min read
What Does "-" Do In Powershell? image

Best PowerShell Guidebooks to Buy in October 2025

1 Learn PowerShell Scripting in a Month of Lunches

Learn PowerShell Scripting in a Month of Lunches

BUY & SAVE
$50.26
Learn PowerShell Scripting in a Month of Lunches
2 PowerShell 7 for IT Professionals

PowerShell 7 for IT Professionals

BUY & SAVE
$27.12 $50.00
Save 46%
PowerShell 7 for IT Professionals
3 Learn Windows PowerShell in a Month of Lunches

Learn Windows PowerShell in a Month of Lunches

BUY & SAVE
$30.39 $44.99
Save 32%
Learn Windows PowerShell in a Month of Lunches
4 PowerShell in Depth

PowerShell in Depth

BUY & SAVE
$59.99
PowerShell in Depth
5 Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell

Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell

  • QUALITY ASSURANCE: THOROUGHLY INSPECTED FOR OPTIMAL READABILITY.
  • ECO-FRIENDLY CHOICE: SUPPORT SUSTAINABILITY BY BUYING USED BOOKS.
  • BUDGET-FRIENDLY: AFFORDABLE PRICES FOR VALUABLE LITERARY FINDS.
BUY & SAVE
$69.80
Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell
6 Windows PowerShell Step by Step

Windows PowerShell Step by Step

BUY & SAVE
$48.60 $59.99
Save 19%
Windows PowerShell Step by Step
7 Learn Windows PowerShell in a Month of Lunches

Learn Windows PowerShell in a Month of Lunches

BUY & SAVE
$31.99 $44.99
Save 29%
Learn Windows PowerShell in a Month of Lunches
8 Windows Server 2019 Automation with PowerShell Cookbook: Powerful ways to automate and manage Windows administrative tasks, 3rd Edition

Windows Server 2019 Automation with PowerShell Cookbook: Powerful ways to automate and manage Windows administrative tasks, 3rd Edition

BUY & SAVE
$61.17 $65.99
Save 7%
Windows Server 2019 Automation with PowerShell Cookbook: Powerful ways to automate and manage Windows administrative tasks, 3rd Edition
9 Pro PowerShell Desired State Configuration: An In-Depth Guide to Windows PowerShell DSC

Pro PowerShell Desired State Configuration: An In-Depth Guide to Windows PowerShell DSC

BUY & SAVE
$65.38 $99.99
Save 35%
Pro PowerShell Desired State Configuration: An In-Depth Guide to Windows PowerShell DSC
10 Learn Windows PowerShell in a Month of Lunches

Learn Windows PowerShell in a Month of Lunches

BUY & SAVE
$40.91 $44.99
Save 9%
Learn Windows PowerShell in a Month of Lunches
+
ONE MORE?

In PowerShell, the "-" character is used as a parameter indicator in commands. It is typically followed by a parameter name that modifies the behavior of the command. For example, when using the "Get-Process" command, the "-Name" parameter can be used to specify the name of the process to retrieve information about. The "-" character plays a crucial role in effectively using PowerShell commands and passing parameters to them.

How to use the "-" symbol alongside wildcard characters in Powershell filters?

In PowerShell, the "-" symbol (minus sign) can be used alongside wildcard characters in filters to exclude certain elements from the search results.

For example, to list all files in a directory except those starting with "abc", you can use the following command:

Get-ChildItem -Path "C:\Path\To\Directory" -Filter "*.txt" | Where-Object { $_.Name -notlike "abc*" }

In this command:

  • Get-ChildItem lists all files in the specified directory
  • -Filter "*.txt" filters only files with a .txt extension
  • Where-Object { $_.Name -notlike "abc*" } filters out files whose names start with "abc"

You can adjust the wildcard pattern and condition based on your specific filtering needs.

How does the "-" symbol affect Powershell parameters?

In PowerShell, the "-" symbol is commonly used to indicate named parameters in command calls. When specifying parameters in PowerShell commands, the "-" symbol prefixes the parameter name to distinguish it from the value being passed. For example, in the command Get-Process -Name "explorer", the "-" symbol indicates that "Name" is a named parameter, and it corresponds to the value "explorer".

Additionally, the "-" symbol can also be used as a subtraction operator in mathematical operations within PowerShell scripts. When used in this context, it performs arithmetic subtraction on the values provided.

How to use the "-" symbol to reference specific variables in Powershell?

In Powershell, the "-" symbol is used as the prefix for parameter names in cmdlets and functions. To reference specific variables using the "-" symbol, you can use the following syntax:

$variable1 = "Value 1" $variable2 = "Value 2"

Using "-" symbol to reference variables

Write-Host $variable1 Write-Host $variable2

In this example, the "-" symbol is used to reference the variables $variable1 and $variable2 when outputting their values using the Write-Host cmdlet.

You can also use the "-" symbol in combination with other characters, such as in variable names or parameter names, to create more complex commands and scripts in Powershell.