Skip to content

Commit

Permalink
Add more documentation to get-lastimagetime
Browse files Browse the repository at this point in the history
  • Loading branch information
darksidemilk committed Aug 23, 2022
1 parent c9bb997 commit e56b452
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions FogApi/Public/Get-LastImageTime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ function Get-LastImageTime {
Searches the imaging log for the hostid and returns the last entries start time and image used in a descriptive string
.PARAMETER serialNumber
The serialnumber to search for, if not specified, it will prompt for input with readhost
The serialnumber to search for, if not specified, it will prompt for input with readhost if none is given
.PARAMETER hostId
Specify the hostid to get the image history for
.PARAMETER fogHost
specify the fog host object to get the last history for
.PARAMETER currentHost
switch param to get the current host's foghost object and return the last image time
.EXAMPLE
Get-LastImageTime
Expand All @@ -18,7 +27,22 @@ function Get-LastImageTime {
And return the full object of the host's imaging log
.EXAMPLE
Get-LastImageTime
Get-LastImageTime -currentHost
Will get the current computer in fog and return the last image log object.
Will also output a descriptive string, i.e. if the hostname is test-pc
hostname is test-pc, it was last imaged at 2022-08-18 12:19:38 with the image Win-10-21H2
.EXAMPLE
Get-LastImageTime -hostID 1234
Will get the foghost with the id 1234 and return the last entry in its image log
.EXAMPLE
$log = Get-LastImageTime -fogHost $hostObj;
Will put the last image history log for the given host in the $log variable.
That $log's properties can then be used in other operations
.NOTES
Implemented as part of a feature request found in the forums here https://forums.fogproject.org/post/146276
Expand Down Expand Up @@ -59,9 +83,18 @@ function Get-LastImageTime {

$imageLog = (get-fogobject -type object -coreObject imaginglog).imagingLogs # get the image history log
$hostLogs = $imageLog | where-object hostid -eq $HostID # get the image history logs for the given host
$hostLog = $hostLogs[-1] # select the last/most recent log
#return a string of the information about the serial number
"Serial number $serialNumber belongs to host $($fogHost.name), it was last imaged at $($hostLog.start) with the image $($hostLog.image)" | Out-Host
return $hostLog;
if (!$hostLogs) {
Write-Warning "No imaging logs found for host $($fogHost.name)!"
return $null;
} else {
$hostLog = $hostLogs[-1] # select the last/most recent log
#return a string of the information about the serial number
if ($serialNumber) {
"Serial number $serialNumber belongs to host $($fogHost.name), it was last imaged at $($hostLog.start) with the image $($hostLog.image)" | Out-Host
} else {
"hostname is $($fogHost.name), it was last imaged at $($hostLog.start) with the image $($hostLog.image)" | Out-Host
}
return $hostLog;
}
}
}

0 comments on commit e56b452

Please sign in to comment.