Uncle.... on the PowerShell.

Ask and answer questions related to any type of OSA scripting.
Post Reply
Message
Author
toddhutch
Posts: 18
Joined: Mon Feb 17, 2014 2:59 pm

Uncle.... on the PowerShell.

#1 Post by toddhutch » Mon Feb 24, 2014 11:22 pm

I continue to enjoy the Open Source Automation software. It's a nice break from the "Day" job. So thank you again!

I have read through the script forum and I'm not able to figure out how to pass and receive a parameter, and I'm not sure where to begin with the reading.

I'm trying to do something which I believe is quite simple, but I've not been able to figure it out.

I'm attempting to pass an "On" or "Off" Parameter, to PowerShell script which will then turn on or off a number of devices. I've tried a number of different things, and as the title states... Uncle, I've given up and decided to ask for help.

PowerShell Script called - Family Room On or Off
Invoke-OSA -Name "CFLampFR" -Method -parameter2
Invoke-OSA -Name "SmLampFR" -Method -parameter2
Invoke-OSA -Name "XBMCTVStereo" -Method -parameter2
Invoke-OSA -Name "ORLargeLamp" -Method -parameter2
Invoke-OSA -Name "CR Test" -Method -parameter2

PowerShell Script calling with a parameter of off
Invoke-OSAScript -Name "Family Room On or Off" -Parameter2 "Off"

Is this possible to do what I'm trying, as this has boggled me.

Thank you again for this great software!

-Todd

toddhutch
Posts: 18
Joined: Mon Feb 17, 2014 2:59 pm

Re: Uncle.... on the PowerShell.

#2 Post by toddhutch » Tue Feb 25, 2014 11:59 am

Working through powerGUI, I tried a couple of things but I'm not able to get those commands to work with OSA. Any with a PowerShell script they could paste as and example that receives a parameter?

Script file testsimple.ps1
$test=$args[0]
Add-Type -Path "C:\Program Files\OSA\OSAE.API.dll"
Import-Module -Name "C:\Program Files\OSA\Plugins\PowerShell\OSAE.PowerShellProcessor.dll"
Invoke-OSA -Name "CR Test" -Method $test

when I call the script it turns CR Test off
./testsimple1.ps1 "Off"

However this is the error I get via the logs for PowerShell
02/25/2014 11:54:38.918 AM - running script: Invoke-OSAScript -Name "test" "Off"
02/25/2014 11:54:39.026 AM - An error occured while trying to run the script, details:
A positional parameter cannot be found that accepts argument 'Off'.

Thanks

User avatar
Mat
Posts: 501
Joined: Thu Aug 09, 2012 2:35 pm
Location: UK

Re: Uncle.... on the PowerShell.

#3 Post by Mat » Tue Feb 25, 2014 1:13 pm

Hi toddhutch,

If I remember correctly in your first example it would be:

Invoke-OSA -Name "CFLampFR" -Method $parameter2
Invoke-OSA -Name "SmLampFR" -Method $parameter2
Invoke-OSA -Name "XBMCTVStereo" -Method $parameter2
Invoke-OSA -Name "ORLargeLamp" -Method $parameter2
Invoke-OSA -Name "CR Test" -Method $parameter2

$parameter2 is the second parameter passed to the execution of the script, so if you invoked your "Family Room On or Off" script passing it On, it would then invoke the on method of "CFLampFR" and so on. The same would apply passing Off to the script parameter, as long as all the methods you invoke in the script support the method it should be fine. The other parameters in Invoke-OSA are optional.

toddhutch
Posts: 18
Joined: Mon Feb 17, 2014 2:59 pm

Re: Uncle.... on the PowerShell.

#4 Post by toddhutch » Tue Feb 25, 2014 2:44 pm

Thank you Mat, that worked great!

Post Reply