PowerShell script exchange
Post Reply
redraidermgr
Lurker
Posts: 2
Liked: never
Joined: Sep 25, 2018 6:53 pm
Full Name: Charles Smith
Contact:

Help with Write-host in a foreach statement.

Post by redraidermgr »

Good morning everyone,

I am new to powershell and have been tasked with writing a script that will alert us if any of our backups are below our minimum retention threshold. I have the code working thanks to some other posts on this forum and some google searching. I am having trouble getting a write-host statement to work in the foreach statement that I created.

Here is my code:

Code: Select all

#Define Veeam Hosts
$VeeamHosts = "host1","host2","host3","host4","host4"

#Backup Job Restore Points (Less than 30 Days)
$BackupResults = foreach ($VeeamHost in $VeeamHosts){
Connect-VBRServer -Server $VeeamHost
$BackupJobs = Get-VBRBackup | Where-Object name -notmatch "Copy" | Select -ExpandProperty Name
Get-VBRRestorePoint -Backup $BackupJobs | Select-Object Name, @{N="Job Name";E={$_.FindSourceJob().name}} | Group-Object Name, "Job Name" -NoElement | Where-Object Count -LT 30 | sort "Job Name" | Format-Table -Property Name, Count
Disconnect-VBRServer
}

$BackupResults
What I am trying to do is put a write-host statement for each host and equate each host to a new name.

For example the out put would be

""Database" Servers Below Retention" instead of ""host1" Servers below retention"

Any articles that would explain how to do that and where to put it in my code would help. I am an extreme novice when it comes to powershell and I am amazed that I have gotten this far on this. Also is there any way to split out the "Job Name" into its own column in the output? Any tips or tricks are appreciated.

Thank You All for making this forum a great source of knowledge!
Mike Resseler
Product Manager
Posts: 8045
Liked: 1263 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

Re: Help with Write-host in a foreach statement.

Post by Mike Resseler »

Hey Charles,

First: welcome to the forums.

You do a foreach and then store the data in a specific variable. What if you write out the results inside the foreach? Building the column line by line?
redraidermgr
Lurker
Posts: 2
Liked: never
Joined: Sep 25, 2018 6:53 pm
Full Name: Charles Smith
Contact:

Re: Help with Write-host in a foreach statement.

Post by redraidermgr »

Thanks Mike,

I will give that a try. I appreciate the comment. I will post an update in a bit.
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests