Powershell Remote Administration (example: Adaxes)

Adaxes, in short is an AD management utility that has very good auditing features. Personally Im not a huge fan of it, its a web gui, its slower than the mmc snapins, its much slower than using powershell cmdlets, and it takes too long to get a task completed. Understanding that auditing is important for our department, we have to use it, but I was about to lose my mind with how long it takes to get a task done, so I thought there has to be a better way. Thankfully there is; Powershell!

The way I took care of this is via setting up my powershell profile to ask the question “Do you want to connect to adaxes?” If you select yes, it will log you in remotely to the system pre-configured, if you choose no it will just open a regular powershell session, as an added bonus we will also request a username and password and securely save them to a variable for later use if needed (such a time saver).

Im not going to go into how to setup a profile or anything like that, as that is out of scope and there are plenty of resources for that online already. I will show you how to configure this particular setup from beginning to end.

 

1) “C:\users\%username$\My Documents\Windows Powershell” is where all of our configurations will be done. In this folder you should have a file called “Microsoft.Powershell_profile.ps1” If you have more than one profile you should already know where it is. Add the following code:

Ok so what is this doing?
– First we set the username variable. This isnt really needed but I deploy this to team mates and it makes life a ton easier when more parts of your code are dynamic.
– We than set the directory that we will search for scripts to autoload
– Than we search the directory specified and load them, Writing to the console is optional but its there if you want it.

2) Now create a folder called “Autoload” In the folder “Windows Powershell”. Create a ps1 file, in my case I called it Adaxes.ps1 because this is a solution for Adaxes. Add the following code:

Ok great so what is this doing?
– First we need to set our variables for our user name ($user) and our server name ($computer)
– Second we request credentials and save them to $creds, this is something I use a lot as it saves SO much time if you are a powershell admin.
– Third we ask if you would like to connect to the computer specified, if yes we connect and in this case load up the Adaxes powershell tools, enter a remote session, and then clear the garbage from the screen. If no we just open a default powershell session but with the added benefit of having our creds securely saved in a variable.

This can pretty much be used for anything and with a few tweaks you could even request a custom computer name for each run, that way you can use it to remotely admin any system you please.

At this point you might be wondering why I dont just install the Adaxes PS tools on my computer, we unfortunately I tried that. They load fine, but they dont have any way to connect to a different system, the tools have to be installed on the same system Adaxes is installed on to work.

I plan on doing alot more with remote powershell, stay tuned if you’re interested!

0 comments… add one

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.