Invoke-command issue via jenkins pipeline

i am triggering a powershell script via the jenkins pipeline that contains invoke-command code that I use to set up Hyper v and run commands on it . However when the script run through Jenkins pipeline it keeps failed with:

An error has occurred which Windows PowerShell cannot handle. A remote session might have ended.

  • CategoryInfo : OpenError: (:String) , PSRemotingDataStructureException
  • FullyQualifiedErrorId : PSSessionStateBroken