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

Welcome Forums General PowerShell Q&A Struggling to read files and services running on an hyper-v VM

  • This topic has 3 replies, 3 voices, and was last updated 1 month ago by
    Moderator
    .
Viewing 3 reply threads
  • Author
    Posts
    • #194393
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      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

       $s = New-PSSession -VMName $vmName -Credential $Cred
      
      Invoke-Command -Session $s -VMName "Peptide Mam automation" -ScriptBlock {get-service -Name "WatLindisfarneApiService"} 

      This is currently returning

        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: (:) [Invoke-Command], ParameterBindingException
      + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand 

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

      Thanks

       

       

    • #194429
      Participant
      Topics: 10
      Replies: 1381
      Points: 1,509
      Helping Hand
      Rank: Community Hero

      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
      
    • #194891
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      Thank you!

    • #194918
      Moderator
      Topics: 3
      Replies: 169
      Points: 889
      Helping Hand
      Rank: Major Contributor

      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.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.