Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

How to modify script to work with a list

$
0
0

I am having trouble modifying an existing script to run from a text list instead of the Powershell VM extension command 'get-vm.'

The script I found is this:

$spec = new-object VMware.Vim.VirtualMachineConfigSpec
$spec.tools = New-Object VMware.Vim.ToolsConfigInfo
$spec.tools.syncTimeWithHost = $false

$vms=get-vm $vm |?{$_.extensiondata.config.tools.synctimewithhost -like $true}
$vms|select -expand name
$vms|%{$_.extensiondata.reconfigvm_task($spec)}

I understand most of what the script is doing. I'm not sure about the select -expand name line though.

I tried this:

forEach ($vminget-contentC:\scripts\servers.txt)

{$_.extensiondata.reconfigvm_task($spec)}

But it doesn't work. Tried a pipe too...

$vm | {$_.extensiondata.reconfigvm_task($spec)} of course this doesn't work either.

Any help appreciated.


Viewing all articles
Browse latest Browse all 6937

Trending Articles