The PowerShell error about parameter name ComputerName appears when a cmdlet or function doesn’t accept the -ComputerName switch.
Seeing this PowerShell message right when you want to hit a remote server can feel frustrating. The good news is that the text “a parameter cannot be found that matches parameter name computername” points to a narrow set of causes, and each one has a clear way out.
This guide walks through what the error really means, where it comes from in different PowerShell versions, and the exact checks you can run to fix it. You will also see safer patterns for remote work and daily tasks so the same message stays out of your scripts.
What This Error Means In Powershell
PowerShell raises this message when it cannot match the name -ComputerName to any parameter on the command you called. The problem is not the value you typed after the switch. The problem is that the command itself does not expose a parameter with that name in the current session.
Under the hood PowerShell uses a parameter binder. That binder looks at the command metadata, finds the defined parameters, and maps the arguments you typed. When it reaches -ComputerName and finds no match, it throws a ParameterBindingException and prints the line “a parameter cannot be found that matches parameter name computername”.
This message might look similar to syntax errors, but it sits in a different class. The parser already accepted your line. The binder then failed to connect the named argument to a real parameter on the command that has been loaded into the session.
A Parameter Cannot Be Found That Matches Parameter Name ComputerName Causes And Fixes
In real use, this message comes from four main patterns. Spotting which one applies to your line of code tells you how to respond.
- Cmdlet never had -ComputerName Some commands only act on the local machine, so the authors never added any remote computer switch.
- Cmdlet dropped -ComputerName in newer PowerShell Several classic commands included the switch in Windows PowerShell 5.1 but not in PowerShell 7, so scripts that run fine in one console break in another.
- Module or snap-in not loaded If you call an advanced function from a module that is not imported, PowerShell may route the name to a different item from the path, one that does not carry the expected parameter.
- Custom function misses the parameter When you write a function with a
paramblock and forget to add$ComputerName, the call site can still type-ComputerName, but the binder has nothing to work with.
PowerShell does not try to guess your intent. If the parameter name is wrong for that command in that session, the binder stops and prints the error. The fix is always to align your code with a command that truly accepts -ComputerName or to pick a remote pattern that fits the current version.
That pattern is helpful because it tells you what not to chase. The issue is rarely DNS, firewall rules, or WinRM when this exact text appears. The line you typed never reached the point of talking to a remote host, because argument binding failed before the command tried to connect.
Check The Cmdlet And Powershell Version
Before you change your script, confirm what command PowerShell is calling and what parameters it really knows about in this console. That quick scan often shows the mismatch right away.
- Confirm the command type Run
Get-Command NameOfCommandto see whether it is a cmdlet, function, alias, or external tool. Aliases and external tools ignore PowerShell style parameters. - List the parameters Run
Get-Command NameOfCommand | Select-Object -ExpandProperty Parametersto print every available parameter. Scan the keys for anything close toComputerName. - Check help for ComputerName Use
Get-Help * -Parameter ComputerNameto see which commands in this session offer that switch at all. If your command is missing from the list, it cannot accept the parameter in this version. - Compare PowerShell versions Look at
$PSVersionTable.PSVersion. Scripts written on Windows PowerShell often rely on parameters that do not exist in the same module on PowerShell 7, especially around remoting and computer targeting.
Many admins first hit the message when moving a script from a Windows 10 server box with Windows PowerShell 5.1 to a host that runs PowerShell 7. In that move, commands such as Get-Service and Restart-Computer can lose their -ComputerName switch, even though the names still work on older machines.
Mixed shells on the same host raise another trap. You might open a Windows PowerShell console to write the script, then run it later inside a PowerShell 7 session because that icon sits on your taskbar. The script file does not know the difference, but the engine loading the modules does, which changes the parameter set in subtle ways.
Use The Right Tool For Remote Computers
On Windows PowerShell, many classic cmdlets accept -ComputerName and quietly handle their own remote calls. PowerShell 7 places more weight on general remoting commands instead, which means you often reach for Invoke-Command or CIM based commands to hit remote hosts.
Once you know that your target command does not know about -ComputerName in this console, pick a pattern that still reaches the remote machine while keeping the error away.
- Wrap the command in Invoke-Command Use
Invoke-Command -ComputerName SERVER1 -ScriptBlock { Get-Service }whenGet-Serviceitself does not accept a computer switch but runs fine inside a script block. - Use CIM for inventory style tasks Commands such as
Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName SERVER1often replace older WMI approaches and still include a computer name parameter. - Create a PSSession first For repeat work, open a session with
New-PSSession -ComputerName SERVER1, then callInvoke-Command -Session $session -ScriptBlock { commands }to run a batch of tasks without mixing remoting logic into each cmdlet. - Switch to a local pattern when needed Some commands like
Stop-Processonly act locally. In those cases, keep them inside a script block that already runs on the target machine instead of forcing a remote parameter that does not exist.
The core idea is that the remote target belongs to a remoting layer, not to every individual cmdlet. Once that layer is in place with Invoke-Command or a session, your inner commands can stay simple and still run on the correct machine.
When You Still Need Windows Powershell
Some shops still depend on modules that never shipped a PowerShell 7 compatible release. In that case, using Windows PowerShell for those scripts can be the cleaner choice. You can keep both shells installed, route older scripts to the Windows PowerShell console, and write new work for PowerShell 7 with remoting patterns from the start.
Common Cmdlets And Computername Alternatives
The table below shows how to approach a few common tasks that often trigger the “a parameter cannot be found that matches parameter name computername” message when scripts move between hosts.
| Task | Older Pattern | Safer Pattern Now |
|---|---|---|
| Check services on a remote server | Get-Service -ComputerName SERVER1 |
Invoke-Command -ComputerName SERVER1 -ScriptBlock { Get-Service } |
| Restart a remote computer | Restart-Computer -ComputerName SERVER1 |
Invoke-Command -ComputerName SERVER1 -ScriptBlock { Restart-Computer -Force } |
| Read OS info from a remote host | Get-WmiObject Win32_OperatingSystem -ComputerName SERVER1 |
Get-CimInstance Win32_OperatingSystem -ComputerName SERVER1 |
| Stop a process on a remote server | Stop-Process -ComputerName SERVER1 |
Invoke-Command -ComputerName SERVER1 -ScriptBlock { Stop-Process -Name notepad } |
Use this pattern as a mental template. When a script line uses -ComputerName on a cmdlet that no longer accepts it, wrap the cmdlet in a remoting block or switch to a CIM based call that still offers a computer switch.
Extend the table in your own notes and add rows for the modules you touch every week.
Fix Custom Functions That Trigger The Error
Sometimes the message does not come from a built in cmdlet at all. It comes from one of your own functions or from a function in a module that you imported. PowerShell prints the same text, but the fix sits in your function definition.
- Open the function source If the function lives in your profile or a script file, open that file and find the
functionblock that matches the name on the error line. - Check the param block Inside the function, inspect the
param()block. Look for a parameter named$ComputerNameand check the spelling and casing. - Add or rename the parameter When the block has no such entry, add a new parameter or rename the existing one so that the name after the dash in your call matches the defined parameter.
- Reload the function Save the file, dot source it again, or reload the module so that the new parameter list reaches your current PowerShell session.
Function calls follow the same rules as cmdlets. If the function metadata lists a parameter with the name you typed, PowerShell binds it. If not, the binder throws the same error text even though all of the code in the body would work fine once the parameter list matches.
When the function belongs to a shared module, treat the parameter change with care. Adding a new $ComputerName parameter that was never there can break existing callers that passed arguments by position. Use parameter attributes and clear help text so colleagues understand the new options.
Tips To Prevent This Parameter Error Next Time
Once you fix the current script or session, take a few small steps so that the “a parameter cannot be found that matches parameter name computername” line shows up far less often in new work.
- Rely on Get-Help and Get-Command Before adding
-ComputerNameto a call, run the help and command listing so you know the parameter really exists in this module and version. - Set a standard PowerShell version When teams mix Windows PowerShell and PowerShell 7, scripts drift. Agree on a default version for shared scripts, and test remote tasks there first.
- Prefer remoting patterns over ad hoc switches Build scripts around
Invoke-Command, CIM sessions, or persistent PSSessions. That design keeps most remote logic in one spot and reduces surprises when a cmdlet sheds-ComputerNamein a future release. - Keep modules under source control Store your custom function libraries in version control and review parameter changes. When you add or remove
$ComputerName, update the calling scripts in the same change.
The next time you see this error, you will know that PowerShell is not upset about the target server name. It is simply telling you that the command in front of it is not a match for the -ComputerName switch in this session, and that a small change in version, cmdlet choice, or function definition will get the run back on track.
