Boost Chaos

    A small change to the XaosCPS script to get karma. Just to illustrate as much as possible:

    $user = ([xml](new-object system.net.WebClient -prop @{encoding=[System.Text.Encoding]::UTF8}).DownloadString("http://habrahabr.ru/api/profile/XaocCPS")).habrauser
    Write-Host "$($user.login) - карма: $($user.karma), рейтинг: $($user.rating)"



    • We initialize the encoding property directly in the parameters of the New-Object call. Please note that the parameter name -properties is completely optional, it is important that there is no other parameter starting with the same letters
    • The type is converted to XML using the string [xml] before the expression, and not before the variable - just to immediately get to the data you need, and not then repeat the path every time
    • Formatting by inserting subexpressions into a string - this way we have a primitive template divider in PowerShell right out of the box

    Also popular now: