SC2012 - problem

by Symbiot at 2012-11-17 03:24:12


as part of my script I am doing this:

$BestHost = Get-VMHostRating -VMHostGroup $VMHostGroup -HardwareProfile $HWProfile -DiskSpaceGB 25 -VMName New | where {$.rating -gt 0} | sort-object -property rating -descending
$currentHost = get-vmhost | where {$
.name -eq $BestHost[0].name}
$storagedisk = get-scstoragedisk -vmhost $currenthost
$path = $ | Out-String

$besthost selects between 3 hosts (at the moment) then selects the best
$currenthost gets the best one
$storagedisk gets the storagedisk of the currenthost object
$path sets the path where VM’s are stored. I use out-string because it wants a string and not an object as $path is

result of path is: C:\Clusterstorage\Volume1 (as an example after besthost etc)
But I get an error when trying to run new-scvirtualmachine…

New-SCVirtualMachine : The file name, folder name, or volume label syntax
is incorrect on the NO_PARAM server. (Error ID: 2905, Detailed Error: )

Ensure that the path name does not contain the characters (\ / : * ? " < > | ), and then try the operation again.

Help :slight_smile:
by DonJ at 2012-11-17 06:49:45
You’ve got something incorrect.

Out-String is being given a collection of objects, and so you’re getting multiple paths. According to that error message, $path contains “C:&lt;CR>C:\ClusterStorage\Volume1” and New-SCVirtualMachine doesn’t like it.

Double-check that $path contains what you think it does. You may need to select out just a single path before piping to Out-String. Actually, you shouldn’t need Out-String at all. Your problem isn’t that $path is an object; the problem is that $storagedisk.diskvolumes is a collection, not a single object. If you can get down to a single diskvolume, its Name property will be the string you need.
by Symbiot at 2012-11-19 01:35:34
thanks…right now I’ve dropped the code, and am trying something different.

this seems to work:
$testpath = $currenthost.vmPaths

So that’s Amaaaaaaazing :slight_smile:
by Symbiot at 2012-11-19 01:44:40
oh but no… of course not…

I get the correct path now but this:
New-SCVirtualMachine -Name $names -vm $vm -VMHost $currentHost -path $path -OperatingSystem “Windows 7” -Owner “HEF_NT\mrt” -StartAction NeverAutoTurnOnVM -StopAction SaveVM

now gives me:

New-SCVirtualMachine : Cannot convert ‘System.String[]’ to the type ‘System.String’ required by parameter ‘Path’. Specified method is not supported.
At line:3 char:71
+ New-SCVirtualMachine -Name $names -vm $vm -VMHost $currentHost -path $path -Ope …
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:slight_smile: [New-SCVirtualMachine], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.VirtualMachineManager.Cmdlets.NewVmCmdlet
by Symbiot at 2012-11-19 01:51:58
so I need to convert the $path to a string…
strange thing is $path only contains “C:\clusterstorage\volume1”…
by Symbiot at 2012-11-19 02:05:40
ok, did this:


works… now for the rest of the errors…