Davegbuf Posted January 22, 2019 Share Posted January 22, 2019 I found a PowerShell module in the TechNet script center that will be useful to me for detecting reboots; however, my knowledge of PowerShell is limited and I don't know how to load the a module for use with my AutoIt scripts. (in case you need it): https://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542) I loaded the PowerShell module successfully manually via the PowerShell ISE on my test machine, and ran a batch command successfully on it too. NOTE: I sometimes use a batch file commands for troubleshooting a few lines of code and then I convert the "known good" command into my final AutoIt scripts). As I mentioned, I ran the following batch command-line successfully after I had manually loaded the Powershell module via the ISE (the command displays a "True" or "False" in the Windows CMD console - see the attachment) : PowerShell -Command (Test-PendingReboot -SkipConfigurationManagerClientCheck).IsRebootPending I need to know how I can include the PowerShell module in a subfolder and load it, in addition to running the command-line mentioned above. I have used *.PS1 scripts before in my AutoIt projects, but my general knowledge of Powershell is limited and I don't know how to work with modules. Can anyone with some Powershell knowledge help me with these few lines of code needed to accomplish the goal? I would appreciate any help you can offer. Link to comment Share on other sites More sharing options...
water Posted January 22, 2019 Share Posted January 22, 2019 Should be possible by reading the registry too: https://stackoverflow.com/questions/21789594/check-for-reboot-pending-status-in-vb #include <AutoItConstants.au3> Local $sValue = RegRead("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update", "RebootRequired") If @error or $sValue <> "*" Then ; <== Replace "*" with the value you get when a reboot is required ConsoleWrite("No reboot required" & @CRLF) Else ConsoleWrite("Reboot required" & @CRLF) EndIf My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
iamtheky Posted January 22, 2019 Share Posted January 22, 2019 loading a ps1 and using it: You can use fileinstall if you need the ps1 packaged up with the script. It would be cooler to write it on the fly tho Davegbuf 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Davegbuf Posted January 22, 2019 Author Share Posted January 22, 2019 Excellent. Thank you very much! I wasn't sure if your example would work because I have a PowerShell module (*.PSM1), and your example had a PowerShell script (*.PS1) but it worked just as well. I noticed that you separated two PowerShell statements with a semicolon ";". That makes sense because I didn't get an error importing the module, but when I tried to run a function on the next line, it looks like the module was not loaded anymore. I wrote the AutoIt script below for anyone who is interested. The script displays a "True" if the machine is pending a reboot; or "False" if it is not. For other possible functions available in the PowerShell module, take a look at the comments in the pendingreboot.psm1file (I also added them to the end of the AutoIt script) . Download the module from here: https://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542 Note: The AutoIt script below only requires only the fist five characters of data for the strings "Ture" or "False"; however, you will want to comment out the two statements below the "; --- Extract Data and format" remark to display the full text returned by the function, especially if you use it with other functions in the PowerShell module. Enjoy =============================================== #include <AutoItConstants.au3> #include <StringConstants.au3> $sCommands = 'powershell -ExecutionPolicy ByPass import-module ' & @ScriptDir & _ '\pendingreboot.0.9.0.6\pendingreboot.psm1; (Test-PendingReboot -SkipConfigurationManagerClientCheck).IsRebootPending' $iPID = Run("cmd /k " & $sCommands, "", @SW_SHOW , $stdout_child) ProcessWaitClose($iPID) ; --- Wait for process to complete $sOutput=StdoutRead($iPID) ; --- Extract Data and format $sOutput=StringLeft($sOutput,5) ; --- Discard white space and extra line of text (CMD path line) $sOutput=StringStripWS($sOutput,$STR_STRIPALL) ; --- Strips 5th white space character if the returned value is "True" MsgBox(0,'Result',$sOutput) Exit #cs ============================================================================================ ; --- Excerpt Comments from the Powershell module file: pendingreboot.psm1https://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542 =============================================================================================== <# .SYNOPSIS Test the pending reboot status on a local and/or remote computer. .DESCRIPTION This function will query the registry on a local and/or remote computer and determine if the system is pending a reboot, from Microsoft/Windows updates, Configuration Manager Client SDK, Pending Computer Rename, Domain Join, Pending File Rename Operations and Component Based Servicing. ComponentBasedServicing = Component Based Servicing WindowsUpdate = Windows Update / Auto Update CCMClientSDK = SCCM 2012 Clients only (DetermineifRebootPending method) otherwise $null value PendingComputerRenameDomainJoin = Detects a pending computer rename and/or pending domain join PendingFileRenameOperations = PendingFileRenameOperations, when this property returns true, it can be a false positive PendingFileRenameOperationsValue = PendingFilerenameOperations registry value; used to filter if need be, Anti-Virus will leverage this key property for def/dat removal, giving a false positive .PARAMETER ComputerName A single computer name or an array of computer names. The default is localhost ($env:COMPUTERNAME). .PARAMETER Credential Specifies a user account that has permission to perform this action. The default is the current user. Type a username, such as User01, Domain01\User01, or User@Contoso.com. Or, enter a PSCredential object, such as an object that is returned by the Get-Credential cmdlet. When you type a user name, you are prompted for a password. .PARAMETER Detailed Indicates that this function returns a detailed result of pending reboot information, why the system is pending a reboot, not just a true/false response. .PARAMETER SkipConfigurationManagerClientCheck Indicates that this function will not test the Client SDK WMI class that is provided by the System Center Configuration Manager Client. This parameter is useful when SCCM is not used/installed on the targeted systems. .PARAMETER SkipPendingFileRenameOperationsCheck Indicates that this function will not test the PendingFileRenameOperations MultiValue String property of the Session Manager registry key. This parameter is useful for eliminating possible false positives. Many Anti-Virus packages will use the PendingFileRenameOperations MultiString Value in order to remove stale definitions and/or .dat files. .EXAMPLE PS C:\> Test-PendingReboot ComputerName IsRebootPending ------------ --------------- WKS01 True This example returns the ComputerName and IsRebootPending properties. .EXAMPLE PS C:\> (Test-PendingReboot).IsRebootPending True This example will return a bool value based on the pending reboot test for the local computer. .EXAMPLE PS C:\> Test-PendingReboot -ComputerName DC01 -Detailed ComputerName : dc01 ComponentBasedServicing : True PendingComputerRenameDomainJoin : False PendingFileRenameOperations : False PendingFileRenameOperationsValue : SystemCenterConfigManager : False WindowsUpdateAutoUpdate : True IsRebootPending : True This example will test the pending reboot status for dc01, providing detailed information .EXAMPLE PS C:\> Test-PendingReboot -ComputerName DC01 -SkipConfigurationManagerClientCheck -SkipPendingFileRenameOperationsCheck -Detailed CommputerName : dc01 ComponentBasedServicing : True PendingComputerRenameDomainJoin : False PendingFileRenameOperations : False PendingFileRenameOperationsValue : SystemCenterConfigManager : WindowsUpdateAutoUpdate : True IsRebootPending : True .LINK Background: https://blogs.technet.microsoft.com/heyscriptingguy/2013/06/10/determine-pending-reboot-statuspowershell-style-part-1/https://blogs.technet.microsoft.com/heyscriptingguy/2013/06/11/determine-pending-reboot-statuspowershell-style-part-2/ Component-Based Servicing:http://technet.microsoft.com/en-us/library/cc756291(v=WS.10).aspx PendingFileRename/Auto Update:http://support.microsoft.com/kb/2723674http://technet.microsoft.com/en-us/library/cc960241.aspxhttp://blogs.msdn.com/b/hansr/archive/2006/02/17/patchreboot.aspx CCM_ClientSDK: http://msdn.microsoft.com/en-us/libr .NOTES Author: Brian Wilhite Email: bcwilhite (at) live.com #> #ce ============================================================================================ Link to comment Share on other sites More sharing options...
Davegbuf Posted January 22, 2019 Author Share Posted January 22, 2019 3 hours ago, water said: Should be possible by reading the registry too: https://stackoverflow.com/questions/21789594/check-for-reboot-pending-status-in-vb #include <AutoItConstants.au3> Local $sValue = RegRead("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update", "RebootRequired") If @error or $sValue <> "*" Then ; <== Replace "*" with the value you get when a reboot is required ConsoleWrite("No reboot required" & @CRLF) Else ConsoleWrite("Reboot required" & @CRLF) EndIf ============================ Thank you but there are many reasons that Windows might be pending a reboot and each is tracked in different places in the registry requiring you to check all of them. My fault for not being more specific with my question. This link shows at least 12 registry keys: https://hiddencodes.wordpress.com/2013/04/24/list-of-registry-keys-involved-in-reboot-pending-decision/ The to check the registry in Windows is not consistent either (thank you Microsoft). Examples from ( https://scriptingetc.wordpress.com/2017/06/16/detect-pending-reboots/) : Pending Reboot •HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing •A reboot is pending if the RebootPending key exists NOTE: If a reboot is pending then the fill registry path adds the key to the end making it: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPendingI didn't know in AutoIt how I would compare a partial tree path since RegRead() reads key values. Pending Windows Update activity •HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update •A reboot is pending if the RebootRequired key exists Pending File Rename(s) •HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager ?Key (REG_MULTI_SZ): PendingFileRenameOperations •A reboot is pending if the value is non-zero / non-empty list of filenamesI had trouble reading these values in AutoIt and I was already frustrated enough to quit for the day Pending System Renames •HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName ?Key: ComputerName •HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName ?Key: ComputerName •A reboot is pending if the 2 values do not matchNOTE: These are registry keys, not values manes and values. I was not sure how I would compare these in AutoIt Pending EXE Modification •HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\UpdateExeVolatile •Any value indicates a pending reboot Link to comment Share on other sites More sharing options...
iamtheky Posted January 22, 2019 Share Posted January 22, 2019 let me see the command line where it 'looked like the module wasnt loaded anymore' ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
water Posted January 22, 2019 Share Posted January 22, 2019 I see. So the PowerShell approach seems to be the best fit My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now