Is it possible to capture the PowerShell commands that are generated from Windows GUIs like IIS? - powershell

I was reading Learn Windows PowerShell 3 in a Month of Lunches by Jones and Hicks and this passage from Chapter 1 caught my attention:
Microsoft's goal for Windows PowerShell is to build 100% of a production's administrative functionality in the shell. Microsoft continues to build GUI consoles, but those consoles are executing PowerShell commands behind the scenes. That approach forces the company to make sure that every possible thing you can do with the product is accessible through the shell. If you need to automate a repetitive task or create a process that the GUI doesn't enable well, you can drop into the shell and take full control for yourself.
A number of Microsoft products have already adopted this approach, including Exchange Server 2007 and 2010, SharePoint Server 2010, many of the System Center products, and many components of Windows itself. Going forward, more and more products and Windows components will follow this pattern. The latest version of Windows Server, which is where PowerShell v3 was introduced, is almost completely managed from PowerShell - or by a GUI sitting atop PowerShell. That's why you can't afford to ignore PowerShell - over the next few years, it'll become the basis for more and more administration.
I was wondering if it is possible to capture the PowerShell commands that are generated from Windows GUIs and tools like IIS?
It would make it very easy to create automation scripts that way, and also help in learning PowerShell.

Stick a Start-Transcript call in your all-host profile ($Profile.CurrentUserAllHosts), probably generating a filename for it based on date or counter or something.
Use something like this Transcript module to add support first for hosts that don't normally allow it (ISE v4.0 and below, SharePoint, etc), possibly only including it if the host isn't PowerShell itself.

Related

Calling SCCM from PowerShell or CMD

We have an application (really a platform) which we need to customise on a per-user role basis. This involves asking some questions and then installing the application and then customising it before handing back to the user.
After the app has been installed, we need to update the application (but not the settings) from time to time as new versions are released.
Our IT people have said I should use a PowerShell/cmd script to do the initial install - because of its specificity. I'd like to get SCCM to do the version updates but I've been told that if SCCM doesn't do the install, it doesn't know there's anything to update - fair enough! So I was wondering how can I call SCCM from my PowerShell script to perform the initial install and then return control to my script for final customisation?
On this site you can learn more about managing SCCM over PowerShell:
https://learn.microsoft.com/en-us/powershell/sccm/overview?view=sccm-ps
But this won't be just a simple script, it will take a bit of time to create!

Create a script to uninstall and install certain programs

I work at a retail store, where I get new computers in all day that I need to uninstall certain programs from (like McAfee) and install certain programs on (like Java, Silverlight). Until now I have been using deCrapifier and ninite to get this done, but i was wondering if I could make a script that would automatically do this. A script that i could put on a USB and just run one time on each computer.
Could i accomplish this using a powershell script mabye?
Yes, you can! Provided you know the software you are going to install, and have administrative rights. It will take you some time to get it right as you need to detect each of the software separately and potentially follow different steps to uninstall, but nothing is impossible.
Many of your suggested examples (such as Java, and SilverLight's /q switch) have "Silent," or "Quiet" installers that do everything for you. These are simple to launch from a batch file, or even via PowerShell if you'd like.
Additionally, for uninstallations, if you know the application's name as it exists on that box (exactly), you can use PowerShell to uninstall applications, as well.

Can i use a wix installer to just run a couple of custom commands

I am working on a project where we need to repeat certain steps with powershell to deploy stuff. i would like to create a process/install guidance (steps supported with UI) with WIX but after the msi has finished i have an entry in programs and features. I just need it to execute the powershell and the end without registering in windows. i might be using the wrong tooling or whatever, any suggestions are welcome.
Definitely not recommended unless you want to track the deployment of these scripts on different systems by checking the entries in ARP (Add/Remove Programs), and even then it clogs up the Add/Remove view of your computers. Most system administrators hate this approach, it is better to just write to your own registry key and read it back from every machine.
What are the scripts doing? Are you actually installing files.

Creating application installers with PowerShell

Hi I'm wondering if it's possible to create application installers for MSI's. What I want it to do is when I run an MSI I want to be able to run it in it's own process so I can reference it via it's process ID so I can send various keys to it so it installs the way I want it too.
I can code in both C and Java but for the Sys Admins would be good if I could code it in Powershell for them. Also I've seen other installers that can detect when the next instance of the install screen appears so it immediately send the new command keys, well appears that way.
Any advice is welcomed.
MSI's traditionally allow for admins to provide an answer file or arguments using msiexec.
See this q/a on SuperUser or this SO Q/A for more info.
You can then use PowerShell to call the exe's by using the 3rd party Windows Installer PowerShell Module
.
[The Windows Installer PowerShell Module] Exposes Windows Installer functionality to PowerShell, providing means to query installed product and patch information and to query views on packages.
for example:
install-msiproduct .\example.msi -destination (join-path $env:ProgramFiles Example)
See this page for additional examples.
If you need to send keystrokes to the msi gui; you could look in to the Windows Automation Snapin for PowerShell. I have never used this personally.

What are my Windows Job Flow Control languages/options?

We are currenly using bat/cmd files to execute jobs, examine a return code and based on the return code execute the next sequence.
I am thinking that .VBS extensioned files may give us a richer language for doing this kind of thing than batch files.
If this is correct, why would someone choose bat files over VBS files? Are VBS files considered "Windows Scripting Host" files? how is this related to Powershell?
Sorry, I am a bit ignorant on my options and the differences.
Writing batch files was powerfull, it still persist nowdays, in fact people are still maintaining batch but it's old fashion.
A few years ago Microsoft introduced Windows Script Host, which is an infrastructure of scripting languages that allows the writing of Visual Basic or Java scripts. This infrastructure allowed scripters to interact with COM objects and in so doing access to almost everything in Windows. (edited) according to #EBGreen remark, WSH is present from W2K to W2K8 R2
In 2006 Microsoft introduced PowerShell. This scripting environment works on the top of the .Net framework. This means that the PowerShell scripter is able to do most of the things a C# prorammer does. The difference with VBS is that PowerShell is more concise and more coherent than VBS because everything is done using .NET types. Powershell is procedural programming using objects (properties and methods). (edited) according to #EBGreen remark, PowerShell V1.0 is present in Vista and W2K8 and PowerShell V2.0 is present in Windows 7 and W2K8 R2. Powershell 2.0 can be deployed begining on Windows XP SP2.
As far as process control is concern, with powershell you can start, stop, wait for the end of a process.