Jump to content
iamtheky

Installed Software list - Ps + WMI + SCCM

Recommended Posts

*Requires that you are a client of SCCM in order for SMS_ to exist/populate

This is an exercise in formatting data returned from CIM via powershell via Autoit.  Should get you the meat:  name, version, location, installdate, and uninstall string. 

Short Version:  Grouped by Program

 

#RequireAdmin
#include<Array.au3>

$iPid = run("powershell (Get-CimInstance -Namespace root\cimv2\sms -ClassName SMS_InstalledSoftware | fl ProductName,InstallDate,InstalledLocation,ProductVersion,UninstallString | out-string).trim()", "" , @SW_HIDE , 0x2)

$sOutput = ""

 While ProcessExists($iPid)
        $sOutput &= StdoutRead($iPID)
 WEnd

$aOutput = stringsplit($sOutput, @LF , 2)
_ArrayDisplay($aOutput)

 

Long Version: Each Category in its own column, modular pieces.

 

;CIMClasses
#include<Array.au3>
#RequireAdmin

$iPid = run("powershell Get-CimInstance -Namespace root\cimv2\sms -ClassName SMS_InstalledSoftware | select ProductName" , "" , @SW_HIDE , 0x2)

$sOutput = ""

 While 1
        $sOutput &= StdoutRead($iPID)
        If @error Then
            ExitLoop
        EndIf
    WEnd

$aProductName = stringsplit($sOutput , @CR , 2)


;;;;;-------------------------------------------

$iPid = run("powershell Get-CimInstance -Namespace root\cimv2\sms -ClassName SMS_InstalledSoftware | select InstallDate" , "" , @SW_HIDE , 0x2)

$sOutput = ""

 While 1
        $sOutput &= StdoutRead($iPID)
        If @error Then
            ExitLoop
        EndIf
    WEnd

$aInstallDate = stringsplit($sOutput , @CR , 2)

;;;;;-------------------------------------------


$iPid = run("powershell Get-CimInstance -Namespace root\cimv2\sms -ClassName SMS_InstalledSoftware | select InstalledLocation" , "" , @SW_HIDE , 0x2)

$sOutput = ""

 While 1
        $sOutput &= StdoutRead($iPID)
        If @error Then
            ExitLoop
        EndIf
    WEnd

$aInstalledLocation = stringsplit($sOutput , @CR , 2)

;;;;;-------------------------------------------

$iPid = run("powershell Get-CimInstance -Namespace root\cimv2\sms -ClassName SMS_InstalledSoftware | select ProductVersion" , "" , @SW_HIDE , 0x2)

$sOutput = ""

 While 1
        $sOutput &= StdoutRead($iPID)
        If @error Then
            ExitLoop
        EndIf
    WEnd

$aProductVersion = stringsplit($sOutput , @CR , 2)

;;;;;-------------------------------------------

$iPid = run("powershell Get-CimInstance -Namespace root\cimv2\sms -ClassName SMS_InstalledSoftware | select UninstallString" , "" , @SW_HIDE , 0x2)

$sOutput = ""

 While 1
        $sOutput &= StdoutRead($iPID)
        If @error Then
            ExitLoop
        EndIf
    WEnd

$aUninstallString = stringsplit($sOutput , @CR , 2)

;;;;;-------------------------------------------


Local $aOut[ubound($aProductName)][5]

For $i = 0 to ubound($aProductName) - 1
    $aOut[$i][0] = $aProductName[$i]
    $aOut[$i][1] = $aInstallDate[$i]
    $aOut[$i][2] = $aInstalledLocation[$i]
    $aOut[$i][3] = $aProductVersion[$i]
    $aOut[$i][4] = $aUninstallString[$i]
Next

_ArrayDisplay($aOut , "SMS Installed Software")

 

Edited by iamtheky
added short form

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

I am just awful at powershell, and these old WMI or registry queries is how I am forcing myself to learn.  Many of these are small slices of larger scripts that pool data from Splunk/Lancope/Forti*/etc...   AutoIt is my only real option for automating the manipulation of data into different formats from many different sources.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Does not format the output for me (running on window 10 pro x86) So why no use IEnumInstalledApps directly on AutoIt.

 

Saludos

 

 

Share this post


Link to post
Share on other sites

Does not format the output for me (running on window 10 pro x86) So why no use IEnumInstalledApps directly on AutoIt.

 

Saludos

 

 

Because the method  posted here requires "System Center Configuration Manager" installed. Most private users don't have that software, which means boththose probably uses machine which is part of some bigger system.

Share this post


Link to post
Share on other sites

So why no use IEnumInstalledApps directly on AutoIt.

I dont know how and a search for "IEnumInstalledApps" in the forums returns only your reply to this thread.

And I am on Win 8.1, PS 4.0.   And I am not doing any ps formatting on the long form, just reading arrays into an array, certainly odd if that fails.

 

Because the method  posted here requires "System Center Configuration Manager" installed

True that.  I will amend to reflect the prereq.

 

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

True that.  I will amend to reflect the prereq.

 

I'm sure you knew this, but doing it directly from AutoItwithout the PowerShell and using the same algo would be:

PrintBoththosesThingInAutoItWithoutUsingPowerShell()
ConsoleWrite("@error = " & @error & ", @extended = " & Hex(@extended) & @CRLF)

Func PrintBoththosesThingInAutoItWithoutUsingPowerShell()
    Local $oErrorHandler = ObjEvent("AutoIt.Error", PrintBoththosesThingInAutoItWithoutUsingPowerShell)
    Local $oWMIService = ObjGet("winmgmts:\\.\root\cimv2\sms") ; dot means "this comp"
    If @error Then Return SetError(1, @error, "")
    Local $oItems = $oWMIService.ExecQuery("SELECT ProductName,InstallDate,InstalledLocation,ProductVersion,UninstallString FROM SMS_InstalledSoftware")
    If @error Then Return SetError(2, @error, "")
    For $oItem In $oItems
        ConsoleWrite($oItem.ProductName & @CRLF)
        ConsoleWrite(@TAB & $oItem.InstallDate & @CRLF)
        ConsoleWrite(@TAB & $oItem.InstalledLocation & @CRLF)
        ConsoleWrite(@TAB & $oItem.ProductVersion & @CRLF)
        ConsoleWrite(@TAB & $oItem.UninstallString & @CRLF)
        ConsoleWrite(@CRLF)
    Next
EndFunc

That's why it wasn't clear to me why you used PowerShell.

Share this post


Link to post
Share on other sites

ah yes, to answer that I have been on a powershell kick as of late due to projects for other business units.  Win 8 powershell made DISM stuff sexy, so being able to mount/apply/interrogate packages with a bunch of one liners would be useful for their future maintenance.

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

... ...
 Local $oItems = $oWMIService.ExecQuery("SELECT ProductName,InstallDate,InstalledLocation,ProductVersion,UninstallString FROM SMS_InstalledSoftware")
... ...

How about Win32_Product
 

#include "Array.au3"

Opt("MustDeclareVars",1)
Opt("TrayIconDebug",1)
Opt("TrayAutoPause",0)
Global $_nice_COMerrorArray, $_nice_COMerrorObj
_nice_COMerrorHandler(1) ; COM error handler.

