基本上,我使用PowerShell从备份软件中获取数据,然后将其写入表中。我对这个部分没有问题,因为我正在获取一天价值的数据,然后将其写入一个表中,其中行是服务器名称,列显示“成功”或“失败”。
我希望能够创建一个表,其中行显示服务器名称,列显示第1至31天,然后“成功”或“失败”每一天。我希望这是合理的。
$format = "<style>"
$format = $format + "{font-family: Arial; font-size: 10pt;}"
$format = $format + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$format = $format + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$format = $format + "TD{border: 1px solid black; padding: 5px; }"
$format = $format + "</style>"
$sessions = Get-VBRBackupSession | Where-Object {$_.JobType -eq "Backup" -and $_.EndTime -ge (Get-Date).addhours(-24)}
$realsessions = $sessions.gettasksessions()
$table = @()
foreach ($session in $realsessions) {
$backupobject = New-Object PSObject
$backupobject | Add-Member -MemberType NoteProperty -Name "Job Name" -Value $session.JobName
$backupobject | Add-Member -MemberType NoteProperty -Name "Server Name" -Value $session.Name
$backupobject | Add-Member -MemberType NoteProperty -Name "Backup Status" -Value $session.Status
$table += $backupobject
}
$table | ConvertTo-Html -Head $format -body "<H2>Veeam Backup Report</H2>" | Out-File "C:\Temp\VeeamBackupReport.xls"$sessions的输出:
BottleneckManager : CJobBottleneckManager
Info : Veeam.Backup.Model.CBackupSessionInfo
Progress : Veeam.Backup.Model.CBackupProgressData
StartupMode : Normal
JobSourceType : VDDK
CurrentPointId : 0b833e92-0f45-4b75-bb40-f8c80a696df9
OriginalSessionId : 5bfdc2bf-d17b-40aa-9e5f-d5e44b19ca67
IsFullMode : False
IsRetryMode : False
IsVeeamZip : False
PostActivity : AskService
Name : Daily_Backups
OrigJobName : Daily_Backups
BackupStats : Veeam.Backup.Model.CBackupStats
WorkDetails : Veeam.Backup.Core.CBackupSessionWorkDetails
WillBeRetried : False
IsManuallyStopped : False
StorageVerificationResult : Veeam.Backup.Core.CStorageVerificationResultContainer
SessionInfo : Veeam.Backup.Model.CBackupSessionInfo
Id : 5bfdc2bf-d17b-40aa-9e5f-d5e44b19ca67
JobType : Backup
JobName : Daily_Backups
JobSpec :
JobTypeString : Other job type
Operation :
Description :
BaseProgress : 100
IsCompleted : True
IsWorking : False
JobId : 843d4014-5dda-4dfb-8590-949d7ed843ce
Result : Success
State : Stopped
EndTime : 2015/04/11 04:12:36 AM
CreationTime : 2015/04/10 10:00:20 PM
AuxData : <AuxData><CBackupStats><BackupSize>46279333376</BackupSize><DataSize>97487622667</DataSize>
<DedupRatio>99</DedupRatio><CompressRatio>47</CompressRatio></CBackupStats><CBackupSessionW
orkDetails><WorkDuration>223365199270</WorkDuration></CBackupSessionWorkDetails></AuxData>
IsLowerAgentPriority : True
LogName : Job.Daily_Backups
LogsSubFolder : Daily_Backups
Logger : Veeam.Backup.Core.XmlLogger
Tracer : Veeam.Backup.Core.CSessionLogTracer$RealSessions输出
JobSess : Veeam.Backup.Core.CBackupSession
Info : Veeam.Backup.Model.CBackupTaskSessionInfo
ProgressManager : Veeam.Backup.Core.CBackupTaskSessionProgress
WorkTimer : Veeam.Backup.Core.CBackupTaskSessionWorkTimer
Id : 3767cd65-8de9-423e-b77e-6850ebb95dab
Name : Server1
Status : Success
Operation :
Progress : Veeam.Backup.Model.CBackupProgressData
CurrentDiskNum : 1
Logger : Veeam.Backup.Core.XmlLogger
Tracer : Veeam.Backup.Core.CSessionLogTracer
WillBeRetried : False
RetryCounter : 0
JobSessId : 5bfdc2bf-d17b-40aa-9e5f-d5e44b19ca67
JobName : Daily_Backups发布于 2015-04-13 16:37:17
我要补充另一个答案。虽然我的另一个答案是不正确的,你的情况下,我想留下它,以防它增加了别人的价值。
我们需要做的是把所有的$realsessions都拿出来,同时保留来自Get-VBRBackupSession原始输出的endtime。
$days = 31
$sessions = Get-VBRBackupSession | Where-Object {$_.JobType -eq "Backup" -and $_.EndTime -ge (Get-Date).AddDays(-$days)}
$realsessions = $sessions | ForEach-Object{
# Get session information
$endtime = [datetime]$_.EndTime
# Create a custom object for each real session that keeps some session info.
$_.gettasksessions() | ForEach-Object{
New-Object -TypeName PSCustomObject -Property @{
ServerName = $_.Name
JobName = $_.JobName
BackupStatus = $_.Status
EndTime = $endtime
}
}
}
# You should check the content of $realsessions to be sure it is organized right
$realsessions | Group-Object ServerName | ForEach-Object{
# Collect the server group
$serverGroup = $_.Group
# Start building the object using the first element
$props = @{
ServerName = $serverGroup[0].Name
JobName = $serverGroup[0].JobName
}
# Cycle the days and populate the status columns
for($daysIndex = 1; $daysIndex -le $days;$daysIndex++){
$props.$daysIndex = $serverGroup | Where-Object{((Get-Date).Date - ($_.Endtime).Date) -eq $daysIndex} | Select-Object -ExpandProperty Status
}
# Output the new object to the pipe.
New-Object -TypeName PSCustomObject -Property $props
} | Export-Csv -Path "C:\Temp\VeeamBackupReport.csv" -NoTypeInformation因为我没有访问Get-VBRBackupSession的权限,所以我需要您进行调试,这样我们就知道哪里在正确的轨道上。
发布于 2015-04-10 15:59:45
不太确定你想要完成什么,但是我会考虑使用逻辑来备份你的信息,根据它是哪一个月。如果这个月是新的,那么我们使用一个不同的文件。这将松散地与31天的要求保持一致。您提到您对CSV输出没有意见,但是我已经对此做得太深入了,所以让我们继续使用HTML输出。我无法访问Get-VBRBackupSession,但是您应该很难将这些代码与cmdlet结合在一起。
function ConvertFrom-HTMLTable{
param(
[string]$Path
)
$regex = "(?s)<TABLE>.*?</TABLE>"
$fileContent = Get-Content $Path -Raw
$table = (Select-String -InputObject $fileContent -Pattern $regex).Matches.Value -split "`r`n"
$properties = ($table | Where-Object{$_ -match '^\<tr\>\<th\>'}) -split '</?th>|</?tr>' | Where-Object{$_}
$table | Where-Object{$_ -match '^\<tr\>\<td\>'} | ForEach-Object{
$values = $_ -split '</?td>|</?tr>' | Where-Object{$_}
$props = @{}
for($propIndex = 0; $propIndex -lt $properties.Count; $propIndex++){
$props."$($properties[$propIndex])" = $values[$propIndex]
}
[pscustomobject]$props
}
}
$body = "<H2>Veeam Backup Report</H2>"
$head = @"
<style>"
{font-family: Arial; font-size: 10pt;}
TABLE{border: 1px solid black; border-collapse: collapse;}
TH{border: 1px solid black; background: #dddddd; padding: 5px; }
TD{border: 1px solid black; padding: 5px; }
</style>
"@
$date = get-date -Format "MMMyyyy"
$outputFile = "C:\Temp\VeeamBackupReport$date.html"
$outputData = @()
If(Test-Path $outputFile){
$outputData = ConvertFrom-HTMLTable $outputFile
}
$result = Get-ChildItem c:\temp -File | Select-Object Name,Length,LastWriteTime,@{Label="Fluff";Expression={get-date -format "mm"}}
$outputData + $result | Select-Object Name,Length,LastWriteTime,Fluff |
ConvertTo-Html -Head $format -Body $body |
Set-Content $outputFile我们看看这个月/年组合是否已经有了一个文件。如果存在,则对其运行ConvertFrom-HTMLTable以获得一个自定义对象,该对象包含与我们将要导出的属性相同的属性。一旦我们得到了新的结果,我们就合并输出并将它们返回到文件中。
我使用Get-ChildItem输出进行测试,并表明可以将自定义字段添加到输出中。同样,您应该能够用自己的代码来适应这种情况。您应该能够在没有任何更改的情况下运行此代码,并等待一两分钟,然后再运行一次,以查看发生了什么。
https://stackoverflow.com/questions/29558310
复制相似问题