header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
SCVMM
Last Post 26 Aug 2009 12:05 AM by griffo. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
griffoUser is Offline
New Member
New Member
Posts:2
Avatar

--
12 Aug 2009 08:41 AM

    Hi, I'm trying to write a powershell script which can update a virtual machines custom properties.

    the code is fairly simple but it errors saying Set-VM a positional parameter can't be found for '-Custom2'

    Here is the code

    # Filename:      Set Custom1.ps1
    # Description:   Updates the Custom 1property


    # Connect to the VMM server.
    Get-VMMServer -ComputerName "localhost"

    $Owner = whoami
    $VMName = $args[0]
    $Custom = "`-Custom" + $args[1]
    $Value = $args[2]
    $Command = (Set-VM -VM $VMName $Custom $Value)
    "Done"

    It's called like this .\Set Custom1.ps1 VMTest 1 Test

    Which should do this

    Set-VM -VM VMTest -Custom1 Test

    Running the above line manually it works fine.

    ?

    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1647
    Avatar

    --
    12 Aug 2009 08:59 AM
    I can't test, but change your $command to try this instead:
    $command=invoke-expression "set-vm -vm $vmname $custom $value"
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    griffoUser is Offline
    New Member
    New Member
    Posts:2
    Avatar

    --
    26 Aug 2009 12:05 AM
    Works perfectly, many thanks.
    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