ToolTip("mouse over the trayicon for debug info.", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Product",1,4)

Local $a = _WMI_Win32_Product()
If @error Then
    MsgBox( 262144 ,"WMI Output","No WMI Objects Found for class: " & "Win32_Product" )
Else
    Switch @extended
        Case 0
            ToolTip("Done.", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Product",1,4)
        Case 1
            ToolTip("Nothing, you've got nothing."&@CR&@CR&"Adjust the query", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Product",2,4)
        Case 2
            ToolTip("More than you can chew."&@CR&@CR&"Adjust the ""$iLimit"" or the query", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Product",2,4)
    EndSwitch
    If $_nice_COMerrorArray[0][0] Then _nice_COMerrorHandler(2)
    _Array_Rotate2D( $a )
    _ArrayDisplay( $a ,"ScriptOMatic - ""Win32_Product""")
EndIf


Func _WMI_Win32_Product( $iLimit = 1000 , $sComputer = "." , $sUser = "" , $sPassword = "" )

    ; Generated by AutoIt ScriptOMatic

    ; Description: Instances of this class represent products as they are installed by MSI.
    ;          A product generally correlates to a single installation package.


    ; Class Methods:
    ;
    ; Install
    ; Admin
    ; Advertise
    ; Reinstall
    ; Upgrade
    ; Configure
    ; Uninstall


    Local $wbemFlagReturnImmediately = 0x10
    Local $wbemFlagForwardOnly = 0x20
    Local $colItems = ""
    Local $sReturn=""
    Local $iExt = 0
    If 1 > Int( $iLimit ) Then $iLimit = 1
    Local $aReturn[1000][ Int( $iLimit ) + 1]
    $aReturn[0][0] = 0
    $aReturn[0][1] = 0

    If $sComputer & $sUser & $sPassword = "." Then
        ToolTip("...ObjGet", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Product",1,4)
        Local $oWMIService = ObjGet("winmgmts:\\" & $sComputer & "\root\CIMV2")
    Else
        ToolTip("...ObjCreate", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Product",1,4)
        Local $wmiLocator = ObjCreate("WbemScripting.SWbemLocator")
        ToolTip("...ConnectServer", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Product",1,4)
        Local $oWMIService = $wmiLocator.ConnectServer($sComputer, "\root\CIMV2", $sUser, $sPassword)
    EndIf

    ToolTip("...ExecQuery", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Product",1,4)
    Local $colItems = $oWMIService.ExecQuery("SELECT * FROM Win32_Product", _
                         "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    ToolTip("...ExecQuery executed."& @CR &"...waiting for data.", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Product",1,4)
    If IsObj($colItems) Then

        ; Class Properties: Names:
        ;

        $aReturn[  1 ][ 0 ] = "AssignmentType"
        $aReturn[  2 ][ 0 ] = "Caption"
        $aReturn[  3 ][ 0 ] = "Description"
        $aReturn[  4 ][ 0 ] = "HelpLink"
        $aReturn[  5 ][ 0 ] = "HelpTelephone"
        $aReturn[  6 ][ 0 ] = "IdentifyingNumber"
        $aReturn[  7 ][ 0 ] = "InstallDate"
        $aReturn[  8 ][ 0 ] = "InstallDate2"
        $aReturn[  9 ][ 0 ] = "InstallLocation"
        $aReturn[ 10 ][ 0 ] = "InstallSource"
        $aReturn[ 11 ][ 0 ] = "InstallState"
        $aReturn[ 12 ][ 0 ] = "Language"
        $aReturn[ 13 ][ 0 ] = "LocalPackage"
        $aReturn[ 14 ][ 0 ] = "Name"
        $aReturn[ 15 ][ 0 ] = "PackageCache"
        $aReturn[ 16 ][ 0 ] = "PackageCode"
        $aReturn[ 17 ][ 0 ] = "PackageName"
        $aReturn[ 18 ][ 0 ] = "ProductID"
        $aReturn[ 19 ][ 0 ] = "RegCompany"
        $aReturn[ 20 ][ 0 ] = "RegOwner"
        $aReturn[ 21 ][ 0 ] = "SKUNumber"
        $aReturn[ 22 ][ 0 ] = "Transforms"
        $aReturn[ 23 ][ 0 ] = "URLInfoAbout"
        $aReturn[ 24 ][ 0 ] = "URLUpdateInfo"
        $aReturn[ 25 ][ 0 ] = "Vendor"
        $aReturn[ 26 ][ 0 ] = "Version"
        $aReturn[ 27 ][ 0 ] = "WordCount"
        $aReturn[0][0] = 27
        For $objItem In $colItems
            $aReturn[0][1] = $aReturn[0][1] + 1
            If Not Mod( $aReturn[0][1] , 100 ) Then ToolTip("...adding "& $aReturn[0][1] &" of "&$iLimit &" ??", @DesktopWidth - 30,@DesktopHeight - 130, "ScriptOMatic - Win32_Product",1,4)
            If $aReturn[0][1] > $iLimit Then
                $iExt = 2
                ExitLoop
            EndIf

            ; Class Properties: Values:
            ;

            $aReturn[  1 ][ $aReturn[0][1] ] = $objItem.AssignmentType
            $aReturn[  2 ][ $aReturn[0][1] ] = $objItem.Caption
            $aReturn[  3 ][ $aReturn[0][1] ] = $objItem.Description
            $aReturn[  4 ][ $aReturn[0][1] ] = $objItem.HelpLink
            $aReturn[  5 ][ $aReturn[0][1] ] = $objItem.HelpTelephone
            $aReturn[  6 ][ $aReturn[0][1] ] = $objItem.IdentifyingNumber
            $aReturn[  7 ][ $aReturn[0][1] ] = $objItem.InstallDate
            $aReturn[  8 ][ $aReturn[0][1] ] = WMIDateStringToDate( $objItem.InstallDate2 )
            $aReturn[  9 ][ $aReturn[0][1] ] = $objItem.InstallLocation
            $aReturn[ 10 ][ $aReturn[0][1] ] = $objItem.InstallSource
            $aReturn[ 11 ][ $aReturn[0][1] ] = Win32_Product_PropertyValues_InstallState( $objItem.InstallState )
            $aReturn[ 12 ][ $aReturn[0][1] ] = $objItem.Language
            $aReturn[ 13 ][ $aReturn[0][1] ] = $objItem.LocalPackage
            $aReturn[ 14 ][ $aReturn[0][1] ] = $objItem.Name
            $aReturn[ 15 ][ $aReturn[0][1] ] = $objItem.PackageCache
            $aReturn[ 16 ][ $aReturn[0][1] ] = $objItem.PackageCode
            $aReturn[ 17 ][ $aReturn[0][1] ] = $objItem.PackageName
            $aReturn[ 18 ][ $aReturn[0][1] ] = $objItem.ProductID
            $aReturn[ 19 ][ $aReturn[0][1] ] = $objItem.RegCompany
            $aReturn[ 20 ][ $aReturn[0][1] ] = $objItem.RegOwner
            $aReturn[ 21 ][ $aReturn[0][1] ] = $objItem.SKUNumber
            $aReturn[ 22 ][ $aReturn[0][1] ] = $objItem.Transforms
            $aReturn[ 23 ][ $aReturn[0][1] ] = $objItem.URLInfoAbout
            $aReturn[ 24 ][ $aReturn[0][1] ] = $objItem.URLUpdateInfo
            $aReturn[ 25 ][ $aReturn[0][1] ] = $objItem.Vendor
            $aReturn[ 26 ][ $aReturn[0][1] ] = $objItem.Version
            $aReturn[ 27 ][ $aReturn[0][1] ] = $objItem.WordCount
        Next
        If $aReturn[0][1] = 0  Then $iExt = 1
        ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1] + 1]
        Return SetError( 0 , $iExt , $aReturn )
    Else
        ReDim $aReturn[1][2]
        Return SetError( 1 , 99 , $aReturn )
    EndIf
EndFunc

Func WMIDateStringToDate($dtmDate)
    Return (StringMid($dtmDate, 5, 2) & "/" & _
        StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
        & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

Func _Array_Rotate2D(ByRef $a)
    Local $u1 = UBound($a, 1) - 1
    If @error Then Return SetError(1)
    Local $u2 = UBound($a, 2) - 1
    If @error Then
        Local $n, $m, $u2 = 1
        Local $b[$u2][$u1 + 1]
        For $n = 0 To $u1
            For $m = 0 To 0
                $b[$m][$n] = $a[$n]
            Next
        Next
    Else
        Local $n, $m
        Local $b[$u2 + 1][$u1 + 1]
        For $n = 0 To $u1
            For $m = 0 To $u2
                $b[$m][$n] = $a[$n][$m]
            Next
        Next
    EndIf
    $a = $b
EndFunc   ;==>_Array_Rotate2D


Func Win32_Product_PropertyValues_InstallState( $value )
    Switch $value
        Case "-6"
            Return "-6 = Bad Configuration"
        Case "-2"
            Return "-2 = Invalid Argument"
        Case "-1"
            Return "-1 = Unknown Package"
        Case "1"
            Return "1 = Advertised"
        Case "2"
            Return "2 = Absent"
        Case "5"
            Return "5 = Installed"
        Case Else
            Return $value&" = ???"
    EndSwitch
EndFunc


Func _nice_COMerrorHandler($i = 0)
    If $i == 1 Then
        Dim $_nice_COMerrorArray[301][9]
        $_nice_COMerrorArray[0][0] = 0
        $_nice_COMerrorObj = ObjEvent("AutoIt.Error", "_nice_COMerrorHandler")
        Return
    EndIf
    If $i == 2 Then
        If Not @Compiled Then
            Local $s = FileRead(@ScriptFullPath)
            Local $a = StringSplit($s, @CRLF, 1)
            For $s = 1 To $_nice_COMerrorArray[0][0]
                If Int($_nice_COMerrorArray[$s][7]) > $a[0] Then ContinueLoop
                $_nice_COMerrorArray[$s][8] = StringStripWS($a[Int($_nice_COMerrorArray[$s][7])], 3)
            Next
        EndIf
        ReDim $_nice_COMerrorArray[$_nice_COMerrorArray[0][0] + 1][9]
        _ArrayDisplay($_nice_COMerrorArray, "ScriptOMatic - COM Errors intercepted ( the script will continue after this screen )")
        Return
    EndIf
    If $_nice_COMerrorArray[0][0] = 300 Then
        $_nice_COMerrorArray[0][8] = "ScriptLine: only first 300 errors shown !!!"
        Return
    EndIf
    $i = $_nice_COMerrorArray[0][0] + 1
    $_nice_COMerrorArray[0][0] = $i
    $_nice_COMerrorArray[$i][1] = "0x" & Hex($_nice_COMerrorObj, 8)
    $_nice_COMerrorArray[$i][2] = $_nice_COMerrorObj.windescription
    $_nice_COMerrorArray[$i][3] = $_nice_COMerrorObj.source
    $_nice_COMerrorArray[$i][4] = $_nice_COMerrorObj.helpfile
    $_nice_COMerrorArray[$i][5] = $_nice_COMerrorObj.helpcontext
    $_nice_COMerrorArray[$i][6] = $_nice_COMerrorObj.lastdllerror
    $_nice_COMerrorArray[$i][7] = $_nice_COMerrorObj.scriptline
    If $i == 1 Then
        $_nice_COMerrorArray[0][1] = "ErrorNumber:"
        $_nice_COMerrorArray[0][2] = "WinDescription:"
        $_nice_COMerrorArray[0][3] = "Source:"
        $_nice_COMerrorArray[0][4] = "HelpFile:"
        $_nice_COMerrorArray[0][5] = "HelpContext:"
        $_nice_COMerrorArray[0][6] = "LastDLLerror:"
        $_nice_COMerrorArray[0][7] = "ScriptLineNumber:"
        $_nice_COMerrorArray[0][8] = "ScriptLine:"
    EndIf
EndFunc   ;==>_nice_COMerrorHandler


#comments-start

List of all the Properties and Methods for \root\CIMV2:Win32_Product


Win32_Product Class Qualifiers
------------------------------

1. Description = Instances of this class represent products as they are installed by MSI.  A product generally correlates to a single installation package.
2. dynamic = -1
3. Locale = 1033
4. MappingStrings = Microsoft.MSI
5. provider = MSIProv
6. SupportsUpdate = -1
7. UUID = {CE3324AA-DB34-11d2-85FC-0000F8102E5F}


Win32_Product Class Properties and Property Qualifiers
------------------------------------------------------

1. AssignmentType
1.1. CIMTYPE = uint16
1.2. Description = Assignment type of the product.
1.3. read = -1
1.4. Values = Per-user,Per-machine

2. Caption
2.1. CIMTYPE = string
2.2. Description = A short textual description (one-line string) for the Product.
2.3. MaxLen = 64
2.4. read = -1

3. Description
3.1. CIMTYPE = string
3.2. Description = A textual description of the product.
3.3. read = -1

4. HelpLink
4.1. CIMTYPE = string
4.2. Description = The support link for the product.
4.3. read = -1

5. HelpTelephone
5.1. CIMTYPE = string
5.2. Description = The support telephone for the product.
5.3. read = -1

6. IdentifyingNumber
6.1. CIMTYPE = string
6.2. Description = Product identification such as a serial number on software, a die number on a hardware chip, or (for non-commercial Products) a project number.
6.3. key = -1
6.4. MappingStrings = MIF.DMTF|ComponentID|001.4
6.5. MaxLen = 64
6.6. read = -1

7. InstallDate
7.1. CIMTYPE = string
7.2. DEPRECATED = -1
7.3. Description = The installation date.  The InstallDate property has been deprecated in favor of the InstallDate2 property which is of type DateTime rather than String. New implementations should use the InstallDate2 property.
7.4. read = -1

8. InstallDate2
8.1. CIMTYPE = datetime
8.2. Description = The InstallDate2 property represents the installation date of the product.
8.3. read = -1

9. InstallLocation
9.1. CIMTYPE = string
9.2. Description = The location of the installed product.
9.3. read = -1

10. InstallSource
10.1. CIMTYPE = string
10.2. Description = The installation source directory of the product.
10.3. read = -1

11. InstallState
11.1. CIMTYPE = sint16
11.2. Description = The installed state of the product.
11.3. read = -1
11.4. ValueMap = -6,-2,-1,1,2,5
11.5. Values = Bad Configuration,Invalid Argument,Unknown Package,Advertised,Absent,Installed

12. Language
12.1. CIMTYPE = string
12.2. Description = The language of the product.
12.3. read = -1

13. LocalPackage
13.1. CIMTYPE = string
13.2. Description = The location of the locally cached package for this product.
13.3. read = -1

14. Name
14.1. CIMTYPE = string
14.2. Description = Commonly used product name.
14.3. key = -1
14.4. MappingStrings = MIF.DMTF|ComponentID|001.2
14.5. MaxLen = 256
14.6. read = -1

15. PackageCache
15.1. CIMTYPE = string
15.2. Description = The location of the locally cached package for this product.
15.3. read = -1

16. PackageCode
16.1. CIMTYPE = string
16.2. Description = The identifier for the package from which this product was installed.
16.3. read = -1

17. PackageName
17.1. CIMTYPE = string
17.2. Description = The original package name for the product.
17.3. read = -1

18. ProductID
18.1. CIMTYPE = string
18.2. Description = The product ID.
18.3. read = -1

19. RegCompany
19.1. CIMTYPE = string
19.2. Description = The company registered to use the product.
19.3. read = -1

20. RegOwner
20.1. CIMTYPE = string
20.2. Description = The owner registered to use the product.
20.3. read = -1

21. SKUNumber
21.1. CIMTYPE = string
21.2. Description = Product SKU (stock keeping unit) information.
21.3. MaxLen = 64
21.4. read = -1

22. Transforms
22.1. CIMTYPE = string
22.2. Description = The transforms of the product.
22.3. read = -1

23. URLInfoAbout
23.1. CIMTYPE = string
23.2. Description = The URL information for the product.
23.3. read = -1

24. URLUpdateInfo
24.1. CIMTYPE = string
24.2. Description = The URL update information the product.
24.3. read = -1

25. Vendor
25.1. CIM_Key = -1
25.2. CIMTYPE = string
25.3. Description = The name of the Product's supplier, or entity selling the Product (the manufacturer, reseller, OEM, etc.). Corresponds to the Vendor property in the Product object in the DMTF Solution Exchange Standard.
25.4. MappingStrings = MIF.DMTF|ComponentID|001.1
25.5. MaxLen = 256
25.6. read = -1

26. Version
26.1. CIMTYPE = string
26.2. Description = Product version information.  Corresponds to the Version property in the product object in the DMTF Solution Exchange Standard.
26.3. key = -1
26.4. MappingStrings = MIF.DMTF|ComponentID|001.3
26.5. MaxLen = 64
26.6. read = -1

27. WordCount
27.1. CIMTYPE = uint32
27.2. Description = Summary information word count for the product
27.3. read = -1


Win32_Product Class Methods and Method Qualifiers
-------------------------------------------------

1. Install
1.1. Description = This method Will install an associated Win32_Product using the installation package provided through PackageLocation and any command line options that are supplied. The method can return the following values:
0 - Success.
2147549445 - RPC Server Fault Error. 
Other - For integer values other than those listed above, refer to the documentation on error codes returned by the Windows Installer API and the Win32 error codes.
1.2. Implemented = -1
1.3. static = -1
1.4. ValueMap = 0,2147549445,..
1.5. Values = Success,RPC Server Fault Error,Other

2. Admin
2.1. Description = This method will preform an administrative install of an associated Win32_Product using the installation package provided through PackageLocation and any command line options that are supplied. The method can return the following values:
0 - Success.
2147549445 - RPC Server Fault Error. 
Other - For integer values other than those listed above, refer to the documentation on error codes returned by the Windows Installer API and the Win32 error codes.
2.2. Implemented = -1
2.3. static = -1
2.4. ValueMap = 0,2147549445,..
2.5. Values = Success,RPC Server Fault Error,Other

3. Advertise
3.1. Description = This method will advertise an associated Win32_Product using the installation package provided through PackageLocation and any command line options that are supplied. The method can return the following values:
0 - Success.
2147549445 - RPC Server Fault Error. 
Other - For integer values other than those listed above, refer to the documentation on error codes returned by the Windows Installer API and the Win32 error codes.
3.2. Implemented = -1
3.3. static = -1
3.4. ValueMap = 0,2147549445,..
3.5. Values = Success,RPC Server Fault Error,Other

4. Reinstall
4.1. Description = This method will reinstall the associated instance of Win32_Product using the specified reinstallation mode. The method can return the following values:
0 - Success.
2147549445 - RPC Server Fault Error. 
Other - For integer values other than those listed above, refer to the documentation on error codes returned by the Windows Installer API and the Win32 error codes.
4.2. Implemented = -1
4.3. ValueMap = 0,2147549445,..
4.4. Values = Success,RPC Server Fault Error,Other

5. Upgrade
5.1. Description = This method will upgrade the associated Win32_Product using the upgrade package provided through PackageLocation and any command line options that are supplied. The method can return the following values:
0 - Success.
2147549445 - RPC Server Fault Error. 
Other - For integer values other than those listed above, refer to the documentation on error codes returned by the Windows Installer API and the Win32 error codes.
5.2. Implemented = -1
5.3. ValueMap = 0,2147549445,..
5.4. Values = Success,RPC Server Fault Error,Other

6. Configure
6.1. Description = This method will configure the associated instance of Win32_Product to the specified install state and level. The method can return the following values:
0 - Success.
2147549445 - RPC Server Fault Error. 
Other - For integer values other than those listed above, refer to the documentation on error codes returned by the Windows Installer API and the Win32 error codes.
6.2. Implemented = -1
6.3. ValueMap = 0,2147549445,..
6.4. Values = Success,RPC Server Fault Error,Other

7. Uninstall
7.1. Description = This method will uninstall the associated instance of Win32_Product. The method can return the following values:
0 - Success.
2147549445 - RPC Server Fault Error. 
Other - For integer values other than those listed above, refer to the documentation on error codes returned by the Windows Installer API and the Win32 error codes.
7.2. Implemented = -1
7.3. ValueMap = 0,2147549445,..
7.4. Values = Success,RPC Server Fault Error,Other

#Comments-End

 

Share this post


Link to post
Share on other sites

That's awesome.  Seems faster than all the regread threads I played in.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By TheyCallMeBacon
      Has anyone had success managing LAPS with AutoIT?  (LAPS is Microsoft's Local Admin Password Solution.)
      I am running v3.3.14.2 and Powershell 5.1.17134.858 on Windows 10 1803 build 17134.885.
      I have read the entire AutoIT Help file, all of the AD UDF scripts and supporting HTML files, and a large part of the Internet and have researched myself into paralysis.
      My company has more than one domain with two-way trusts and use LAPS on each domain.  At present, we remote in to a jump box in each domain when we need to manage a device there. I want to build a multiple-domain console that works just like the LAPS UI, but allows the user to select a domain via pull-down. 
      At this point, I can't even get the crazy thing to work on the current domain.  
      If I feed it $sComputername = 'T4211BLC1' 
      $sComputerName = GUICtrlRead($idComputerName) $iPID = Run('powershell.exe -executionpolicy bypass Get-AdmPwdPassword "' & $sComputerName & '"', "c:\", @SW_Show, $STDOUT_CHILD) ; Wait until the process has closed using the PID returned by Run. ProcessWaitClose($iPID) ; Read the Stdout stream of the PID returned by Run. While 1 $sOutput = StdoutRead($iPID) if @error then ExitLoop if $sOutput <> "" Then $sStdout = $sStdout & @CRLF & $sOutput WEnd sends this to the console:
      Get-AdmPwdPassword : The term 'Get-AdmPwdPassword' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + Get-AdmPwdPassword T4211BLC1 + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-AdmPwdPassword:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException But if I put this on the Windows command line:
      powershell.exe -executionpolicy bypass Get-AdmPwdPassword "T4211BLC1" ...it runs perfectly.
      ComputerName DistinguishedName Password Expiration Timestamp ------------ ----------------- -------- ---------- T4211BLC1 CN=T4211BLC1,OU=GPO Computers Testing OU,O... YQc7Cl39wFrIF5 6/10/20... So (if you're still awake),
      Why can't Powershell find 'Get-AdmPwdPassword' when called from within AutoIT? Why can't I read STDOUT? FYI - I've tried ShellExecute, and calling a .ps1 from the script, even Run('cmd /k ...) and I get the same result - Powershell doesn't recognize the cmdlet.
      Thanks in advance!!
    • By a350
      I send a string Sun is shining, the weather is sweet to my Powershell script for converting text to JSON request and then to speech.
      This snippet works as intended:
      $CMD = "powershell " & $powershellScript & " -Text '" & $sText & "' -Path " & $outputFile[1] & ".wav" $execCommand = Run($CMD, '' , @SW_HIDE, 0x2) This one differs only by single quotes:
      $CMD = 'powershell ' & $powershellScript & ' -Text "' & $sText & '" -Path ' & $outputFile[1] & '.wav' $execCommand = Run($CMD, '' , @SW_HIDE, 0x2) And only the first word Sun is voiced for some reason.
      I wonder why is it so and is it on Autoit side or PS/JSON?
    • By AdamUL
      Below are some functions that I created when I needed to get some Group Policy information via script.  The quickest way I found to get this information was using the Group Policy Module for PowerShell.  This is not a full UDF for the Group Policy Module.  There are a lot more options available with the cmdlets, and this only touches on a few.  To use the functions below, for a Windows client, you will need to install Remote Server Administration Tools (RSAT).  For Windows Server 2012 or later, you will need to install the Group Policy Management Console.  
      Remote Server Administration Tools (RSAT)
      Installing the Group Policy Management Console via PowerShell for Windows Server 2012 or later.  Run in an Admin PowerShell prompt.
      Install-WindowsFeature –Name GPMC PowerShell Group Policy Module Documentation
      For the example below, the AD UDF is only required to query GPO names, but is not required to use the functions.  
      #include <AD.au3> #include <WinAPIFiles.au3> Global $sLDAPFilter = "(name=*)" Global $sExcludeFilter = "" Global $sIncludeFilter = "" Global $sBaseDN = "DC=ad,DC=university,DC=edu" Global $sDataToRetrieve = "sAMAccountName" $sIncludeFilter = "(&(displayName=LIBS-*))" ;GPO Names. $sLDAPFilter = "(&(objectClass=groupPolicyContainer)" & $sExcludeFilter & $sIncludeFilter & ")" $sDataToRetrieve = "displayName,name" _AD_Open() Global $aGPONames = _AD_GetObjectsInOU($sBaseDN, $sLDAPFilter, 2, $sDataToRetrieve) If @error Then MsgBox(64, "Active Directory Functions", "No objects found") Exit _AD_Close() EndIf _AD_Close() ;Add column headers to the output array. Global $aDataToRetrieve = StringSplit($sDataToRetrieve, ",", 2) For $i = 0 To UBound($aGPONames, 2) - 1 Step 1 $aGPONames[0][$i] = $aDataToRetrieve[$i] Next _ArraySort($aGPONames) _ArrayDisplay($aGPONames, "LIBS GPOs") ;For Testing. Global $aGPOPermissions = _AD_GetGPOPermissionsPS($aGPONames[1][0]) If @error Then Exit 1 _ArrayDisplay($aGPOPermissions, $aGPONames[1][0]) Global $sOU = "OU=libs,OU=active,DC=ad,DC=university,DC=edu" Global $aGPOLinks = _AD_GetGPOLinksPS($sOU) If @error Then Exit 2 _ArrayDisplay($aGPOLinks, $sOU) Global $aGPOInheritedLinks = _AD_GetGPOInheritedLinksPS($sOU) If @error Then Exit 2 _ArrayDisplay($aGPOInheritedLinks, $sOU) Global $aGPOs = _AD_GetAllGPOsPS() If @error Then Exit 3 _ArraySort($aGPOs) _ArrayDisplay($aGPOs, "GPOs") Global $aGPOName = _AD_GetGPOByNamePS($aGPONames[1][0]) If @error Then Exit 4 _ArrayDisplay($aGPOName, $aGPONames[1][0]) Global $aGPOGuid = _AD_GetGPOByGuidPS($aGPONames[1][1]) If @error Then Exit 5 _ArrayDisplay($aGPOGuid, $aGPONames[1][1]) Global $sReportName = "C:\Users\adamul\Desktop\Group Policy Object (GPO) PowerShell\Reports\" & $aGPONames[1][0] & ".html" _AD_GetGPOReportByNamePS($aGPONames[1][0], $sReportName) If @error Then Exit 6 Global $sReportGUID = "C:\Users\adamul\Desktop\Group Policy Object (GPO) PowerShell\Reports\" & $aGPONames[1][1] & ".html" _AD_GetGPOReportByGuidPS($aGPONames[1][1], $sReportGUID) If @error Then Exit 6 Func _AD_GetGPOPermissionsPS($sGPOName) ;An array of permission level for one or more security principals on a specified GPO. Local $sGPOCmd = 'powershell "Import-Module GroupPolicy; Get-GPPermissions -Name ''' & $sGPOName & ''' -All"' ConsoleWrite($sGPOCmd & @CRLF) ;Turn off redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False) Local $iPIDGPOCmd = Run($sGPOCmd, @SystemDir, @SW_HIDE, $STDERR_MERGED) ProcessWaitClose($iPIDGPOCmd) ;Turn on redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(True) Local $sGPOCmdOutput = StringStripWS(StdoutRead($iPIDGPOCmd), 3) ;~ ConsoleWrite($sGPOCmdOutput & @CRLF & @CRLF) ;For testing. Local $iGPOCmdOutputSS = StringInStr($sGPOCmdOutput, @CRLF & @CRLF) If $iGPOCmdOutputSS = 0 Then Return SetError(1, 0, 0) Local $sGPOCmdOutputSS = StringMid($sGPOCmdOutput, 1, $iGPOCmdOutputSS) ;~ ConsoleWrite(@CRLF & @CRLF & $sGPOCmdOutputSS & @CRLF) Local $sRegEx = "([^:\r\n]*):.*" Local $aProperties = StringRegExp($sGPOCmdOutputSS, $sRegEx, 3) ;~ _ArrayDisplay($aProperties) ;For testing. If StringInStr($sGPOCmdOutput, "ArgumentException") Then Return SetError(2, 0, 0) ;Get data on multiple lines to a single line. $sGPOCmdOutput = StringRegExpReplace($sGPOCmdOutput, "(\r\n\h{2,})", "") Local $aGPOCmdOutput = StringSplit($sGPOCmdOutput, @CRLF & @CRLF, 1) ;~ _ArrayDisplay($aGPOCmdOutput) ;For testing. ;Convert from a list output to a 2D array. Local $aGPOCmdOutput2D[$aGPOCmdOutput[0]][UBound($aProperties)] Local $aTemp For $i = 1 To $aGPOCmdOutput[0] Step 1 $aTemp = StringSplit($aGPOCmdOutput[$i], @CRLF, 1) For $j = 1 To $aTemp[0] Step 1 For $k = 0 To UBound($aProperties) - 1 Step 1 If StringInStr($aTemp[$j], $aProperties[$k]) Then $aGPOCmdOutput2D[$i - 1][$k] = StringStripWS(StringReplace($aTemp[$j], $aProperties[$k] & ":", ""), 3) EndIf Next Next Next ;~ _ArrayDisplay($aGPOCmdOutput2D) ;For testing. For $i = 0 To UBound($aProperties) - 1 Step 1 $aProperties[$i] = StringStripWS($aProperties[$i], 3) Next _ArrayTranspose($aProperties) _ArrayConcatenate($aProperties, $aGPOCmdOutput2D) Return $aProperties EndFunc ;==>_AD_GetGPOPermissionsPS Func _AD_GetGPOLinksPS($sOUName) ;An array of GPOs that are linked directly to the location. Local $sGPOCmd = 'powershell "Import-Module GroupPolicy; (Get-GPInheritance -Target ''' & $sOUName & "').GpoLinks" ConsoleWrite($sGPOCmd & @CRLF) ;Turn off redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False) Local $iPIDGPOCmd = Run($sGPOCmd, @SystemDir, @SW_HIDE, $STDERR_MERGED) ProcessWaitClose($iPIDGPOCmd) ;Turn on redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(True) Local $sGPOCmdOutput = StringStripWS(StdoutRead($iPIDGPOCmd), 3) ;~ ConsoleWrite($sGPOCmdOutput & @CRLF & @CRLF) ;For testing. Local $iGPOCmdOutputSS = StringInStr($sGPOCmdOutput, @CRLF & @CRLF) If $iGPOCmdOutputSS = 0 Then Return SetError(1, 0, 0) Local $sGPOCmdOutputSS = StringMid($sGPOCmdOutput, 1, $iGPOCmdOutputSS) ;~ ConsoleWrite(@CRLF & @CRLF & $sGPOCmdOutputSS & @CRLF) ;For testing. Local $sRegEx = "([^:\r\n]*):.*" Local $aProperties = StringRegExp($sGPOCmdOutputSS, $sRegEx, 3) ;~ _ArrayDisplay($aProperties) ;For testing. If StringInStr($sGPOCmdOutput, "ArgumentException") Then Return SetError(1, 0, 0) ;Get data on multiple lines to a single line. $sGPOCmdOutput = StringRegExpReplace($sGPOCmdOutput, "(\r\n\h{2,})", "") Local $aGPOCmdOutput = StringSplit($sGPOCmdOutput, @CRLF & @CRLF, 1) ;~ _ArrayDisplay($aGPOCmdOutput) ;For testing. ;Convert from a list output to a 2D array. Local $aGPOCmdOutput2D[$aGPOCmdOutput[0]][UBound($aProperties)] Local $aTemp For $i = 1 To $aGPOCmdOutput[0] Step 1 $aTemp = StringSplit($aGPOCmdOutput[$i], @CRLF, 1) For $j = 1 To $aTemp[0] Step 1 For $k = 0 To UBound($aProperties) - 1 Step 1 If StringInStr($aTemp[$j], $aProperties[$k]) Then $aGPOCmdOutput2D[$i - 1][$k] = StringStripWS(StringReplace($aTemp[$j], $aProperties[$k] & ":", ""), 3) EndIf Next Next Next ;~ _ArrayDisplay($aGPOCmdOutput2D) ;For testing. For $i = 0 To UBound($aProperties) - 1 Step 1 $aProperties[$i] = StringStripWS($aProperties[$i], 3) Next _ArrayTranspose($aProperties) _ArrayConcatenate($aProperties, $aGPOCmdOutput2D) Return $aProperties EndFunc ;==>_AD_GetGPOLinksPS Func _AD_GetGPOInheritedLinksPS($sOUName) ;An array of GPOs that are applied to the location when Group Policy is processed on a client. Local $sGPOCmd = 'powershell "Import-Module GroupPolicy; (Get-GPInheritance -Target ''' & $sOUName & "').InheritedGpoLinks" ConsoleWrite($sGPOCmd & @CRLF) ;Turn off redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False) Local $iPIDGPOCmd = Run($sGPOCmd, @SystemDir, @SW_HIDE, $STDERR_MERGED) ProcessWaitClose($iPIDGPOCmd) ;Turn on redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(True) Local $sGPOCmdOutput = StringStripWS(StdoutRead($iPIDGPOCmd), 3) ;~ ConsoleWrite($sGPOCmdOutput & @CRLF & @CRLF) ;For testing. Local $iGPOCmdOutputSS = StringInStr($sGPOCmdOutput, @CRLF & @CRLF) If $iGPOCmdOutputSS = 0 Then Return SetError(1, 0, 0) Local $sGPOCmdOutputSS = StringMid($sGPOCmdOutput, 1, $iGPOCmdOutputSS) ;~ ConsoleWrite(@CRLF & @CRLF & $sGPOCmdOutputSS & @CRLF) ;For testing. Local $sRegEx = "([^:\r\n]*):.*" Local $aProperties = StringRegExp($sGPOCmdOutputSS, $sRegEx, 3) ;~ _ArrayDisplay($aProperties) ;For testing. If StringInStr($sGPOCmdOutput, "ArgumentException") Then Return SetError(1, 0, 0) ;Get data on multiple lines to a single line. $sGPOCmdOutput = StringRegExpReplace($sGPOCmdOutput, "(\r\n\h{2,})", "") Local $aGPOCmdOutput = StringSplit($sGPOCmdOutput, @CRLF & @CRLF, 1) ;~ _ArrayDisplay($aGPOCmdOutput) ;For testing. ;Convert from a list output to a 2D array. Local $aGPOCmdOutput2D[$aGPOCmdOutput[0]][UBound($aProperties)] Local $aTemp For $i = 1 To $aGPOCmdOutput[0] Step 1 $aTemp = StringSplit($aGPOCmdOutput[$i], @CRLF, 1) For $j = 1 To $aTemp[0] Step 1 For $k = 0 To UBound($aProperties) - 1 Step 1 If StringInStr($aTemp[$j], $aProperties[$k]) Then $aGPOCmdOutput2D[$i - 1][$k] = StringStripWS(StringReplace($aTemp[$j], $aProperties[$k] & ":", ""), 3) EndIf Next Next Next ;~ _ArrayDisplay($aGPOCmdOutput2D) ;For testing. For $i = 0 To UBound($aProperties) - 1 Step 1 $aProperties[$i] = StringStripWS($aProperties[$i], 3) Next _ArrayTranspose($aProperties) _ArrayConcatenate($aProperties, $aGPOCmdOutput2D) Return $aProperties EndFunc ;==>_AD_GetGPOInheritedLinksPS Func _AD_GetAllGPOsPS() ;An array of information on all the GPOs in a domain. Local $sGPOCmd = 'powershell "Import-Module GroupPolicy; Get-GPO -All"' ConsoleWrite($sGPOCmd & @CRLF) ;Turn off redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False) Local $iPIDGPOCmd = Run($sGPOCmd, @SystemDir, @SW_HIDE, $STDERR_MERGED) ProcessWaitClose($iPIDGPOCmd) ;Turn on redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(True) Local $sGPOCmdOutput = StringStripWS(StdoutRead($iPIDGPOCmd), 3) ;~ ConsoleWrite($sGPOCmdOutput & @CRLF & @CRLF) ;For testing. Local $iGPOCmdOutputSS = StringInStr($sGPOCmdOutput, @CRLF & @CRLF) If $iGPOCmdOutputSS = 0 Then Return SetError(1, 0, 0) Local $sGPOCmdOutputSS = StringMid($sGPOCmdOutput, 1, $iGPOCmdOutputSS) ;~ ConsoleWrite(@CRLF & @CRLF & $sGPOCmdOutputSS & @CRLF) ;For testing. Local $sRegEx = "([^:\r\n]*):.*" Local $aProperties = StringRegExp($sGPOCmdOutputSS, $sRegEx, 3) ;~ _ArrayDisplay($aProperties) If StringInStr($sGPOCmdOutput, "ArgumentException") Then Return SetError(1, 0, 0) ;Get data on multiple lines to a single line. $sGPOCmdOutput = StringRegExpReplace($sGPOCmdOutput, "(\r\n\h{2,})", "") Local $aGPOCmdOutput = StringSplit($sGPOCmdOutput, @CRLF & @CRLF, 1) ;~ _ArrayDisplay($aGPOCmdOutput) ;For testing. ;Convert from a list output to a 2D array. Local $aGPOCmdOutput2D[$aGPOCmdOutput[0]][UBound($aProperties)] Local $aTemp For $i = 1 To $aGPOCmdOutput[0] Step 1 $aTemp = StringSplit($aGPOCmdOutput[$i], @CRLF, 1) For $j = 1 To $aTemp[0] Step 1 For $k = 0 To UBound($aProperties) - 1 Step 1 If StringInStr($aTemp[$j], $aProperties[$k]) Then $aGPOCmdOutput2D[$i - 1][$k] = StringStripWS(StringReplace($aTemp[$j], $aProperties[$k] & ":", ""), 3) EndIf Next Next Next ;~ _ArrayDisplay($aGPOCmdOutput2D) ;For testing. For $i = 0 To UBound($aProperties) - 1 Step 1 $aProperties[$i] = StringStripWS($aProperties[$i], 3) Next _ArrayTranspose($aProperties) _ArrayConcatenate($aProperties, $aGPOCmdOutput2D) Return $aProperties EndFunc ;==>_AD_GetAllGPOsPS Func _AD_GetGPOByNamePS($sGPOName) ;An array of information on one Group Policy Object (GPO) in a domain by Display Name. Local $sGPOCmd = 'powershell "Import-Module GroupPolicy; Get-GPO -Name ''' & $sGPOName & '''"' ConsoleWrite($sGPOCmd & @CRLF) ;Turn off redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False) Local $iPIDGPOCmd = Run($sGPOCmd, @SystemDir, @SW_HIDE, $STDERR_MERGED) ProcessWaitClose($iPIDGPOCmd) ;Turn on redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(True) Local $sGPOCmdOutput = StringStripWS(StdoutRead($iPIDGPOCmd), 3) ;~ ConsoleWrite($sGPOCmdOutput & @CRLF & @CRLF) ;For testing. ;Add end of line characters for single return group to be processed. $sGPOCmdOutput = $sGPOCmdOutput & @CRLF & @CRLF Local $iGPOCmdOutputSS = StringInStr($sGPOCmdOutput, @CRLF & @CRLF) If $iGPOCmdOutputSS = 0 Then Return SetError(1, 0, 0) Local $sGPOCmdOutputSS = StringMid($sGPOCmdOutput, 1, $iGPOCmdOutputSS) ConsoleWrite(@CRLF & @CRLF & $sGPOCmdOutputSS & @CRLF) Local $sRegEx = "([^:\r\n]*):.*" Local $aProperties = StringRegExp($sGPOCmdOutputSS, $sRegEx, 3) ;~ _ArrayDisplay($aProperties) ;For testing. If StringInStr($sGPOCmdOutput, "ArgumentException") Then Return SetError(1, 0, 0) ;Get data on multiple lines to a single line. $sGPOCmdOutput = StringRegExpReplace($sGPOCmdOutput, "(\r\n\h{2,})", "") ;Remove last @CRLF to prevent blank row in return array. $sGPOCmdOutput = StringTrimRight($sGPOCmdOutput, 2) Local $aGPOCmdOutput = StringSplit($sGPOCmdOutput, @CRLF & @CRLF, 1) ;~ _ArrayDisplay($aGPOCmdOutput) ;For testing. ;Convert from a list output to a 2D array. Local $aGPOCmdOutput2D[$aGPOCmdOutput[0]][UBound($aProperties)] ;~ _ArrayDisplay($aGPOCmdOutput2D) ;For testing. Local $aTemp For $i = 1 To $aGPOCmdOutput[0] Step 1 $aTemp = StringSplit($aGPOCmdOutput[$i], @CRLF, 1) For $j = 1 To $aTemp[0] Step 1 For $k = 0 To UBound($aProperties) - 1 Step 1 If StringInStr($aTemp[$j], $aProperties[$k]) Then $aGPOCmdOutput2D[$i - 1][$k] = StringStripWS(StringReplace($aTemp[$j], $aProperties[$k] & ":", ""), 3) EndIf Next Next Next ;~ _ArrayDisplay($aGPOCmdOutput2D) ;For testing. For $i = 0 To UBound($aProperties) - 1 Step 1 $aProperties[$i] = StringStripWS($aProperties[$i], 3) Next _ArrayTranspose($aProperties) _ArrayConcatenate($aProperties, $aGPOCmdOutput2D) Return $aProperties EndFunc ;==>_AD_GetGPOByNamePS Func _AD_GetGPOByGuidPS($sGPOGuid) ;An array of information on one Group Policy Object (GPO) in a domain by GUID. Local $sGPOCmd = 'powershell "Import-Module GroupPolicy; Get-GPO -Guid ''' & $sGPOGuid & '''"' ConsoleWrite($sGPOCmd & @CRLF) ;Turn off redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False) Local $iPIDGPOCmd = Run($sGPOCmd, @SystemDir, @SW_HIDE, $STDERR_MERGED) ProcessWaitClose($iPIDGPOCmd) ;Turn on redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(True) Local $sGPOCmdOutput = StringStripWS(StdoutRead($iPIDGPOCmd), 3) ;~ ConsoleWrite($sGPOCmdOutput & @CRLF & @CRLF) ;For testing. ;Add end of line characters for single return group to be processed. $sGPOCmdOutput = $sGPOCmdOutput & @CRLF & @CRLF Local $iGPOCmdOutputSS = StringInStr($sGPOCmdOutput, @CRLF & @CRLF) If $iGPOCmdOutputSS = 0 Then Return SetError(1, 0, 0) Local $sGPOCmdOutputSS = StringMid($sGPOCmdOutput, 1, $iGPOCmdOutputSS) ;~ ConsoleWrite(@CRLF & @CRLF & $sGPOCmdOutputSS & @CRLF) ;For testing. Local $sRegEx = "([^:\r\n]*):.*" Local $aProperties = StringRegExp($sGPOCmdOutputSS, $sRegEx, 3) ;~ _ArrayDisplay($aProperties) ;For testing. If StringInStr($sGPOCmdOutput, "ArgumentException") Then Return SetError(1, 0, 0) ;Get data on multiple lines to a single line. $sGPOCmdOutput = StringRegExpReplace($sGPOCmdOutput, "(\r\n\h{2,})", "") ;Remove last @CRLF to prevent blank row in return array. $sGPOCmdOutput = StringTrimRight($sGPOCmdOutput, 2) Local $aGPOCmdOutput = StringSplit($sGPOCmdOutput, @CRLF & @CRLF, 1) ;~ _ArrayDisplay($aGPOCmdOutput) ;For testing. ;Convert from a list output to a 2D array. Local $aGPOCmdOutput2D[$aGPOCmdOutput[0]][UBound($aProperties)] ;~ _ArrayDisplay($aGPOCmdOutput2D) Local $aTemp For $i = 1 To $aGPOCmdOutput[0] Step 1 $aTemp = StringSplit($aGPOCmdOutput[$i], @CRLF, 1) For $j = 1 To $aTemp[0] Step 1 For $k = 0 To UBound($aProperties) - 1 Step 1 If StringInStr($aTemp[$j], $aProperties[$k]) Then $aGPOCmdOutput2D[$i - 1][$k] = StringStripWS(StringReplace($aTemp[$j], $aProperties[$k] & ":", ""), 3) EndIf Next Next Next ;~ _ArrayDisplay($aGPOCmdOutput2D) ;For testing. For $i = 0 To UBound($aProperties) - 1 Step 1 $aProperties[$i] = StringStripWS($aProperties[$i], 3) Next _ArrayTranspose($aProperties) _ArrayConcatenate($aProperties, $aGPOCmdOutput2D) Return $aProperties EndFunc ;==>_AD_GetGPOByGuidPS Func _AD_GetGPOReportByNamePS($sGPOName, $sReportFullPath, $sReportType = "HTML") ;Generates a report either in XML or HTML format for a specified GPO by name in a domain. Switch $sReportType Case "HTML", "XML" Case Else Return SetError(1, 0, False) EndSwitch Local $sPath = StringRegExpReplace($sReportFullPath, "(^.*\\)(.*)", "$1") ;~ ConsoleWrite($sPath & @CRLF) ;For testing. ;~ If Not FileExists($sPath) Then Return SetError(2, 0, False) Local $sGPOCmd = 'powershell "Get-GPOReport -Name ''' & $sGPOName & ''' -ReportType ' & $sReportType & ' -Path ''' & $sReportFullPath & '''"' ConsoleWrite($sGPOCmd & @CRLF) ;Turn off redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False) Local $iPIDGPOCmd = Run($sGPOCmd, @SystemDir, @SW_HIDE, $STDERR_MERGED) ProcessWaitClose($iPIDGPOCmd) ;Turn on redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(True) Local $sGPOCmdOutput = StringStripWS(StdoutRead($iPIDGPOCmd), 3) ;~ ConsoleWrite($sGPOCmdOutput & @CRLF & @CRLF) ;For testing. If $sGPOCmdOutput <> "" Then SetError(3, 0, False) Return True EndFunc ;==>_AD_GetGPOReportByNamePS Func _AD_GetGPOReportByGuidPS($sGPOGuid, $sReportFullPath, $sReportType = "HTML") ;Generates a report either in XML or HTML format for a specified GPO by GUID in a domain. Switch $sReportType Case "HTML", "XML" Case Else Return SetError(1, 0, False) EndSwitch Local $sPath = StringRegExpReplace($sReportFullPath, "(^.*\\)(.*)", "$1") ;~ ConsoleWrite($sPath & @CRLF) ;For testing. ;~ If Not FileExists($sPath) Then Return SetError(2, 0, False) Local $sGPOCmd = 'powershell "Get-GPOReport -GUID ''' & $sGPOGuid & ''' -ReportType ' & $sReportType & ' -Path ''' & $sReportFullPath & '''"' ConsoleWrite($sGPOCmd & @CRLF) ;Turn off redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False) Local $iPIDGPOCmd = Run($sGPOCmd, @SystemDir, @SW_HIDE, $STDERR_MERGED) ProcessWaitClose($iPIDGPOCmd) ;Turn on redirection for a 32-bit script on 64-bit system. If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(True) Local $sGPOCmdOutput = StringStripWS(StdoutRead($iPIDGPOCmd), 3) ;~ ConsoleWrite($sGPOCmdOutput & @CRLF & @CRLF) ;For testing. If $sGPOCmdOutput <> "" Then SetError(3, 0, False) Return True EndFunc ;==>_AD_GetGPOReportByGuidPS  
      Adam
       
    • By hemichallenger
      Not sure if this is possible or if someone has already tackled this. Is it possible to embed PowerShell into a GUI? Autoit is great for quick function but sometime I need to run a command thru PowerShell. It be great to have PowerShell console embedded into the gui.
    • By BigDaddyO
      After much searching I finally found a method to get eMails from an Exchange eMail account inbox.  I was hoping for AutoIT or vbscript but I couldn't find any that would read the inbox messages without using Outlook.
      I needed this because I'm testing a web-form that generates an eMail sent to a shared mailbox "not what my current outlook is configured for".  so, I needed to connect to a different account, then get the inbox messages, and see if the auto-generated eMail message body contains what I submitted in the form.
       
      I found a PowerShell script that was close and modified it to do just what I want, but I'd still like it to run in AutoIT but I'm not sure how to use the Microsoft.Exchange.WebServices.dll
      Anybody have some ideas? 
      #To Launch! # C:\Windows\System32> powershell -ExecutionPolicy ByPass #This launches PowerShell and allows execution of .ps1 files # PS C:\Windows\System32> . "C:\Temp\eMail\getInbox.ps1" #The period . in front of the .ps1 file forces PS to display results on-screen # Where is the EWS .DLL file that you are using # Get the installer from https://www.microsoft.com/en-us/download/details.aspx?id=42022 # We only need 2 dll's from the install and they can be stored anywhere: "Microsoft.Exchange.WebServices.Auth.dll" & "Microsoft.Exchange.WebServices.dll" $EWSdll = "C:\Temp\eMail\Microsoft.Exchange.WebServices.dll" # Where do you want the output text file to be saved $Output = "C:\Temp\eMails.txt" # replace with your email address $email = "MyemailAddress@work.net" # only need to populate these if you're impersonating... $username = "myemail" $password = "Sup3rS3cre+" $domain = "ad.work.net" # load the assembly : point to the dll in the location you have the .dll file [void] [Reflection.Assembly]::LoadFile($EWSdll) # set ref to exchange, first references 2007, 2nd is 2010 (default) #$s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1) $s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService # use first option if you want to impersonate, otherwise, grab your own credentials with the 3rd one. not sure what the 2nd one is for $s.Credentials = New-Object Net.NetworkCredential($username, $password, $domain) ##$s.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials #$s.UseDefaultCredentials = $true # discover the url from your email address $s.AutodiscoverUrl($email) # get a handle to the inbox $inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($s,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox) #create a property set (to let us access the body & other details not available from the FindItems call) $psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties) $psPropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text; # If you have a set number of items you want to get, use this and insert the # in the () # $items = $inbox.FindItems(5) # If you want to retrieve all items (Server limit is usually at 1000) then use this line # Details on the max returned by server: https://blogs.msdn.microsoft.com/exchangedev/2010/03/12/throttling-policies-and-the-ewsfindcountlimit/ $items = $inbox.FindItems($inbox.TotalCount) # Put some counts at the top of the output Write-host "Total Inbox count: $($inbox.TotalCount)" Write-host "Unread count: $($inbox.UnreadCount)" #These two lines, write the output to the specified text file Add-Content $Output "Total Inbox count: $($inbox.TotalCount)" Add-Content $Output "Unread count: $($inbox.UnreadCount)" foreach ($item in $items.Items) { # load the property set to allow us to get to the body $item.load($psPropertySet) # Get the Body text as-is $bod = $item.Body.Text #if you only want a short summary of the Body, then comment the above line and un-comment these 4 lines # $bod = $item.Body.Text -replace '\s+', ' ' # $bodCutOff = (100,$bod.Length | Measure-Object -Minimum).Minimum # $bod = $bod.Substring(0,$bodCutOff) # $bod = "$bod..." # output the results - first of all the From, Subject, References and Message ID write-host "====================================================================" Write-host "From: $($item.From.Name)" Write-host "Subject: $($item.Subject)" Write-host "Body: $($bod)" write-host "====================================================================" "" # Output the results to the specified Text file Add-Content $Output "" Add-Content $Output "====================================================================" Add-Content $Output "From: $($item.From.Name)" Add-Content $Output "Subject: $($item.Subject)" Add-Content $Output "Body:",$($bod) Add-Content $Output "====================================================================" Add-Content $Output "" } #see these URLs for more info # EWS Stuff # folder members: https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.folder_members%28v=exchg.80%29.aspx # exporting headers: https://www.allabout365.com/2010/10/export-email-headers-exchange-powershell/ # read emails with EWS: https://social.technet.microsoft.com/Forums/en-US/3fbf8348-2945-43aa-a0bc-f3b1d34da27c/read-emails-with-ews?forum=exchangesvrdevelopment  
      Thanks,
      Mike
×
×
  • Create New...