Logo

about me

portfolio

portfolio

portfolio















HALi PS1 Directive

I have always had an interest in mastering PowerShell but the main challenge of learning to do everything you know a completely different way takes time. Often I found myself at a workstation where I needed to perform some administrative tasks on the fly. I thought, shall I do this with PowerShell , it would be so much quicker but the problem is that I didn't know how and I would have to look it up which would end up taking longer than if I were to just do it via the GUI. This has always been catch 22 when it comes to PowerShell.
The way to master PowerShell and make use of it is to think of the tasks you might want to perform and then learn how to do them, write some scripts and then put them into practice next time.
This is when I came up with the idea of creating a .Net application that I can run off my IPAD and execute PowerShell scripts that I have stored in my database. However this presented many challenges. I will list some of the challenges below:


How would I perform administrative tasks from a .net client server web page? I would be anonymous?

I took a break for awhile on this project and did a bit more thinking. I started playing around with UWP application development and then discovered I could create what is called a Desktop Bridge between a UWP application and the local desktop. I created an administrator account on Windows 10 and enabled remote-signed powershell permissions on all the clients I wanted to manage on the LAN.


During the Development of the UWP app, I created a refresh timer that would read a text file on a remote server every second and information appeared in that textfile within that time window, the UWP app would then invoke the command to generate the powershell desktop bridge.

I did hit a snag that held me up for quite some time. The issue was that when you locked the computer or minimized the UWP app it essentially put it to sleep. This defeated the purpose and I was stuck on this problem for quite a while. I then discovered that in later versions of UWP development platforms, Microsoft had enabled an override feature that allowed you to keep the UWP alive even when minimzed or when the desktop locked. The reason Microsoft put UWP apps to sleep when minimized is because of battery saving. However this is a workstation, I do not need battery saving and also I am not going to put this UWP app on the Windows Store. I would not be able to put the app on the Windows Store because I enabled the override feature.

I then went about designing a web interface for my .net application that would generate the scripts that I wanted to execute and would also have a transcript box using an AJAX update panel that would show the results of the task performed.
I then could fire up the IPAD and log into my PowerShell administration page and select the task I wanted to run and then execute!

Once executed, the UWP app that is running in the background will pick up a signal from the text file and the details of the script that I created using my .net app. Once the UWP picked up the information from the text file, it would then use the desktop bridge to invoke a PowerShell session and execute the command.Remember that it will execute the powershell as an administrator so it would have the permissions required to run the scripts on the remote clients.


To my delight, I watched all the computers in the main computer room shut down before my very eyes, all from the touch of an iPad.
It did make me think about how powerful and dangerous PowerShell can be if not treated with caution. But on the other hand, very cool.
I will include a video and some pictures soon so that you can see it in action.

Here you can see the UWP app running side by side with the C Sharp.NET powershell script creator

ps1directive

 

Last updated, August 2018