locked
Count content RRS feed

  • Question

  • Dear all,

    first thing: I am new to powershell and I tried to figure it out today, but I cannot get it to work, so please be patient with me :-)

    I need to find out how many citrix licenses are availabe in total. For that I already modified the following script for my needs and it works pretty good:

    $licensePool = Get-WmiObject  -Class "Citrix_GT_License_Pool" -ComputerName "myserver" -Namespace "root\CitrixLicensing" | where {$_.PLD -eq "XDT_ENT_UD”}
    $licinfo=($licensePool | Select-Object @{n="Product";e={$_.PLD}},@{n="Installed";e={$_.Count}})$

    $licinfo throws out this:

    Product    Installed
    -------    ---------
    XDT_ENT_UD        11
    XDT_ENT_UD        16
    XDT_ENT_UD        22
    XDT_ENT_UD        11
    XDT_ENT_UD        71

    What I finally need is the sum of the "installed" column. How can I get this done?

    Thanks for any help!

    Sebastian


    • Edited by Sebi83 Wednesday, April 25, 2018 6:24 AM typos
    Tuesday, April 24, 2018 3:00 PM

Answers

  • pipe it to "Measure-Object -Property Installed -Sum".

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    • Proposed as answer by Richard MuellerMVP Tuesday, April 24, 2018 4:07 PM
    • Marked as answer by Sebi83 Wednesday, April 25, 2018 2:29 PM
    Tuesday, April 24, 2018 3:18 PM

All replies

  • pipe it to "Measure-Object -Property Installed -Sum".

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    • Proposed as answer by Richard MuellerMVP Tuesday, April 24, 2018 4:07 PM
    • Marked as answer by Sebi83 Wednesday, April 25, 2018 2:29 PM
    Tuesday, April 24, 2018 3:18 PM
  • That was easy, thanks a lot :-)
    Wednesday, April 25, 2018 6:43 AM
  • Hi,

    I'm checking how the issue is going, was your issue resolved? And if the replies as above are helpful, we would appreciate you to mark them as answers. It will be greatly helpful to others who have the same question.

    Appreciate for your feedback.

    Best Regards,
    Albert

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, April 25, 2018 9:28 AM
  • I have another question regarding passing the output into a variable. As suggested I piped "Measure-Object -Property Installed -Sum" and additionally selected the sum

    The full script looks like this:

    $licensePool = Get-WmiObject  -Class "Citrix_GT_License_Pool" -ComputerName "myserver" -Namespace "root\CitrixLicensing" | where {$_.PLD -eq "XDT_ENT_UD”}
    $licinfo=($licensePool | Select-Object @{n="Product";e={$_.PLD}},@{n="Installed";e={$_.Count}}) | Measure-Object -Property Installed -Sum | Select Sum

    $xmlsessions2=""

    foreach ($total in $licinfo) {
        $xmlsessions2 += "<result>"
        $xmlsessions2 += "<channel>Availablelics$($total.Name)</channel>"
        $xmlsessions2 += "<value>$($total.count)</value>"
        $xmlsessions2 += "<unit>#</unit>"
        $xmlsessions2 += "</result>"
    }


    $myxml2=@"
    <?xml version="1.0" encoding="Windows-1252" ?>
    <prtg>
      <result>
        <channel>Availablelics</channel>
        <value>$($licinfo)</value>
        <unit>#</unit>
      </result>
    $($xmlsessions2)
    </prtg>
    "@

    write-host $myxml2
    exit 0

    Output looks like this:

    ?xml version="1.0" encoding="Windows-1252" ?>
    <prtg>
      <result>
        <channel>Availablelics</channel>
        <value>@{Sum=131}</value>
        <unit>#</unit>
      </result>
    <result><channel>Availablelics</channel><value></value><unit>#</unit></result>
    </prtg>

    What I need is only this, since I need to pass this into PRTG monitoring system.

    <value>131</value>


    Any idea how to achive this? Tried different ways, but I can't figure it out... Thanks again!




    • Edited by Sebi83 Wednesday, April 25, 2018 1:51 PM
    Wednesday, April 25, 2018 1:49 PM
  • I have another question regarding 

    If you have another question you have to create a new thread with a proper subject describing what the question will be about. Do not overtake other or old threads with new questions.

    And PLEASE format your code as code.

    Thanks

    And if an answer helped you with your question you should mark it as answer. So others searching for the  same or a similar issue will find the answer more quickly.

    Thanks.


    Best regards,

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Wednesday, April 25, 2018 1:55 PM
    Wednesday, April 25, 2018 1:54 PM
  • You need to learn basic PowerShell.  The issue is absolutely PS 101.

        <value>$($licinfo.Sum)</value>


    \_(ツ)_/

    Wednesday, April 25, 2018 2:02 PM
  • This is what I am currently trying to do ;-)

    Thanks!


    • Edited by Sebi83 Wednesday, April 25, 2018 2:34 PM
    Wednesday, April 25, 2018 2:33 PM
  • You might take a little step back and start "from scratch" ... 

    Learn PowerShell: Microsoft Virtual Academy - Getting Started with Microsoft PowerShell.


    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Wednesday, April 25, 2018 2:52 PM