Dummy learning Powershell Please help

Hi Guys
New to Powershell - jobless training at home myself


  • when i run from powershell core
    gsv -Name M* -ComputerName
    i get Get-Service: A parameter cannot be found that matches parameter name ‘ComputerName’.

however when i run from normal powershell from the same machine i get
PS C:\Users\rahimm1> gsv -Name M* -ComputerName localhost

Status Name DisplayName

Stopped MapsBroker Downloaded Maps Manager
Stopped McpManagementSe… McpManagementService
Stopped MessagingServic… MessagingService_c53fc
Stopped MicrosoftEdgeEl… Microsoft Edge Elevation Service (M…
Stopped MixedRealityOpe… Windows Mixed Reality OpenXR Service
Running mpssvc Windows Defender Firewall
Stopped MSDTC Distributed Transaction Coordinator
Stopped MSiSCSI Microsoft iSCSI Initiator Service
Stopped msiserver Windows Installer
Stopped MsKeyboardFilter Microsoft Keyboard Filter

can someon please explain to me why this is

Welcome to the forum. :wave:t4:

I assume you’re using different versions of PowerShell, don’t you? :wink:

You may compare the version 7.2

with the version 5.1

Newer version do not have the parameter -ComputerName anymore. You will have to use explicit remoting with Invoke-Command instead. :wink:

Regardless of that … when you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

thanks so much your a star - really enjoyin this stuff

PS C:\Users\Administrator> Invoke-Command -ComputerName labserver -ScriptBlock {Get-Service} | select-string “M”

with the above string it searches for everything with the letter M included in a service name but not service names starting with M

Also I tried this

$Cred = Get-Credential -Credential “mopower\Administrator”
$ScriptBlock = {
Get-Service -Name “dps”
$ServiceStatus = Invoke-Command -ComputerName labserver -Credential $Cred -ScriptBlock $ScriptBlock -ArgumentList “$Service”

when i put this into ISE - runs the command but shows no output

I think you had the right idea to begin with just need to sort out parameters.
Recommendation, update the local help files and review examples in whatever version you are using. The included examples are usually decent.

Get-Help Get-Service -Examples
Get-Help Invoke-Command -Parameter ScriptBlock  #or any other parameter name
Get-Help Invoke-Command -Examples
1 Like

Great to hear that. :wink: BUT!!! Please format your code as code. :pray:t3: You can read in my first answer how to do that.

First of all … you should filter INSIDE the script block. :point_up_2:t4:
Then …
If you want to limit the output to services where the name starts with an “M” you could use the cmdlet by itself:

Get-Service -Name M*

or you use a filter with Where-Object where you could apply even more complex filter rules if needed. In this simple case this would enough:

Get-Service | 
    Where-Object {$_.Name -like 'M*'}

Of course it does not. :man_shrugging:t4: What output did you expect? :wink: You saved the only possible output in a variable buit you did not output this variable. :wink:

$Cred = Get-Credential -Credential 'mopower\Administrator'
$ScriptBlock = {
    Get-Service -Name 'dps'
$ServiceStatus = Invoke-Command -ComputerName labserver -Credential $Cred -ScriptBlock $ScriptBlock

Since you don’t use your parameter anyway you can omit it.


thanks so much guys - i need to do some more reading - but glad i found you guys :slight_smile:

thanks Posh - thanks guys been a while never managed to say thanks properly

If you are still working on learning, one of the best free resources can be found here
Windows PowerShell 4.0: TFM (The F****** Manual) (sapien.com)

I have no connection to sapien, just think their books were the best for learning PS.