I moved adaxes to a new virtual server (2022), upgraded powershell, and upgraded to 2025.1 so working through script issues. This script retrieves the last reboot for computers and now I get this error:

The term 'gwmi' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Stack trace: at , : line 1

When I run the script in powershell ise as my svcAdaxes user on the Adaxes server, it works.


$resultobj = gwmi win32operatingsystem -ComputerName %name% | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$.ConverttoDateTime($_.lastbootuptime)}}

$logmessage = $resultobj | Out-String -Stream foreach ($logline in $logmessage) { if ($logline -ne '') { $Context.LogMessage($logline, "Information") } }

$RebootTime = New-TimeSpan -Start $resultobj.LastBootUpTime -End (Get-Date)

$logmessage = 'The system was last restarted (' + $RebootTime.Days + ') days ago.' $Context.LogMessage($logmessage, "Information")

by (450 points)

1 Answer

by (306k points)
0 votes

Hello,

The thing is that Adaxes 2025.1 only uses PowerShell 7 and does not use PowerShell 5. As per our investigation, WMI is not supported in PowerShell 7. There might be workarounds, but we were not able to find anything like that.

by (450 points)
0

for others that end up here I rewrote my script which works in adaxes 2025.1 / powershell 7.

$LastBootupTime = (Get-CimInstance Win32_OperatingSystem -ComputerName '%name%').LastBootupTime

$RebootDays = ((Get-Date) - $LastbootupTime).Days

$logmessage = 'The system was last restarted ' + $RebootDays + ' days ago. (' + $LastBootupTime + ')'

$Context.LogMessage($logmessage, "Information")

Related questions

Hi, would it be possible to script a workstation in AD and also directly from our local SCCM environment ?

asked Oct 28, 2024 by ddesmedt (40 points)
0 votes
1 answer

Can anyone tell me what the adaxes system does upon initial startup? I am asking because it takes my system over 45 minutes to start responding after any restart - service or ... that normal? Is there anyway to make this take less time? Thanks. - Scott W.

asked Aug 6, 2014 by hms.scott (220 points)
0 votes
0 answers

We have AD groups that manage what VLAN a user's system is associated with based on the user's department. I have custom command to change the PC group membership if the ... business rule. (I cannot select the command) is there a way to work around this?

asked Feb 27 by stevehalvorson (150 points)
0 votes
1 answer

The report criteria would be as follows, Name/Last Logon Date of any user that was disabled in the last 30 days. Furthermore, if possible, how would I publish this to the user ... run a report and/or choose which dates to run the report, on his own? TIA

asked Nov 26, 2024 by Milan.Pathak (40 points)
0 votes
1 answer

I am experiencing that I can no longer use computed results such as password expiration date, days left, and so on. Is there any known cause of this? I have ... When sending an email through Scheduled Task, the parameter sends null data in the email.

asked Nov 22, 2024 by Daniel (160 points)
0 votes
1 answer