header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
powershell - virtual machine manager
Last Post 01 Jul 2010 11:38 PM by phillbl. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
phillblUser is Offline
New Member
New Member
Posts:9
Avatar

--
30 Jun 2010 11:15 PM

    Hi, 

    I have a powershell script myscript.ps1 that is run from a batch file.  I use the following command
    C:\PSScripts>powershell "& 'c:\psscripts\pausevm.ps1' "
    I get an error message (end of the message). 

    The reason seems to be that when i run this command it launches a powershell that does not have the vm cmdlets.  The powershell that i run from the start menu > Windows Powershell - Virtual Machine Manager is the version that I need to run.  How can i get this powershell to load instead of the one without the vm cmdlets using the batch file.

    Thanks
     


    Set-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\M
    icrosoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.
    At C:\psscripts\pausevm.ps1:14 char:20
    + set-executionpolicy <<<<  RemoteSigned
        + CategoryInfo          : NotSpecified: (:) [Set-ExecutionPolicy], Unautho
       rizedAccessException
        + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.Pow
       erShell.Commands.SetExecutionPolicyCommand

    The term 'Get-VMMServer' is not recognized as the name of a cmdlet, function, s
    cript file, or operable program. Check the spelling of the name, or if a path w
    as included, verify that the path is correct and try again.
    At C:\psscripts\pausevm.ps1:16 char:14
    + Get-VMMServer <<<<  chimay
        + CategoryInfo          : ObjectNotFound: (Get-VMMServer:String) [], Comma
       ndNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

    The term 'Get-VM' is not recognized as the name of a cmdlet, function, script f
    ile, or operable program. Check the spelling of the name, or if a path was incl
    uded, verify that the path is correct and try again.
    At C:\psscripts\pausevm.ps1:18 char:7
    + Get-VM <<<<  | Where-Object {$_.Tag -eq 'pause'} | Suspend-VM
        + CategoryInfo          : ObjectNotFound: (Get-VM:String) [], CommandNotFo
       undException
        + FullyQualifiedErrorId : CommandNotFoundException


    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    30 Jun 2010 11:38 PM
    • Accepted Answer
    two things:
    1. at the beginning of the script you need to load the VMM Snap-in:
      Add-PSSnapin -name VirtualMachineManagerSnapIn
    2. Set-ExecutionPolicy needs to be run external to the script, but can be done as part of the execution:
      powershell "& 'c:\psscripts\pausevm.ps1' " -executionpolicy RemoteSigned
      or by bypassing the ExecutionPolicy
    Also, if you are using 2.0 you should be using the -file parameter to specify your script file:
    powershell.exe -file c:\psscripts\pausevm.ps1 -executionpolicy RemoteSigned
    When at first you don't succeed Step-Into

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

    phillblUser is Offline
    New Member
    New Member
    Posts:9
    Avatar

    --
    01 Jul 2010 11:38 PM
    thanks for that cruisader03. works great. Thanks again
    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