On Windows devices turn ZMAN commands into Powershell commandlets so they can be chained or results from them manipulated much more easily.

Comments

  • This is a MUST! Powershell is object based and all zenworks commands should be ported to Powershell instead.

  • this also helps give support when running zcc server on windows server core.

  • We are rather unhappy with zman - it only offers a fraction of functionality needed for proper automation. A comprehensive API allowing us to read and manipulate properties of ZCM's objects and settings would be great, but is apparently not something which is actively considered.

  • Since zman only ever seems to return grid-table formatted data, we found a naïve implementation of the zman powershell wrapper to be surprisingly useful, albeit rather slow as each zman call is taking its time:

    #####
    $ZMANHOME = "C:\Novell\ZENworks"
    $ZMANEXE = "$ZMANHOME\bin\zman.exe"
    $ZENWORKSSERVER="zcm-01.example.com"
    $ZENUSER="someZCMAdminUser"
    $ZENPASSWORD="*secretpassword*"


    function zman()
    {
    Param(
    [string]$Command,
    [array]$CommandOptions
    )
    $errNo = $null
    $zmanResult = & "$ZMANEXE" $Command $CommandOptions "--host=$ZENWORKSSERVER" "--User=$ZENUSER" "--Password=$ZENPASSWORD"

    # Evaluate results through simple regex patterns
    $resultGrid = $zmanResult -match "^Displaying [0-9]* - [0-9]* of [0-9]* results:.*"
    $resultErrorMessage = $zmanResult -cmatch "^ERROR: [0-9]*"
    $resultSuccessMessage = $zmanResult -cmatch "^Success.*"

    # Did we encounter an Error?
    If(-not (($null -eq $resultErrorMessage) -or ($false -eq $resultErrorMessage))) {

    Throw "ZMAN: $($zmanResult -match '\S')"
    Return
    }

    # Is the result a Grid?
    If(-not (($null -eq $resultGrid) -or ($false -eq $resultGrid))) {
    # Remove horizontal ASCII gridlines, empty lines, and the status line
    $zmanresult = (($zmanresult -replace "^[-+]{10,}$", "") -match '\S') -notmatch "^Displaying [0-9]* - [0-9]* of [0-9]* results:.*"
    # remove filling spaces in the grid
    $zmanResult = $zmanResult -replace "[\s]+\|[\s]+", "|"
    # Convert to object collection and return as the result set
    $zmanResult | ConvertFrom-Csv -Delimiter "|"
    }

    # Do we just have a status success message?
    If(-not (($null -eq $resultSuccessMessage) -or ($false -eq $resultSuccessMessage))) {
    Write-Debug "ZMAN: $resultSuccessMessage"
    }

    }

  • I forgot to attach a Usage example to the above powershell sniplet:

    zman "bl" @("/Bundles", "-r")

    will return an object collection containing *all* bundles and bundle folders with property names reflecting the original zman output grid column headers.

    Also, make sure that code lines are not wrapped when pasting the powershell code into your execution environment.

  • I have published a more feature-complete module wrapping ZMAN into Powershell to the Technet gallery:
    https://gallery.technet.microsoft.com/scriptcenter/Zenworks-Configuration-8c535013

    It probably covers most of the ZMAN output formats and even tries dealing with unescaped line breaks in the output. Results look promising - we are implementing a moderately sophisticated Active Directory-to-ZCM synchronizer based on this (unidirectional folder and object sync for device folders and computer objects, creation of corresponding bundle folders and registration rules) and did not encounter major problems so far.