0 votes

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 <ScriptBlock>, <No file>: 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")

ago by (450 points)

1 Answer

0 votes
ago by (301k points)

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.

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

0 votes
1 answer

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
0 answers

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
1 answer

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 (130 points)
0 votes
1 answer

Hello, I'm trying to create a business rule that will update a user account expiry date when that user logs in for the first time. I'm new to Adaxes, so I don't have a ... updated by a user's action, such as "Last Logon". Is it possible to make this work?

asked Mar 6, 2024 by sjjb2024 (60 points)
0 votes
1 answer

I have a specific computer property pattern for three different types of computers, which live in three different OUs and are in three different business units. I will have ... How do I enforce a property pattern for a specific business unit at creation time?

asked Jul 17, 2023 by bennett.blodinger (60 points)
3,681 questions
3,363 answers
8,515 comments
549,414 users