Sunday, July 30, 2017

Last System/Computer BootUpTime

Use below code to show up system/server LastBootUptime

Get-CimInstance -ClassName win32_operatingsystem -ComputerName Server01,Server02,Server03 | select csname, lastbootuptime | SORT CSNAME

OR

Get-CimInstance -ClassName win32_operatingsystem -ComputerName (Get-Content D:\serverS.TXT) | select csname, lastbootuptime | SORT CSNAME | ft -AutoSize

OR

gwmi win32_operatingsystem -comp Server01,Server02,Server03 | select PSComputerName, @{n='BootTime';e={$_.ConvertToDateTime($_.LastBootupTime)}}

Output:
 

Get Active Sync Mobile Device Statistics Report - O365

Here we are with PS code to list and report the Active Sync Mobile Device Statistics which help us to remove unused device for important user.

Sample Report:

===================Start of Script==================
#Connecting to O365 Powershell
#Use your own parameter here to connect O365.

$date = date

# Start of script code Get-MobileDeviceStatistics

Import-Csv "C:\test\MemberList.csv" | `
foreach { Get-MobileDeviceStatistics -Mailbox $_.Alias} | `
Select-Object -Property {$input},LastSyncAttemptTime,LastSuccessSync,DeviceType,DeviceID,DeviceModel,DeviceFriendlyName,DeviceOS,Status | `
Export-Csv "C:\test\ActiveSyncData.csv" -NoTypeInformation

#>
#End of script code Get-MobileDeviceStatistics

#Importing csv File (ActiveSyncData - MobileDeviceStats).
$csvfile = Import-Csv "C:\test\ActiveSyncData.csv" |`
 select @{l='DisplayName';e={$_.'$input'.split("=};")[1]}},LastSyncAttemptTime,@{l='LastSuccessSync';e={([datetime]$_.LastSuccessSync)}},DeviceType,DeviceID,DeviceModel,DeviceFriendlyName,DeviceOS,Status |`
 sort DisplayName

$Result = @()

foreach ($user in $csvfile)
{
$Temp = $user

$Result += [PSCustomObject] @{

User = "$($User.DisplayName)"
LastSyncAttemptTime = "$($USer.LastSyncAttemptTime)"
LastSuccessSync = "$($User.LastSuccessSync)"
DeviceType = "$($User.DeviceType)"

DeviceID = "$($User.DeviceID)"
DeviceModel = "$($User.DeviceModel)"
DeviceFriendlyName = "$($User.DeviceFriendlyName)"
DeviceOS = "$($User.DeviceOS)"
Status = "$($User.Status)"
                             }
$Outputreport = "<HTML><TITLE> ActiveSync Mobile Device Report</TITLE>
                     <BODY background-color:Cornsilk>
                     <font color =""#DC143C"" face=""Microsoft Tai le"">
                     <H2> ActiveSync Device Statistics as on $date </H2></font>
                     <font color =""#B8860B"" face=""Microsoft Tai le"">
                     <H2> ActiveSync/Mobile Device Statistics </H2></font>
                     <p font size=20><font face = 'calibri'> Note: Below statistics are to highlight all registered devices. <br>Detailed device statistics is attached as an .csv file.</br></font></p>
                     <p font size=20><font face = 'calibri'> Thresholds as below: <br><font face = 'calibri'><small><i> <font color = '#FF0000'>RED </font> = Not Synced since last <b>14 days</b> <br> <font color ='#008000'>GREEN </font>= Synced in last <b>14 days</b> </i></small></br></font></font></p>
                     <Table border=2 cellpadding=2 cellspacing=2>
                     <TR bgcolor=DarkGoldenRod align=center>
                     <TD><B><font face='calibri'>User</B></TD></font>
                     <TD><B><font face='calibri'>LastSyncAttemptTime</B></TD></font>
                     <TD><B><font face='calibri'>LastSuccessSync</B></TD></font>
                     <TD><B><font face='calibri'>DeviceType</B></TD></font>
                     <TD><B><font face='calibri'>DeviceID</B></TD></font>
                     <TD><B><font face='calibri'>DeviceModel</B></TD></font>
                     <TD><B><font face='calibri'>DeviceFriendlyName</B></TD></font>
                     <TD><B><font face='calibri'>DeviceOS</B></TD></font>
                     <TD><B><font face='calibri'>Status</B></TD></font>"
Foreach($Entry in $Result)
{
if([datetime]$Entry.LastSuccessSync -lt (Get-Date).AddDays(-14)) {$Cdrivecolor="OrangeRed"}`
else{$Cdrivecolor="Chartreuse"}
$Outputreport += "<TR bgcolor=BlanchedAlmond>"
$Outputreport += "<TD><font face='calibri'>$($Entry.User)</TD></font>
<TD align=center> <font face='calibri'>$($Entry.LastSyncAttemptTime)</TD></font>
<TD align=center bgcolor = $Cdrivecolor><font face='calibri'>$($Entry.LastSuccessSync)</TD></font>
<TD align=center><font face='calibri'>$($Entry.DeviceType)</TD></font>
<TD align=center><font face='calibri'>$($Entry.DeviceID)</TD></font>
<TD align=center><font face='calibri'>$($Entry.DeviceModel)</TD></font>
<TD align=center><font face='calibri'>$($Entry.DeviceFriendlyName)</TD></font>
<TD align=center><font face='calibri'>$($Entry.DeviceOS)</TD></font>
<TD align=center><font face='calibri'>$($Entry.Status)</TD></font>"
          }
          $Outputreport += "</Table></BODY></HTML>"
          }
$body =$outputreport

$Outputreport | out-file "C:\test\ActiveSyncMobDashboard.htm"

# Sending Email
$Recipient = "EmailAddress@domain.com"
$FromAddress = "EmailAddress@domain.com"
$SMTPAddress = 'domain.com'
Send-MailMessage -To $Recipient -From $FromAddress -Subject "Users ActiveSync Device status $date" -SmtpServer $SMTPAddress -body $body -BodyAsHtml `
-attachments "C:\test\ActiveSyncData.csv"
#>
===================END of a Script=======================