PowerShell script exchange
Post Reply
ken2023
Novice
Posts: 5
Liked: never
Joined: Jul 08, 2023 6:35 am
Full Name: ken
Contact:

Fail to change the media pool of backup job via powershell

Post by ken2023 »

Case #06155499

Code: Select all

Welcome to the Veeam Backup and Replication PowerShell Toolkit!

To list available commands, type Get-VBRCommand
To open online documentation on all available commands, type Get-VBRToolkitDocumentation

c Veeam Software Group GmbH. All rights reserved.


PS C:\Users\Administrator> Get-VBRTapeMediaPool -Name "Monthly"


Capacity               : 23999998328832
FreeSpace              : 22127039217664
MediaSetCreationPolicy : Never
MediaSetName           : Media set # %id% %date%
MoveOfflineToVault     : False
RetentionPolicy        : Period
MultiStreamingOptions  : Veeam.Backup.PowerShell.Infos.VBRMultiStreamingOptions
Vault                  :
Worm                   : False
LibraryId              : dc73ffd3-f7d0-48a7-af9d-4d63265d43c2
MoveFromFreePool       : True
Type                   : Custom
EncryptionOptions      : False
GlobalOptions          : Veeam.Backup.PowerShell.Infos.VBRGlobalMediaPoolOptions
Medium                 : {1000004L, 1000021L}
Id                     : a86cf70e-6708-406b-94b0-bc8a69513fe3
Name                   : Monthly
Description            : Created by sanbkup\Administrator at 5/25/2023 3:34:33 PM.



PS C:\Users\Administrator> Get-VBRTapeJob -Name "Weekly Backup"


FullBackupPolicy            : Daily
IncrementalBackupPolicy     : Daily
Object                      : {}
NdmpObject                  : {/svm_fcp_1/san_disk_02, /svm_fcp_1/san_disk_03, /svm_fcp_1/san_disk_04,
                              /svm_fcp_1/san_disk_05}
UseVss                      : False
ParallelDriveOptions        : Veeam.Tape.Model.CTapeJobParallelDriveOptions
EnableFileAclChangeTracking : False
EjectCurrentMedium          : False
ExportCurrentMediaSet       : False
ExportDays                  : {Sunday, Monday, Tuesday, Wednesday...}
FullBackupMediaPool         : weekly
IncrementalBackupMediaPool  : weekly
UseHardwareCompression      : False
NotificationOptions         :
JobScriptOptions            : Veeam.Backup.PowerShell.Infos.VBRJobScriptOptions
Enabled                     : True
NextRun                     : 7/5/2023 11:00:00 PM
Target                      : weekly
Type                        : FileToTape
LastResult                  : Success
LastState                   : Stopped
Id                          : e0dca307-b479-43f9-8939-f9b7097b7773
Name                        : Weekly Backup
Description                 : Created by sanbkup\Administrator at 6/8/2023 8:27 PM.



PS C:\Users\Administrator>
PS C:\Users\Administrator> [b]$newpool = Get-VBRTapeMediaPool -Name "Monthly"[/b]
PS C:\Users\Administrator> [b]Get-VBRTapeJob -Name "Weekly Backup" | Set-VBRBackupToTapeJob -FullBackupMediaPool $newpool[/b]
Set-VBRBackupToTapeJob : The input object cannot be bound to any parameters for the command either because the command
does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline
input.
At line:1 char:40
+ ... Weekly Backup" | Set-VBRBackupToTapeJob -FullBackupMediaPool $newpool
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Weekly Backup:PSObject) [Set-VBRBackupToTapeJob], ParameterBindingExce
   ption
    + FullyQualifiedErrorId : InputObjectNotBound,Veeam.Backup.PowerShell.Cmdlets.SetVBRBackupToTapeJob

PS C:\Users\Administrator>
veremin
Product Manager
Posts: 20655
Liked: 2374 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Fail to change the media pool of backup job via powershell

Post by veremin »

Not sure what your question is, but what happens if you try to assign a job to a variable first instead of working with it through the pipeline?
david.domask
Veeam Software
Posts: 2566
Liked: 603 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Fail to change the media pool of backup job via powershell

Post by david.domask »

Agree with @veremin, don't pass it down the pipeline. Set the tape job to some $job variable, then pass that to the -Job parameter on Set-VBRbackupToTapeJob.

I'm not sure the User Guide entry is fully correct on the input from pipeline, so I will ask to check this and validate if it's really the case. But I think Powershell is getting confused because you're trying to pass arguments both from pipeline and with the parameters.
David Domask | Product Management: Principal Analyst
ken2023
Novice
Posts: 5
Liked: never
Joined: Jul 08, 2023 6:35 am
Full Name: ken
Contact:

Re: Fail to change the media pool of backup job via powershell

Post by ken2023 »

Case #06155499
I would like to write a simple powershell script to change the media pool of a backup job. I expect to use Set-VBRBackupToTapeJob -FullBackupMediaPool $newpool can change the media pool. But it prompt the above error message
veremin
Product Manager
Posts: 20655
Liked: 2374 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Fail to change the media pool of backup job via powershell

Post by veremin »

We suggested something similar to the following:

Code: Select all

$newpool = Get-VBRTapeMediaPool -Name "Monthly"
$Job = Get-VBRTapeJob -Name "Weekly Backup"
Set-VBRBackupToTapeJob -Job $Job -FullBackupMediaPool $newpool
Thanks!
ken2023
Novice
Posts: 5
Liked: never
Joined: Jul 08, 2023 6:35 am
Full Name: ken
Contact:

Re: Fail to change the media pool of backup job via powershell

Post by ken2023 »

PS C:\Users\Administrator> $newpool = Get-VBRTapeMediapool -name "Monthly"
PS C:\Users\Administrator> $job = Get-VBRTapeJob -Name "Weekly Backup"
PS C:\Users\Administrator> Set-VBRBackupToTapeJob -Job $job -FullBackupMediaPool $newpool
Set-VBRBackupToTapeJob : Cannot bind parameter 'Job'. Cannot convert the "Weekly Backup" value of type
"Veeam.Backup.PowerShell.Infos.VBRFileToTapeJob" to type "Veeam.Backup.PowerShell.Infos.VBRBackupToTapeJob".
At line:1 char:29
+ Set-VBRBackupToTapeJob -Job $job -FullBackupMediaPool $newpool
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-VBRBackupToTapeJob], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Cmdlets.SetVBRBackupToTapeJob

PS C:\Users\Administrator>
david.domask
Veeam Software
Posts: 2566
Liked: 603 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Fail to change the media pool of backup job via powershell

Post by david.domask »

Aha, and there's your issue :)

You were passing a type VBRFileToTapeJob to Set-VBRBackupToTapeJob, but you need to pass a VBRBackupToTapeJob object.

https://helpcenter.veeam.com/docs/backu ... ml?ver=120

Use Set-VBRFileToTapeJob, see if it works: https://helpcenter.veeam.com/docs/backu ... ml?ver=120
David Domask | Product Management: Principal Analyst
ken2023
Novice
Posts: 5
Liked: never
Joined: Jul 08, 2023 6:35 am
Full Name: ken
Contact:

Re: Fail to change the media pool of backup job via powershell

Post by ken2023 »

Your Suggestion is work; Thank you.
david.domask
Veeam Software
Posts: 2566
Liked: 603 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Fail to change the media pool of backup job via powershell

Post by david.domask »

Glad it worked out @ken2023,

Just for your future scripting, it's best to avoid long piping like that in your scripts. It makes debugging a lot harder as the piping "swallows" the actual errors and hides it. Long piping like that is maybe okay for one-liners you create on the fly, but in your scripts there's not much benefit to it, and instead you should just do the processes separately. It only makes it harder to debug when you do such piping in scripts.
David Domask | Product Management: Principal Analyst
ken2023
Novice
Posts: 5
Liked: never
Joined: Jul 08, 2023 6:35 am
Full Name: ken
Contact:

Re: Fail to change the media pool of backup job via powershell

Post by ken2023 »

Thank you for your advice.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests