Provisioning Services and Powershell - easier method

1:07 PM
Provisioning Services and Powershell - easier method -

As you may have noticed, cmdlets default to the PVS back array of text and .NET objects not regularly - since Powershell is an object-oriented scripting language, it can be quite complicated to handle with the output if you want to automatically process (not just displayed on the screen).

As a temporary workaround, I wrote a function that converts the output MCLI. exe regular objects with properties - this should make it much easier to use in the code

use is very simple -. MCLI.exe just run with all the arguments and output to the called function ConvertFrom- MCLI - you will automatically array of objects in your output

 ConvertFrom-MCLI Function Begin {{[array] = @ $ PvsLines () {} process PvsLines $ + = $ _} {End [array]. $ ResultArray = @ (): nextLine foreach ($ line $ PvsLines) {if ($ Line.Length -eq 0) {Continue} if ($ line [0] -eq "" Line.StartsWith or $ ( "Record # ")) {# If New object reference ($ Line.StartsWith (" Record # ")) {[Object] $ Script: PvsObject = New-object PSObject ResultArray $ + = $ Script: PvsObject Continue nextLine} ElseIf ( $ Script: PvsObject -is [Object]) {$ ItemName = $ ([System.Text.RegularExpressions.Regex] :: Replace ($ Line.Substring (0, $ Line.IndexOf ( ":")), "[^1-9a-zA-Z_]", "") ) $ ItemValue = $ ($ Line.Substring ($ Line.IndexOf ( ":") + 2)) $ Script: PvsObject | Add-members -MemberType NoteProperty -Name $ ItemName -Value $ ItemValue}}} write-host " Retrieved $ ($ ResultArray.Count) objects "Return $ ResultArray}} 
  Examples  

1) Retrieve the device name and MAC address:

 & 'C:  Program Files  Citrix  Provisioning services  MCLI.exe get DeviceInfo | ConvertFrom-MCLI | Select deviceName, DeviceMac 

2) Collect all target devices with more than 0 retries.

 & 'C:  Program Files  Citrix  Provisioning Services  MCLI.exe'. Get DeviceInfo | ConvertFrom-MCLI | Where 

3) Display of the number of days since domain account was created Status -gt0 {$ _.} :.

 $ & Devices = 'C:  Program Files  Citrix  Provisioning Services  MCLI.exe get DeviceInfo | ConvertFrom-MCLI foreach ($ Devicein $ Devices) {Write-Host "$ ($ Device.deviceName):" $ -NoNewlineWrite-Host ([Math] :: Round ($ ((Get-Date) - [datetime] $ Device .domainTimeCreated) .TotalDays))} 

If you are looking for a specific example, please ask in the comments

Each object will automatically return all assigned properties -. the only drawback at the moment is the fact that each property is [String] type - but you can always override this default if necessary (see Example 3 -. saying that I domainTimeCreated is [DateTime]) .

You can download the tool here

Zugec Martin

Previous
Next Post »
0 Komentar