PowerShell script exchange
Post Reply
sebastien22
Novice
Posts: 5
Liked: never
Joined: Aug 07, 2014 9:06 am
Full Name: Sebastien
Contact:

MyVeeamReport exclude Folders

Post by sebastien22 »

Hello
Excuse me for my english

I use the script smasterson MyVeeamReport.ps1
(https://gist.github.com/smasterson/9136 ... report-ps1)


But excluding folders does not work or simply for a folder,
you have an idea for multiples folders ?

# To Exclude Missing VMs from VM Backups report add names to be excluded as follows
# $ @ = Excludevms ("vm1", "vm2", "* _replica")
$ @ excludeVMs = ("")
# Exclude Missing VMs from backups report in the following (vCenter) folder
folderExclude $ = ""


folderExclude $ = "No_backup" = OK
folderExclude $ = "No_backup,No_backup_citrix" = KO
folderExclude $ = "No_backup","No_backup_citrix" = KO
folderExclude $ = "No_backup" "No_backup_citrix" = KO

Thank you in advance
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: MyVeeamReport exclude Folders

Post by veremin »

But excluding folders does not work or simply for a folder, you have an idea for multiples folders ?
Can you elaborate on that? You mean the script can only exclude VMs coming from one folder, not multiple ones? Thanks.
sebastien22
Novice
Posts: 5
Liked: never
Joined: Aug 07, 2014 9:06 am
Full Name: Sebastien
Contact:

Re: MyVeeamReport exclude Folders

Post by sebastien22 »

hello

No, it is the exclusion of a complete folder in datacenter , with one folder it works, but not with more

Exemple :

# Exclude Missing VMs from backups report in the following (vCenter) folder
folderExclude $ = ""

folderExclude $ = "No_backup" = OK ( all VM in folder is exclude )

But with multiples folders in variables , dont work

folderExclude $ = "No_backup,No_backup_citrix" = KO
folderExclude $ = "No_backup","No_backup_citrix" = KO
folderExclude $ = "No_backup" "No_backup_citrix" = KO


thanks
nefes
Veeam Software
Posts: 649
Liked: 170 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: MyVeeamReport exclude Folders

Post by nefes »

Could you try

Code: Select all

$folderExclude = @("No_backup", "No_backup_citrix")
?
It will create an array with two elements rather than one big string
sebastien22
Novice
Posts: 5
Liked: never
Joined: Aug 07, 2014 9:06 am
Full Name: Sebastien
Contact:

Re: MyVeeamReport exclude Folders

Post by sebastien22 »

hello

I also tested the same result.

$folderExclude = @("No_backup", "No_backup_citrix")



If I place a folder OK, as soon as there are at least two, it does not work.

The folder name is good, one by one is OK

Thanks
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: MyVeeamReport exclude Folders

Post by veremin »

Then, some sort of cycle seems to be required within the script provided. Based on your description, currently script can only exclude only one folder. So, you will have to add cycle to the script. Within the cycle specified folders will be taken and excluded one by one. Thanks.
nefes
Veeam Software
Posts: 649
Liked: 170 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: MyVeeamReport exclude Folders

Post by nefes »

After some reading of the script you linked, seems that I find the reason. The string 443

Code: Select all

$vmobjs = Find-VBRObject -Server $vcenterobj | Where-Object {$_.Type -eq "VirtualMachine" -and $_.VMFolderName -notlike $script:folderExclude}
should be changed to

Code: Select all

$vmobjs = Find-VBRObject -Server $vcenterobj | Where-Object {$_.Type -eq "VirtualMachine" -and $_.VMFolderName -notin $script:folderExclude}
After that $folderExclude = @("No_backup", "No_backup_citrix") should work. Please be aware, this search is case-specific ("no_backup" folder will not be excluded)
sebastien22
Novice
Posts: 5
Liked: never
Joined: Aug 07, 2014 9:06 am
Full Name: Sebastien
Contact:

Re: MyVeeamReport exclude Folders

Post by sebastien22 »

Hello ,

Thank you for your help.

I'm testing, but following the change

Code: Select all

PS C:\Users\root> U:\prc\veeam\Rapport_Veeam_Quotidien.ps1
Vous devez fournir une expression de valeur à droite de l'opérateur « - ».   ( You must provide a value expression on the right of the "-" operator. )
Au niveau de U:\prc\veeam\Rapport_Veeam_Quotidien.ps1 : 362 Caractère : 114
+     $vmobjs = Find-VBRObject -Server $vcenterobj | Where-Object {$_.Type -eq "VirtualMachine" -and $_.VMFolderName - <<<< notin $script:folderExclude}
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : ExpectedValueExpression

Thanks
nefes
Veeam Software
Posts: 649
Liked: 170 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: MyVeeamReport exclude Folders

Post by nefes »

Seems that "-notin" comparator is presented only in PowerShell 3.0
If you want to use Powershell 2.0, you could try "-notcontains", but you should switch places of parameters:

Code: Select all

$vmobjs = Find-VBRObject -Server $vcenterobj | Where-Object {$_.Type -eq "VirtualMachine" -and $script:folderExclude -notcontains $_.VMFolderName}
sebastien22
Novice
Posts: 5
Liked: never
Joined: Aug 07, 2014 9:06 am
Full Name: Sebastien
Contact:

Re: MyVeeamReport exclude Folders

Post by sebastien22 »

Hello

Thank you very much for your quick response, it works fine, I tested with ten records and perfect.


And Shawn Masterson offered me this solution also works great


On line 21

Code: Select all

$folderExclude = ""
Separate multiple folders with a | like so

Code: Select all

$folderExclude = "folder1|folder2|folder3"

On line 443

Code: Select all

$vmobjs = Find-VBRObject -Server $vcenterobj | Where-Object {$_.Type -eq "VirtualMachine" -and $_.VMFolderName -notlike $script:folderExclude}
Lets change this from -notlike to -notmatch

Code: Select all

$vmobjs = Find-VBRObject -Server $vcenterobj | Where-Object {$_.Type -eq "VirtualMachine" -and $_.VMFolderName -notmatch $script:folderExclude}



Thank you again
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests