Hosting in Azure (or other external web hosting) - how to run scripts on client computer

Hi, this is a bit of a newbie question so please bear with me.

I know how to use PSU in my internal network to run scripts and get information across my servers as I obviously know the names of my servers so can use commands with -ComputerName for example to get the information.

But how do I use it when hosting in Azure (or in my case as per discussion here with a ASP.NET hosting provider) to run commands / scripts on the connecting client computer? as it could be any computer opening my webpage and logging into my dashboard with provided credentials and I won’t know the name of that computer to use with -ComputerName (or perhaps Invoke-Command)?

And related to this what issues will I face and how do I overcome them in relation to permissions / security when a user accesses my dashboard via website externally like this (compared to doing it via an internal network for example?)

Many thanks, and apologies for the “newb” question - but eager to learn here.

Product: PowerShell Universal
Version: 3.6.2


The sort of information I want to retrieve from the computer(s) will be system information such as disk size / space, RAM, processor information, information I would usually get via WMI etc

Hey @wingers,

This isn’t something that is easily accomplished. Running arbitrary scripts on a machine from a web browser is a huge security risk so you’d have to have some sort of system setup on the client machines to accommodate this.

If you can setup something like an Azure Gateway to connect from the Azure VM running PowerShell Universal down to your local networking, then you might be able to use PowerShell remoting like you are suggesting. Retrieving the actual computer name (or local IP address) from the web browser comes with set of issues but it may be possible.

Hi Adam, thanks for the response.

That puts a major dent in one of my planned use cases then.

I am hosting it via a third party ASP hosting provider (as per my detailed research here rather than in Azure, as cheaper and it runs really well for my needs)

I will control who runs the scripts (they will only be clients of my company), so it won’t be open to everyone so I can contain / control the risks if it can be done somehow?

If not back to the drawing board and will need to find another solution to achieve my ideas.

Just bumping this thread after 3 months of inactivity hoping for some more input / discussion on whether this is going to be possible or not before I proceed or give up and go down a different path…

You will want to check out our upcoming event hubs feature. It might be what you’re after.

Interesting, Thanks Adam.

Would it allow me to have a dashboard / page that could interact with a client machine automatically e.g. if I sent a customer a link to a dashboard hosted in azure or my web hosting which then had various buttons / controls on it so if clicked it would then run interactive scripts / PowerShell commands on their machine for example to retrieve system information (disk space / RAM / CPU info, network information etc) which would then be returned to me?

Yep. You could use Send-PSUEvent to send a notification down to all connected machines. Each machine could collect that data and then send it back to the server via Invoke-RestMethod.

1 Like

And I could also instigate it on a button click event for just a single machine?

I will get latest beta version installed on my hosting platform shortly and take a look.

A small snippet / sample of how this works / can be implemented would be handy as it is so new so I can give it a test if possible :slight_smile: … thanks…

Okay I have 4.0.0-beta2 running on my Netcetera windows core hosting platform and working well. Would appreciate a basic sample of this new Event Hubs idea so I can see how it works and test it, and obviously do some real-world testing for you at the same time :slight_smile:

At the moment, it doesn’t work for a single machine but we could certainly add that before the final v4 release.

First, create an event hub with a name like MyEventHub.

From your dashboard, you would want a button that does something like this:

New-UDButton -Text "Launch on Client" -OnClick {
 Send-PSUEvent -Hub 'MyEventHub' -Data "Write Me"

Finally, import the Universal module on the client machine and call:

Connect-PSUEventHub -ComputerName http://locahost:5000 -Hub MyEventHub -ScriptBlock {
    Write-Host $_

Now, when you click the button, Write Me text will be written to the client terminal.

1 Like

Hi Adam, thank you for your reply, much appreciated.

Firstly when trying that I get below error when running Connect-PSUEventHub command

“Connect-PSUEventHub : Exception has been thrown by the target of an invocation”

Secondly I think we are still actually talking cross purposes here about what I am trying to achieve, perhaps I haven’t explained myself properly, or I am just not grasping the idea you are proposing.

I will try and explain again in case it is possible:-

I am wanting that my clients / customers would visit a dashboard (or apps as I believe you now calls them in v4) page, they would then click a button (or similar) on that page which would run a series of PowerShell commands / scripts on their computers to collect system information which is then displayed on the their screen AND also then sent back to me, would be for purposes of me providing support / running remote tests / checks on the computers. This is all just an idea at this stage, currently I connect up via TeamViewer (or equivalent and run various things) and just wanted to look at providing some sort of automated solution where they can visit a webpage, have a login, and then click buttons to perform various tasks and the results of the said tasks are they sent back to me for analysis or further work.

Thirdly - not sure if this is a problem with my hosting or a v4 beta issue, but when turning authentication off for a page (dashboard) and clicking save settings it doesn’t apply, if I go back it is still enabled. This is when changing it under Edit Details > settings of a app (dashboard). If I try it via Edit Properties I get error of “Object reference not set to an instance of an object.”

P.S. Perhaps what I am asking simply isn’t going to be possible - it is only an idea I had so not a problem if it isn’t, I’m sure I can find another way / solution if not - but was worth a try, plenty of other uses for PSU!!