header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
PSsession remotely execute script
Last Post 30 Jun 2010 11:51 AM by nosoup4u. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
nosoup4uUser is Offline
New Member
New Member
Posts:5
Avatar

--
30 Jun 2010 10:14 AM
    Hello all thanks in advance for your help.

    The following script functionality works to authenticate & connect to hyper v hosts & query directly vm details, however this is only when PS is running in console, not IDE, nor can I directly run the .PS1 script.

    A recent MVP mentioned that this is a limitation - http://social.technet.microsoft.com...8645e5c035

    See code below:

    $VMHost = "servername" Enter-PSSession $VMHost -credential ( Get-Credential )
    $Env = "environmentname"

    CD D:\PS\Scripts . .\hyperv.ps1 -quiet
    Get-VM $Env*
    Exit-PSSession

    I'd like to have it so I can just run the script located on the hyper v host ( PS\Scripts . .\hyperv.ps1) remotely through PSSession w/ out needing to open a console, any suggestions?
    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    30 Jun 2010 11:41 AM
    Please post your entire script.  There is a lot of missing functionality here and we cannot troubleshoot this partial script
    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    nosoup4uUser is Offline
    New Member
    New Member
    Posts:5
    Avatar

    --
    30 Jun 2010 11:51 AM
    This is the whole script, honestly. I think however that I've found a way to get it to run via the script without opening a console first. it involves adding the invoke command.

    Invoke-Command -Session $Session -ScriptBlock `


    $VMHost = "vmhost"
    $Session = New-PSSession $VMHost -credential ( Get-Credential )

    Invoke-Command -Session $Session -ScriptBlock `
    {
    $Env = "M4C"
    CD D:\PS\Scripts\
    . .\hyperv.ps1
    Get-VM $Env*
    }

    Remove-PSSession $Session
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer