Octopus.Script exported 2014-05-30 by bobjwalker belongs to ‘Windows’ category.
Get computer up time.
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
Computer name
Computer
Computer to get up-time from.
Script body
Steps based on this template will execute the following PowerShell script.
$pc = $computer
$info = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer
$diff = ($info.ConvertToDateTime($info.LocalDateTime) - $info.ConvertToDateTime($info.LastBootUpTime))
$properties=[ordered]@{
'ComputerName'=$pc;
'UptimeDays'=$diff.Days;
'UptimeHours'=$diff.Hours;
'UptimeMinutes'=$diff.Minutes
'UptimeSeconds'=$diff.Seconds
}
$obj = New-Object -TypeName PSObject -Property $properties
Write-Output $obj
Provided under the Apache License version 2.0.
To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
{
"Id": "8bd69993-6c6f-4729-8455-0aa8fc07dc3c",
"Name": "Windows - Get Uptime",
"Description": "Get computer up time.",
"Version": 1,
"ExportedAt": "2014-05-30T18:33:20.536+00:00",
"ActionType": "Octopus.Script",
"Author": "bobjwalker",
"Parameters": [
{
"Name": "Computer",
"Label": "Computer name",
"HelpText": "Computer to get up-time from.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
}
],
"Properties": {
"Octopus.Action.Script.ScriptBody": "$pc = $computer\n$info = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer\n$diff = ($info.ConvertToDateTime($info.LocalDateTime) - $info.ConvertToDateTime($info.LastBootUpTime))\n \n$properties=[ordered]@{\n 'ComputerName'=$pc;\n 'UptimeDays'=$diff.Days;\n 'UptimeHours'=$diff.Hours;\n 'UptimeMinutes'=$diff.Minutes\n 'UptimeSeconds'=$diff.Seconds\n }\n $obj = New-Object -TypeName PSObject -Property $properties\n \nWrite-Output $obj",
"Octopus.Action.Script.Syntax": "PowerShell"
},
"Category": "Windows",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/windows-get-uptime.json",
"Website": "/step-templates/8bd69993-6c6f-4729-8455-0aa8fc07dc3c",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////Da3qSsLvhtb0wur6O7zuWcfxldv2aMzyK7ftpOD3s+X48Pr+0fD7d9HzHLLr4fX8xD/OcwAAAaNJREFUeNrs3cFygjAUQFECWott1f//2sJoW6kIKEzNs+euXOmcmSSGDa8oJEmSJEmSJGmsj1W1K9cpsGD1Vr2WdToVEPC+2lYvZfpVrEW0qZpF1F+MRdRugzoNlvkiarfBPk0pT8GhWUSX2yASpDlLr2+DEJBmEY1ug6whx7N0n2b30G1QlmmxHsRYp6X76yvF9vg5RYQczq8UVURI35UiFmTgShED0p6lI1eKzCHTrxS5Qk6PZ9PLDtJ9PIsJmXWlyAky6/dAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQMJCyjltF/iO3gpJUpD8s4OAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgID8T8itwwKyhbTdMr4ha8hXUwZqhICcOgyNOIkE+V5wo4MSgr1u/fp7poO+AL8K/gL8yw0UeyRB34m9iQ/pVD8L5JYTO3NI58R+AsiEEzsW5OfE3sUe/zRwYkeGnG2g2CPS7rhjF4GKP0ZwyoldxK37kFqEL/7wU0mSJEmSJOmJ+xRgAHxZTCXGdZkfAAAAAElFTkSuQmCC",
"$Meta": {
"Type": "ActionTemplate"
}
}
Page updated on Friday, May 30, 2014