Automated execution of a powershell script on Active Directory, Triggered from a web page - powershell

I am proposing an idea for a final year project that is basically a virtual environment. I would be using Citrix XenServer in conjunction with Windows Server 2008 R2 and Citrix netscaler to make the server accessible over the web. I would also be hosting a website on the server that Windows is on.
What I was wondering is, would it be possible to trigger the execution of a script on the server from the web page. So basically a user comes along, goes to my website, registers their details. a csv file is then produced based on the details that are input. Then I was wondering is there a way to trigger the execution of a powershell script that would use the csv file to set up the user in Active directory. The powershell script itself is simple its just how I would get it to run is another thing.

Yes it is possible.
PowerShell lets us create graphical interfaces with the .NET winforms. With it, we can build front end to manage our scripts. It's a really nice feature, and tools like AdminScriptEditor make it pretty easy.
I have found this link for your reference - PowerShellOnWebPage
You can tweak/create the script as per your need.
Let me know if this helps.
Thanks!

Related

Running Alteryx flows from command line

I'm trying to figure out if I can launch a pre-built Alteryx workflow without launching the Designer - and without having Alteryx Server.
I came across a helpful post on Alteryx uses by #Runonthespot that, among other things, addressed running workflows from the command line, but doesn't go into detail. That discussion is here: https://stackoverflow.com/a/30469848/4313331. I don't have the rep to comment on his post and the question is closed.
He writes:
"Flows are runnable from the commandline on a server, and easiest way I've found (besides using Alteryx's own scheduler) is to save as an "App", and then run from the command line using the Alteryx engine executable, passing it parameters via xml file. You can save a sample xml parameter file from your flow by hitting the magic wand button (after saving the flow as a .yxwz (app)) This brings up a panel that lets you set the variables, and that panel has a handy "save" button which generates an xml file in the right format."
So, I'm looking for more info on this process. Is it simply a question of using Alteryx Server? Or is this a more interesting work around?
Thanks.
Yes, you can run a workflow (used generally to refer to a workflow, macro, or analytical app) without launching the Designer. You'll first need to understand how to run the workflow from the command line. The AlteryxEngineCmd.exe executable runs a workflow. It is located in the Alteryx install path in the bin subfolder. Here is where mine is located:
C:\Program Files\Alteryx\bin
It allows an additional parameter of an XML file with interface values. This is documented for analytical apps ONLY though it does work for macros as well. This is based on my extensive use of this undocumented feature.
Below are two examples:
AlteryxEngineCmd.exe MyWorkflow.yxmd
AlteryxEngineCmd.exe MyAnalyticApp.yxwz AppValues.xml
You can see a post here:
Alteryx Command Line Help
I prefer to wrap the command in a batch file and execute that for more control.
Now that you understand how to run the workflow from the command line, you can execute it anytime you want without launching Designer. Furthermore, you can use Windows Scheduler or a third-party tool to run the command or the batch file on a schedule.
Finally, you do need a license which enables API & Command Line w/ Scheduler. This is less expensive than Alteryx Server.
Have you tried C:\Program Files\Alteryx\bin\AlteryxEngineCmd.exe? It doesn't require server.
https://help.alteryx.com/2019.1/Command_Line.htm
If restrained by budget, you don't need a scheduler license (enables the AlteryxEnginecmd.exe), you can use a windows mouse clicker or even Powershell, to run the Designer though, without manual intervention.

Installing other installers?

