title: How to get an variable output from remote pssession
body: <p>I have a script to get virtual harddisk info from vmm, im executing it remotely from a server, currently im unable to get the variable value outside of the pssession in the local host, could you please help me out with achieveing the same.</p>
  
  <pre><code>PS C:\Windows\system32&gt; enter-pssession iscvmm02
  [iscvmm02]: PS C:\Users\su\Documents&gt;Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager
  [iscvmm02]: PS C:\Users\su\Documents&gt;$hide= Get-VMMServer -ComputerName "iscvmm02.corp.avanade.org"
  [iscvmm02]: PS C:\Users\su\Documents&gt;$VM = Get-VM | where { $_.ComputerNameString -contains "idpsm02.corp.air.org" }
  [iscvmm02]: PS C:\Users\su\Documents&gt;$harddisk=$VM.VirtualHardDisks
  [iscvmm02]: PS C:\Users\su\Documents&gt;$h=$harddisk.length
  [iscvmm02]: PS C:\Users\su\Documents&gt;for($i=0;$i-lt$h;$i++){
      New-Variable -Name "HardDiskType_$i" -value $harddisk[$i].vhdtype
      New-Variable -Name "HardDiskLocation_$i" -value $harddisk[$i].Location
  }
  [iadpscvmm02]: PS C:\Users\su\Documents&gt;Exit-PSSession
  PS C:\Windows\system32&gt;$harddisktype_0
  PS C:\Windows\system32&gt;$harddisklocation_0
  </code></pre>
  
  <p>as you can see both the variable output's give null value, im unable to retain the values</p>