Author Topic: PowerShell  (Read 795 times)

Offline wholm

  • Sr. Newbie
  • *
  • Posts: 23
  • Karma: +0/-0
PowerShell
« on: February 12, 2015, 06:08:58 pm »
All, this is my small contribution using PowerShell to get an inventory of your system:

Base code:
$vera = wget "http://192.168.81.1:3480/data_request?id=user_data2&output_format=xml"
$xmlvera = [xml]$vera.Content

(you could create $devices here that is equal to $xmlvera.root.devices.ChildNodes to shorten/replace typing, I didn't to allow some basic raw examples)

What you can do with these objects (type in the whole line and press enter):
$xmlvera.root.devices.ChildNodes.Count

$cooper = $xmlvera.root.devices.ChildNodes | Where {$_.manufacturer -Match "Cooper"}
$cooper.Count

$dimcooper = $cooper | Where {$_.device_type -Match "DimmableLight"}
$swcooper = $cooper | Where {$_.device_type -Match "BinaryLight"}
$alldim = $xmlvera.root.devices.ChildNodes | Where {$_.device_type -Match "DimmableLight"}
$allsw_and_relay = $xmlvera.root.devices.ChildNodes | Where {$_.device_type -Match "BinaryLight"}

$dimcooper.count
$swcooper.count
$alldim.count
$allsw_and_relay.count

Count by manufacturer field example:

$xmlvera.root.devices.ChildNodes | Group-Object manufacturer

Okay, I have these in variables, how do I get this data to excel (use $[VARIABLE] | Export-Csv -NoTypeInformation [PATH AND FILE NAME].csv)?

$xmlvera.root.devices.ChildNodes | Export-Csv -NoTypeInformation .\alldevices.csv
$cooper | Export-Csv -NoTypeInformation .\cooperdevices.csv

I believe this works for both UI5 and 7, 7 I know works for sure.

You can use PowerShell to change state as well. If you don't know PowerShell, that's okay, if you have Windows you have it and with an IP change above these commands should work as is (if you have Cooper, otherwise you can use the name of your devices in place of the word cooper or you can even filter on different field).  If you have Linux you can use mono.

Enjoy
« Last Edit: February 12, 2015, 07:56:08 pm by wholm »

Offline wholm

  • Sr. Newbie
  • *
  • Posts: 23
  • Karma: +0/-0
Re: PowerShell
« Reply #1 on: July 16, 2017, 09:35:48 pm »

Base code:
$vera = wget "http://192.168.81.1:3480/data_request?id=user_data2&output_format=xml"


Update:

This works in PowerShell for Linux (https://github.com/powershell/powershell) as well as other platforms listed there.

Please note that you need to change wget to Invoke-WebRequest:

$vera = Invoke.WebRequest "http://192.168.81.1:3480/data_request?id=user_data2&output_format=xml"

The reason for this is in Windows, wget and curl are simply aliases.  In Linux and MacOSX (because they are OpenBSD based) have these commands and will perform much more different than PowerShell.  PS is superior in many ways but for expectations, I am guess they removed the aliases.

The remaining commands work as is and haven't changed in over 2.5+ years.

Offline BOFH

  • Sr. Hero Member
  • ******
  • Posts: 2410
  • Karma: +112/-139
Re: PowerShell
« Reply #2 on: July 16, 2017, 10:21:57 pm »
Good Job! It never dawned on me to look into PS for anything Vera related. Going to give your inventory script a try as I think that will help me in my upcoming migration from Vera 3 to and Edge and a Plus.
Vera3 UI5 UI7 Edge Plus
Trane TZEMT400AB32 | Schlage BE369 FE599 | GE 45601 45602 45603 45604 45606 45609 45631 | Intermatic HA01C HA03C HA05C HA07C CA600 CA3000 | Aeon DSC06106 | Telguard GDC1 | Foscam FI8910W FI8905W FI9821W | D-Link 930L | Wanscam JW0011 | ZModo ZPIBH13W