powershell cmdlets

PowerShell script exchange

Re: powershell cmdlets

Veeam Logoby ThomasMc » Fri Nov 04, 2011 11:09 am

You may also want $v to be an array because you just keep overwriting it

Code: Select all
Get-Folder "Temp" | Get-VM | ForEach { $v += @($_.Name) }

Actually thinking about what your trying to do, it wouldn't work in a array after look at the code below the Get-Folder, might I suggest you;

1) create the job without any objects
2) Move the Get-Folder cmd below your Add-VBRJob and change your ForEach to use the Add-VBRJobObject cmdlet(or use the function below)

Code: Select all
function Add-JO{
  Param ([string]$vmname,[string]$jobname)
  $newjob =  Get-VBRJob | ?{$_.Name -eq "$jobname"}
  $vbrserver = Get-VBRServer | ?{$_.Type -eq "VC"}
  Add-VBRJobObject -Job $newjob -Server $vbrserver -Object $vmname

and to call you would use

Code: Select all
Add-JO "vm01.lab.local" "VM01 Backup Job Name"
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell


Return to PowerShell

Who is online

Users browsing this forum: Bing [Bot] and 1 guest