implemented try catch blocks on adding to hashmap to allow graceful handling of exceptions
This commit is contained in:
parent
82df61e07a
commit
a71cf2f949
@ -37,32 +37,53 @@ function ProduceHashMap {
|
|||||||
$Elements
|
$Elements
|
||||||
)
|
)
|
||||||
$HashTable =@{}
|
$HashTable =@{}
|
||||||
foreach ($elem in $Elements){
|
foreach ($elem in $Elements){
|
||||||
$indexOfFirst = $elem.IndexOf(" ")
|
$indexOfFirst = $elem.IndexOf(" ")
|
||||||
if($indexOfFirst -le 0){
|
if($indexOfFirst -le 0){
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
$date = $elem.SubString(0,$elem.IndexOf(" ",($indexOfFirst + 1)))
|
$date = $elem.SubString(0,$elem.IndexOf(" ",($indexOfFirst + 1)))
|
||||||
$timeStamp = ConvertDate($date)
|
|
||||||
$rest = $elem.Substring($elem.IndexOf(" ",($indexOfFirst + 1))+1)
|
$rest = $elem.Substring($elem.IndexOf(" ",($indexOfFirst + 1))+1)
|
||||||
$vmName = GetVMName($rest)
|
$vmName = GetVMName($rest)
|
||||||
$backUpState = DeterminState($rest)
|
$backUpState = DeterminState($rest)
|
||||||
|
$timeStamp
|
||||||
if($HashTable.ContainsKey($vmName)){
|
if($HashTable.ContainsKey($vmName)){
|
||||||
$array = $HashTable[$vmName]
|
$array = $HashTable[$vmName]
|
||||||
|
try {
|
||||||
|
$timeStamp = ConvertDate($date)
|
||||||
$array += New-Object psobject -Property @{
|
$array += New-Object psobject -Property @{
|
||||||
state = $backUpState
|
state = $backUpState
|
||||||
ts = $timeStamp
|
ts = $timeStamp
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
foreach ($i in (($array.Count-1)..0)){
|
||||||
|
Write-Host $array[$i]
|
||||||
|
if ($array[$i]["state"] -eq 'Started') {
|
||||||
|
Write-Host "found started"
|
||||||
|
$timeStamp = $array[$i]['ts']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$array += New-Object psobject -Property @{
|
||||||
|
state = $backUpState
|
||||||
|
ts = $timeStamp
|
||||||
|
}
|
||||||
|
}
|
||||||
$HashTable[$vmName]=$array
|
$HashTable[$vmName]=$array
|
||||||
} else{
|
} else {
|
||||||
|
try {
|
||||||
|
$timeStamp = ConvertDate($date)
|
||||||
$HashTable += @{$vmName=@(New-Object psobject -Property @{
|
$HashTable += @{$vmName=@(New-Object psobject -Property @{
|
||||||
state = $backUpState
|
state = $backUpState
|
||||||
ts = $timeStamp
|
ts = $timeStamp
|
||||||
})}
|
})}
|
||||||
}
|
}
|
||||||
}
|
catch {
|
||||||
$HashTable
|
<#Do nothing as key is empty and failed state#>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $HashTable
|
||||||
}
|
}
|
||||||
|
|
||||||
function getElems {
|
function getElems {
|
||||||
|
Loading…
Reference in New Issue
Block a user