I'm tasked with reducing a 50-page installation manual to "much less"; a bunch of applications need to be installed in a specefic order, with specific options, and so on. Can I use any of the popular installers (WiX, NSIS, Inno Setup) to automate this process, or do I need to use Powershell?
I've read about what these installers can do, and as far as I can see they're designed to install one application to one computer -- I haven't seen that or even if they can be used to control other installers in a very detailed fashion -- "use this, this, and this option on this wizard page, but not that one on the next wizard page, and install to this path, then enter these details (users, whatever)".
Am I wildly over-understanding what these tools can do? Given that I need to do this, what's the best way to go about it?
Update 2: I learn that installers do offer silent install by way of a config file. Neat! I'm currently looking at NSIS (spawning Powershell scripts and other installers) as the option that's easiest to just start & go with. I like that I don't need a custom IDE for it. But I'm also wondering wether NSIS is (soon) obsolete, in a Windows 7&10 world?
You should look at WiX with a custom bootstrapper UI. That can be used to install any number of setups in whatever order you want. The tricky question is whether all those setups need to show their own UIs, one after the other. If they can all be installed silently with command line paramaters, then your WiX bootstrapper could show your UI to collect all the options, and then install each of the setups silently while you show progress for the entire operation. You could also get a single entry for the entire package in Programs&Features. So something like WiX could do it, but the UI requirements could make it awkward.
PowerShell CAN do it, but it's through invoking COM objects and sending keys to the window, so it's not the BEST way to do it. I'm going to repost something I posted yesterday to a similar question about using PowerShell to uninstall some unwanted software.
QFT:
PowerShell isn't going to interact with the prompts... you can't just tell it to click "Next" in an executable because it can't see it.
You can send keys to it though. You're really just using COM objects.
So, first, get your process ID by setting a variable that contains an array, the data for which is defined by the name of your process. Let's say your process is called, "Uninstall" and the process is ALREADY RUNNING:
$a = Get-Process | ?{$_.Name -eq "Uninstall"}
Start the COM:
$wshell = New-Object -ComObject wscript.shell;
Bring the uninstallation program with this process ID to the front so we can send it keystrokes:
$wshell.AppActivate($a.id)
Give it a few seconds to bring that window forward. I chose 5, but if your machine isn't stressed, 2 is probably enough:
Start-Sleep 5
Now start telling it what keys you want to send. The syntax here is this: whatever is in the () is what will be sent. The position in the single-quote is the keystroke to send, after the comma is how long you want it to wait before proceeding. Assuming the first screen is "Next" you can send your first command by telling PowerShell to send the ENTER key and wait 5 seconds:
$wshell.SendKeys('~',5)
The wait function is optional, but for your purposes, you're definitely going to want it. (If you don't want it $wshell.SendKeys('~') would send the ENTER key and immediately move to the next command.)
Walk through the uninstallation yourself manually, using all keystrokes, and for any keystroke you send, pay attention to how long it takes before the next part of uninstallation is loaded, and wait longer than that with your script (e.g. if it processes your ENTER key instantaneously, I'd have it wait 3 or 5 seconds before it sends the next command. If it takes 5 seconds to load, I'd tell it to wait 10 seconds before sending the next command).
Letters are letters, and numbers are numbers. Most non-commands are just assigned to their keys (meaning if you want to type "K" your command would just be $wshell.SendKeys('K')) You can get the rundown for the specific keys here: https://msdn.microsoft.com/en-us/library/office/aa202943(v=office.10).aspx.
/QFT
You may want to look into Auto-It, but that's based on pixel, last I checked, so if you run it on machines with different screen resolution, it can cause problems.
How you approach this really depends on if these other installers supports silent mode and/or answer files. This page list the options for some of the popular installers.
If they do and you decide to use NSIS then you would just do something like this:
Name "BundleInstaller"
OutFile "bundlesetup.exe"
RequestExecutionLevel Admin
Page Components # Comment out this if you don't want the user to have a choice
Page InstFiles
Section -Init
InitPluginsDir # $PluginsDir directory is deleted when the installer quits
SetOutPath "$PluginsDir"
SectionEnd
Section "Foo v1.2.3"
DetailPrint "Installing Foo"
File "FooSetup.exe"
ExecWait '"$PluginsDir\FooSetup.exe" /S /D=$ProgramFiles\Foo' # This is the syntax for NSIS installers
SectionEnd
Section "Bar 2015"
DetailPrint "Installing Bar 2015"
File "BarSetup.msi"
ExecWait '"MSIEXEC" /qb /i "$PluginsDir\BarSetup.msi" REBOOT=ReallySuppress'
SectionEnd
Section -Cleanup
SetOutPath "$Temp" # Release current directory lock on $PluginsDir
SectionEnd
If this solution is not possible then you are looking at some form of automation like the other answers have suggested.
I'd say there are two forms of automation; one where the app you are automating has to be the active window and the other where you send messages instead of keystrokes.
Just sending Enter to the active window with some sleep's thrown in is of course the easy solution but it can break if somebody starts interacting with the machine.
NSIS supports commands like FindWindow and SendMessage and I assume AutoHotkey does as well. The advantage to using FindWindow to find a specific HWND and then sending it a message directly is of course that the application does not have to have keyboard focus. This approach requires a bit more work but the end result is better because you only use SendMessage after finding the right window (and you can make sure the window/control is visible and enabled etc) so you know the application is in a known state without having to hope that the sleep was long enough...
Installing other installers is no problem with any decent installer builder.
These other installers are either msi, exe or zip files.
I do not assume that the installers (for SQL database servers and the like) offer silent install (by way of a million command-line parameters or a config file).
I highly doubt I can launch these installers in silent mode (with a million command line parameters)... :-(
Fetch the installer for the SQL database server and check it.
Most of the installers offer a silent install.
msi or exe files created by another installer builder accept CLI arguments to select components and set the target path
even exe files created as SFX archives accept a target path for the unpackaging
some installers do not provide all form-fields of their GUI configuration dialogs as CLI parameters. for those installers you would need a post-configuration step, which might simply consist of copying a default config file into the application folder
Yes, its also possible to center an installer around the idea of "gui automation" or "inserting keystrokes" using AutoIt, AutoHotkeys or any other Automation tool from inside the main installer.
You would need to build an automation script for each installer and execute it from the main installer. Its probably nice for testing and replaying the individual component installations.
But YAGNI.
Given that I need to do this, what's the best way to go about it?
Make a full run and note all the installation steps.
list the installers you need
find the download urls
download the installers
download additional tools you need (unzip?)
for each installer check the CLI arguments it accepts
check if you get a decent default configuration, when leaving some CLI args away
install each installer from the CLI into your target location
Then translate the steps you have into the Installer builder of your choice. Its mostly copy pasting CLI commands into Exec() or ShellExec() calls, followed by copying config files and fiddling around with cross-component configuration.
I haven't seen that or even if they can be used to control other installers in a very detailed fashion
Just think of all the game installers shipping DirectX or the pre-packaged web-development stacks like XAMPP or WPN-XM (speaking of the last: you might take a look at this InnoSetup script file).
A wrapped installation of multiple software components is pretty common.

Launch local PowerShell script from link in local browser session

My boss has asked me to look into launching a PowerShell script I've written (which is to be deployed to all users desktops) when the user clicks on a link in their web browser (and not by the clicking on a desktop icon as I've proposed). I did not think this was possible for security reasons and can't understand how this can be done. Does anyone know if this is possible ? i.e. a web link can somehow trigger the running of a PowerShell script held locally on the user's machine? Seems dangerous to me but he says it can be done !!!
No, it won't automatically run a linked script and will require the user to download and then run it.
The way to accomplish the goal of running a script when they click on something, though, would be to do it with server-side code that launches the script remotely or creates a scheduled task on the user's system. However, this may not work if the user needs to see the command window or interact with the script.

