Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
System Center Family
SCVMM
Last Post 26 Aug 2009 12:05 AM by
griffo
. 2 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
griffo
New Member
Posts:2
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)
Veteran Member
Posts:1647
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
griffo
New Member
Posts:2
26 Aug 2009 12:05 AM
Works perfectly, many thanks.
You are not authorized to post a reply.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
System Center Family
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2