//
you're reading...

Powershell

Formatting MCli-Get output

It’s no secert that Citrix released a Powershell SDKs for Provisioning Server that’s not Powershell “friendly”.

Here’s a script that will convert the output from MCli-Get to a System.Collections.ArrayList. 

Requires the Provisioning Server Powershell snap-in.

Example
$myDevices = .\Get-PVSInfo.ps1 -type DeviceInfo
$myDevices | Out-GridView

#Author: Phil Lindsey
#Website: http://www.ctxfarmer.com
#Last Modified: 08/28/2010

param(
  [string]$type=""
)
function get-value{
  param([string]$strText="",[string]$strDelimiter="")
  return $strText.SubString($strText.IndexOf($strDelimiter)+2)
}
function get-name{
  param([string]$strText="",[string]$strDelimiter="")
  return $strText.SubString(0,$strText.IndexOf($strDelimiter))
}
$type = $type.Trim()
switch($type){
  "AdDomains"                        {}
  "AuthGroup"                        {}
  "Collection"                       {}
  "Device"                           {}
  "DeviceInfo"                       {}
  "DeviceStatus"                     {}
  "DiskInfo"                         {}
  "DiskLocator"                      {}
  "Farm"                             {}
  "FarmView"                         {}
  "Server"                           {}
  "ServerInfo"                       {}
  "Site"                             {}
  "SiteView"                         {}
  "Store"                            {}
  "UserGroup"                        {}
  default                            {write-output "Bad type"; exit;}
}

Add-PSSnapin McliPS* -ErrorAction SilentlyContinue
$all = @()
$obj = New-Object System.Collections.ArrayList

$lines = Mcli-Get $type
for($i=0;$i -lt $lines.length;$i++){
  if(($lines[$i].length -gt 0) -and ($lines[$i].contains(":")) -and -not ($lines[$i] -match "Executing: Get ")){
    $name = get-name -strText $lines[$i] -strDelimiter ":"
    $value = get-value -strText $lines[$i] -strDelimiter ":"
    $obj | Add-Member -membertype noteproperty -name $name -Value $value
  }
  if($lines[$i].contains("#") -or (($i+1) -eq $lines.length)){
    $all += $obj
    $obj = New-Object psObject
  }
}

Write-Output $all