Variable with space

If I have a variable input is passed with space it causes the follow on commandlet to fail.



get-vbrjob from veeam if the jobs have spaces when I pass it to vbrjobobject it fails because the jobs from the passed variable has spaces.


Test job 1
Test backup job 2
Test backup monthly

when the $var is passed it fails because of the space.

enclose the var in quotes

would it be


Either single or double should work. The main difference is double qoutes will attempt to expand variables and single qoutes are literal:

PS C:\WINDOWS\system32> $test = "a zombie"

PS C:\WINDOWS\system32> "Rob was chased by $test"
Rob was chased by a zombie

PS C:\WINDOWS\system32> 'Rob was chased by $test'
Rob was chased by $test

I’m not sure I follow your question. Are you saying the variable name has spaces or your variable has a value <string> with spaces in it? For information on naming variables look here. Bottom line to have spaces in a variable name you would place it in curly braces like this.

${hello world} = "Some text"

String literals with spaces should be in quotes. Single quotes are literal and double-quotes can interpolate. You can read more about that here.

If you post your actual code I might be able to help you further.

Add-PSSnapin VeeamPSSnapin
“$jobs” = (Get-VBRJob).name

ForEach-Object ($job in “‘$jobs’”)
Get-VBRJobObject -Name $job

here is the list of items that I’m passing from a cmdlet as you can see most of the list has spaces. What I’m really trying to accomplish is to pass this data to another cmdlet however it fails. I wonder if I have to split each item in the list into a separate item (not sure how to do that) because it still fails when I put the vatiable in quotes i.e “$jobs”.

VMware Daily-Weekly-Monthly GFS-1 8D-RP_52W_RP-12M-RP
Weekly Saturday Backup Group-1 Saturday GFS1 0D-RP_4W-RP_12M-RP
Twice Week Days VMware Backup Group-1
VMware Daily-Weekly-Monthly GFS-2 (4 D-RP 52 W-RP 12 M-RP)
Weekly VMware Backup Group-1 No-GFS
Weekly Sunday VMware Group-1 No-GFS
VMware Twice Daily GFS-1 8D-RP_52W_RP-12M-RP
VMware No Daily Weekly Monthly GFS-2 0D-RP_26W_RP-12M-RP
Weekly Saturday VMware Group-1 No-GFS
Weekly Saturday
EOL Server Backup
Week Days VMware Backup Group-4
Week Day VMware Backup Group-6-NWLK
Week Days VMware Backup Group-6
Weekly VMware Saturday-Group-1
Physical Twice Daily GFS-1 8D-RP_26W_RP-12M-RP
VMware No Daily Weekly Monthly GFS-1 0D-RP_13W_RP-0M-RP
Week Days VMware Backup Group-2
Week Days VMware Backup Group-3
Week Days VMware Backup Group-1
Weekly Folder GFS-1 0D-RP_26-RP_0M-RP
Weekly Sunday VMware Group-1-NWLK

This should be all you need:

Add-PSSnapin VeeamPSSnapin
$jobs = Get-VBRJob

forEach ( $job in $jobs) {
    Get-VBRJobObject -Name $job.Name