# PowerShell Tile to display server and lastboottime

**URL:** <https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558>\
**Category:** PowerShell\
**Tags:** powershell\
**Created:** [September 3, 2021, 2:32pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558 "2021-09-03T14:32:33Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlbivona](https://community.squaredup.com/user_avatar/community.squaredup.com/mlbivona/32/972_2.png) [@mlbivona](https://community.squaredup.com/u/mlbivona)\
**Post date:** [September 3, 2021, 2:32pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/1 "2021-09-03T14:32:33Z")

</div>

i have a simple PowerShell Script that I am executing in a PowerShell Grid tile that returns a host name and its last boot time. The example data returns what you would see in Powershell as the name and the Date\Time. the Dashboard however renders the date\time as the number. Need some assistance on adjusting the format of the column as i am assuming that is where it is being converted back to a number. Additionally, not sure if I understand the Scoping. I want it to return all of the servers in the Group identified. using All Windows Server Computer Group in this case. Moving forward I will have to scope it tighter to a subset based on pre-existing SCOM Groups.

Script:  
Get-WmiObject Win32\_OperatingSystem | Select csname, LastBootUpTime

---

<div class="post-metadata">

**Author:** ![Badger1](https://community.squaredup.com/user_avatar/community.squaredup.com/badger1/32/845_2.png) [@Badger1](https://community.squaredup.com/u/Badger1)\
**Post date:** [September 3, 2021, 3:24pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/2 "2021-09-03T15:24:13Z")

</div>

Hey Mike

What is the format of the time returned? Is it UTC or Unix? You just have to pass it as a custom property. Depending on which time format it is, one of the following should probably work:

```auto
@{
    Name = "timestamp";
    Expression = { [DateTime]::Parse($_.timestamp) }
}

```

OR

```auto
@{
        Name = "timestamp";
        Expression = {(Get-Date 01.01.1970) + ([System.TimeSpan]::fromseconds([int]$_.starttime))}
}

```

For more examples you can refer to the Github repository and see how some of those dashboards are scripted.

> **[samples/dashboards at master · squaredup/samples](https://github.com/squaredup/samples/tree/master/dashboards)**
>
> master/dashboards

Hope this helps.

---

<div class="post-metadata">

**Author:** ![mlbivona](https://community.squaredup.com/user_avatar/community.squaredup.com/mlbivona/32/972_2.png) [@mlbivona](https://community.squaredup.com/u/mlbivona)\
**Post date:** [September 3, 2021, 3:53pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/3 "2021-09-03T15:53:51Z")

</div>

> [@mlbivona](#):
>
> Get-WmiObject Win32\_OperatingSystem | Select csname, LastBootUpTime

i am getting this output: 20210812162420.500000-300 While readable not human digestable 🙂

---

<div class="post-metadata">

**Author:** ![mlbivona](https://community.squaredup.com/user_avatar/community.squaredup.com/mlbivona/32/972_2.png) [@mlbivona](https://community.squaredup.com/u/mlbivona)\
**Post date:** [September 3, 2021, 5:42pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/4 "2021-09-03T17:42:42Z")

</div>

So I did find this in the examples:  
{{timeago(value)}}  
this changes 20210812162420.500000-300 to August 12th 2021, 12:00:00 am

Can someone point me to more documentation on the use or datetime formatting of timeago? For this particular representation, I would rather have some form of month, day, hour, seconds displayed from that time

---

<div class="post-metadata">

**Author:** ![shawn149](https://community.squaredup.com/user_avatar/community.squaredup.com/shawn149/32/822_2.png) [@shawn149](https://community.squaredup.com/u/shawn149)\
**Post date:** [September 3, 2021, 6:56pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/5 "2021-09-03T18:56:43Z")

</div>

Hi Mike,

Check out these links for more resources on the TimeAgo function:

- **[Using Timeago to convert Unix timestamps](https://support.squaredup.com/hc/en-us/articles/4402410298385-How-to-use-Custom-Labels#Timeago)**

- **[SquaredUp GitHub for TimeAgo](https://github.com/squaredup/samples/blob/master/mustache-and-custom-labels/timeago-js.md)**

But, I get the impression that you want _ **total control** _ of the formatting of the DateTime value?

If you do, then you need to format the value as a _String_ in your script.

Here is an example script that shoots out the LastBootUpTime value in three different ways.

> ```auto
> Get-WmiObject Win32_OperatingSystem | 
> Select csname, LastBootUpTime, 
> @{LABEL = 'LastBootUpTime2'; EXPRESSION = { $_.ConverttoDateTime($_.lastbootuptime) } }, 
> @{LABEL = 'LastBootUpTime3'; EXPRESSION = { ('{0:yyyy}/{0:MM}/{0:dd} {00:hh}:{00:mm}:{00:ss} {0:tt}' -f $_.ConverttoDateTime($_.lastbootuptime)).ToString()}}
> 
> ```

If you want the long-winded explanation, that begins here.

On a SquaredUp Dashboard, the first value will appear as:

> `20210831140614.094750-240`

When you apply the TimeAgo function in the Grid Column, it will then appear as:

> `August 31st 2021, 12:00:00 am`

Take note that the time value is 12:00:00 am. I have found that when working with WMI, the DateTime value is returned in a weird format. In order to get the time portion of the value, you need to reformat the value like this:

> `$_.ConverttoDateTime($_.lastbootuptime)`

This will output:

> `1630418774094.75`

And when you apply the TimeAgo function, you will get:

> `August 31st 2021, 10:06:14 am`

But if you want to format the value in a specific way, I don’t think the TimeAgo function will do that. But if you format the value as a String before it’s sent to SquaredUp, you can format it in any way that you want. Here’s an example:

> `('{0:yyyy}/{0:MM}/{0:dd} {00:hh}:{00:mm}:{00:ss} {0:tt}' -f $_.ConverttoDateTime($_.lastbootuptime)).ToString()`

This will output:

> `2021/08/31 10:06:14 PM`

Be warned, I didn’t account for any time zone drama. So, if your value is off by a couple of hours, you will need to adjust for the timezone in whatever way makes sense for you.

Hopefully, that helps.

---

<div class="post-metadata">

**Author:** ![mlbivona](https://community.squaredup.com/user_avatar/community.squaredup.com/mlbivona/32/972_2.png) [@mlbivona](https://community.squaredup.com/u/mlbivona)\
**Post date:** [September 3, 2021, 7:24pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/6 "2021-09-03T19:24:53Z")

</div>

Thank you. That does it. But it is not acting on my scope of All Windows Server computer Group, i am only getting output for the current machine I am running SquaredUP on…what am I missing there?

---

<div class="post-metadata">

**Author:** ![shawn149](https://community.squaredup.com/user_avatar/community.squaredup.com/shawn149/32/822_2.png) [@shawn149](https://community.squaredup.com/u/shawn149)\
**Post date:** [September 3, 2021, 8:29pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/7 "2021-09-03T20:29:50Z")

</div>

Hi Mike,

For the PowerShell tile, when you select a Scope for the tile, all you’re doing is passing in a pre-filled variable called

> `$scope`

into your script.

At that point, it’s up to you to loop through each item in the object. Something like this:

> ```auto
> foreach ($item in $scope) {
> $item.DisplayName
> }
> 
> ```

Then for each iteration, you would need to save off the values.

But if I am to understand you correctly, you are wanting to run that WMI query against every server that is returned via the $scope parameter? Why do you want to do that when you have SCOM? Just create a collection rule for the value and be done with it.

In other words, when you start querying other servers there will be a delay while that other server processes your request. That means the dashboard won’t show anything until everything comes back.

On the other hand, I can envision doing this for other things, so the concept is a good idea. But I worry that will be disappointed with the results (in this case, at least).

Let me know your thoughts.

---

<div class="post-metadata">

**Author:** ![mlbivona](https://community.squaredup.com/user_avatar/community.squaredup.com/mlbivona/32/972_2.png) [@mlbivona](https://community.squaredup.com/u/mlbivona)\
**Post date:** [September 3, 2021, 8:38pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/8 "2021-09-03T20:38:18Z")

</div>

> [@shawn149](#):
>
> ```auto
> foreach ($item in $scope) {
> $item.DisplayName
> }
> 
> ```

Thank you, this helps. As for why, because I was blinded by PowerShell 🙂 I will do the rule, as that makes way more sense. Then I just need to be able to make the simple tile to pull it in. Thanks Shawn

---

<div class="post-metadata">

**Author:** ![mlbivona](https://community.squaredup.com/user_avatar/community.squaredup.com/mlbivona/32/972_2.png) [@mlbivona](https://community.squaredup.com/u/mlbivona)\
**Post date:** [September 3, 2021, 8:41pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/9 "2021-09-03T20:41:28Z")

</div>

one follow-up on the scope and powershell that I just thought of… how does this handle agents in other domains, would I have to make separate groups based on domain and have different run as accounts to execute said PowerShell scripts against those scopes? Something to know for future endeavors and thank you so much for your time. i will tell you after having this for five years, the management finally see the value, so now I really get to spend more time in it. Exciting times.

---

<div class="post-metadata">

**Author:** ![shawn149](https://community.squaredup.com/user_avatar/community.squaredup.com/shawn149/32/822_2.png) [@shawn149](https://community.squaredup.com/u/shawn149)\
**Post date:** [September 3, 2021, 8:55pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/10 "2021-09-03T20:55:47Z")

</div>

Hello again!

The short answer about other domains is that it depends. 😉

In all seriousness, it depends on what you’re doing and where you’re doing it.

For discussion purposes, if you have one Management Group monitoring two domains, then there is probably a “Trust” between the two domains. In that case, just user credentials that both domains “trust” and things should be fairly seamless.

But, if you are using Gateways (and need to use credentials), things can get more difficult. At that point, you will need to beef up your script so that it uses the correct credentials for the proper domain.

If you’re monitoring with certificates, then it gets even crazier.

In my experience, I always try to write my script so that they run as local system. That way, it doesn’t matter what domain the agent is in; as long as the Monitor or Rule can run, the script will run. But as soon as you need to pass credentials, things can, and will, get messy.

I’m not sure that really answered your question, but the answer is never short when it comes to multiple domains.

---

<div class="post-metadata">

**Author:** ![mlbivona](https://community.squaredup.com/user_avatar/community.squaredup.com/mlbivona/32/972_2.png) [@mlbivona](https://community.squaredup.com/u/mlbivona)\
**Post date:** [September 10, 2021, 7:08pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/11 "2021-09-10T19:08:53Z")

</div>

Just wanted to follow up on what I have been able to do.  
We are already collecting System Uptime via Performance counter collection. System \ System Uptime.  
It is in Seconds.  
I am trying to figure out the {{}} format I can apply, where it comes out as nn Days, nn Hours, nn Seconds

---

<div class="post-metadata">

**Author:** ![Adam](https://community.squaredup.com/user_avatar/community.squaredup.com/adam/32/763_2.png) [@Adam](https://community.squaredup.com/u/Adam)\
**Post date:** [September 13, 2021, 8:49am UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/12 "2021-09-13T08:49:00Z")

</div>

Hey Mike

TL:DR  
`{{timeago(Date.now() - (value * 1000))}}`

Just to walk you through it… you’re starting with `{{value}}` which you mentioned is the number of seconds that your system has been up. Step 1 is to get the current time.

`{{Date.now()}}`

The default for this object is miliseconds so to take away your `{{value}}` which is in seconds, we multiply `{{value}}` by 1000 as `{{value * 1000}}` then subtract it from `{{Date.now()}}`

`{{Date.now() - (value * 1000)}}`

Then to make it render in the format you want, we wrap the whole thing in `{{timeago}}`

`{{timeago(Date.now() - (value * 1000))}}`

You can apply some true/false switches to `{{timeago}}` to further customise the string format. Check [this article](https://support.squaredup.com/hc/en-us/articles/4406616238609-How-to-use-Custom-Labels).

---

<div class="post-metadata">

**Author:** ![mlbivona](https://community.squaredup.com/user_avatar/community.squaredup.com/mlbivona/32/972_2.png) [@mlbivona](https://community.squaredup.com/u/mlbivona)\
**Post date:** [September 14, 2021, 5:24pm UTC](https://community.squaredup.com/t/powershell-tile-to-display-server-and-lastboottime/1558/13 "2021-09-14T17:24:54Z")

</div>

So with your help I’ve been able to display the Date of the last reboot in the Matrix tile, customized to only show the one column.

 ![image](https://community-cdn.squaredup.com/original/1X/92d04939bcf91b3abe4d658438c7f1d8a8de40ce.png)  
My goal is to get that Date to Display as NN Days, NN Hours, etc. I don’t want anyone to have to do the math.

What I am finding is that the Tile does not format in a useful way, nor is it sortable by the output. So I have created a Performance (simple Threshold) monitor and I am now trying to get it to display in a useful way. Where the Tile output shows only when That Monitor exists for the Scoped Machine, but that is another topic.

I also suppose I could do a PowerShell Discovery and collect the date, but where to put it I am still working out.

thank you for all your help
