Struggling to read files and services running on an hyper-v VM

I am automating an hyper-v vm from outside of the vm

In my scripts I have a checkpoint applied, running the VM and waiting for it to become stable, then copying and running an exe to install an application

After installing the app I want to check the files are installed and the services are running

To do the the latter, I am trying the following

[pre] $s = New-PSSession -VMName $vmName -Credential $Cred

Invoke-Command -Session $s -VMName “Peptide Mam automation” -ScriptBlock {get-service -Name “WatLindisfarneApiService”} [/pre]

This is currently returning

[pre] Invoke-Command : Parameter set cannot be resolved using the specified named parameters.
At C:\Peptide MAM Automation\Check Installation.ps1:18 char:5

  • Invoke-Command -Session $s -VMName “Peptide Mam automation” -Scri …
  • CategoryInfo : InvalidArgument: (:slight_smile: [Invoke-Command], ParameterBindingException
  • FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand [/pre]

Does anyone know what the correct syntax or code I should be using please?

Thanks

 

 

Look at your commands. There is no ‘VMName’ parameter, it should be -ComputerName

PS C:\WINDOWS\system32> Invoke-Command -ComputerName
PS C:\WINDOWS\system32> New-PSSession -ComputerName

Thank you!

Please remove -VMName parameter from the Invoke-Command CmdLet, you can provide either -VMName or -Session but not both.

Both New-PSSession and Invoke-Command supports -VMName parameter. From Windows Server 2016/Windows 10 onwards it supports PowerShell Direct to manage the Hyper-V VMs directly from the Host itself.

Thank you.