Export current DSC configuration for import to another server (using IIS website as an example)

I'm trying to wrap my hand around DSC in PowerShell 4.0, what's possible, and what's not. I've installed xWebAdministration Module.
Could I create a website in IIS, then somehow export it to the a .ps1 file (I think in the MOF format). For example, txWebAdministration has a sample called xWebAdministration\Examples\Sample_xWebsite_NewWebsite.ps1. Could I use an existing website to build a file like this? Or do I have to type everything in manually?
I'm basically trying to jump in and try some things without reading from end-to-end. I was hoping Get-DscConfiguration would somehow read my IIS configuration and create such a file.
For example, in SQLServer, you can create a database and tables using the graphical user interface of SQL Studio Management Studio (SSMS), then export a script to re-create those same tables on another server.
Is such a concept possible with DSC, or am I missing the boat.
There is nothing like this at the moment.
Keep in mind DSC is very new and quite sparse. The DSC Resource Kit is created by people at Microsoft, but isn't supported or all that official.
You could write a script to parse an existing web site and export it to a configuration in a PS1, or even directly into an MOF (it's a text file too), but there is nothing close to this functionality existing at the moment.
Your best bet is probably to type it out manually at this time.
There is a tool that creates a DSC configuration from an existing machine called GuardRail but I think it will not support the experimental xWebAdministration Module. As briantist said, it wouldn't be too difficult to create a powershell script that uses WebAdministration commandlets to produce a DSC configuration.
In fact a workmate asked me the same question today and I'm considering writing one. If you I'll update my answer in a few days with a script that will do this.

Location of Websphere Application Server config files

I have a Websphere Application Server v8.0, and my job requires me to change the location of my JDBC data source to different values to test in different environments. I traditionally would do this via the admin console and change the settings via the Resources > JDBC > Data sources section, but I'd like to write a script to change these settings. When I run the admin console, where do the settings get stored? I can run the console vis-a-vis the Servers tab in Eclipse (Rational Application Developer) or by navigating to localhost:9044, but I don't know where the settings are stored - which I'd need to write said script.
Can anybody help me out?
From what I remember of WebSphere Application Server, the settings are ultimately persisted to the file system - however you shouldn't be changing them this way because application server config is a messy and complicated business and by directly changing settings you risk destroying your app server.
I'd recommend checking out this redbook, particularly Chapter 8 which describes how you can configure your app server with scripts. Also I seem to recall plans to display the equivalent scripting commands in the admin console.
If it helps, I had a quick look locally and found a reference to my JDBC data source in "resources.xml" located within the websphere directory at...
<server profile root>\config\cells\<aNodeCell>\nodes\<aNode>\servers\<aServer>
In the past I've used xml config to read values for convenience, but not often to update. Instead I have made use of some of the jython script options available and can echo Jim's response to check out the options there in case there is something that would be a viable alternative.
Edit:
There is another link that may be of interest Configuring data access with wsadmin scripting. I've not used this particular feature of wsadmin myself but it does appear to show promise at first glance.
If you want to write a script, then rather than looking at file system write a proper jython script, which will do your modifications in the similar way as you would do it via console.
To make writing script easier you can use:
Command assistance in the console - the Help portlet on the right shows last invoked command in jython
Script library, which already provides some scripts - Automating data access resource configuration using wsadmin scripting
And basic scripting commands - Configuring data access with wsadmin scripting