I have a script which uses Posh-SSH GitHub - darkoperator/Posh-SSH: PowerShell Module for automating tasks on remote systems using SSH but it needs .Net Framework 3.5 and we need to be able to use the syntax of Powershell 5 too, otherwise we're constrained by the limitations of Powershell v2.
Has anyone found a way to force/allow/cajole PowerShell scripts in SAM to run using Powershell 5, not the default v2. I've Googled at length before posting here to ask the experts.
We don't even have Powershell v2 installed on some servers, it's ancient.
If this case I need to run this script only on one server, not have compatibility across the environment. It logs in to an HPE MSA and issues commands to get the pool info (show pools), then the output which comes back (which is XML) is walked through to find the available space on the storage pools. With thin-provisioned LUNs we need to keep an eye on available raw storage.
I was getting 'Not defined' in the output. I tested by just adding two lines for a fake Message and Statistic, and that was then ok. What is happening is that it cannot connect via SSH to the MSA, therefore the output, which is generated in a loop, never happens because the connection fails and no output is received. All works on the exact same machine, where I developed it, when I run it in VScode. I made sure to include import-module for Posh-SSH, and I polite in putting an exit(0) at the end.
I can create an SQL database and tables, put the data in there, then display it in Solarwinds using Custom Object - but what's the point - we miss out on perfstack and all the other benefits this product is supposed to provide. I don't want to go back to writing dozens of scripts which email me with the data. There is an API method on the HPE MSA, but I don't want to re-engineer. Besides I have other ideas for using Posh-SSH in other places in Solarwinds.
Solarwinds should have an option to select the default Powershell version to use, either 2 or 5. It doesn't seem like this would be a lot of work.
In the meanwhile, has anybody got any clever tricks to get the job done? Get the script to launch powershell 5, then return the results to this script. Is that feasible?
We're going to keep running in to these limitations and they cause problems - it's nearly 2020, we should have an option to use Powershell 5 in the scripts. Or maybe it obvious and I'm just missing something.