Auto configuring IIS websites / app pools using PowerShell or other scripts - powershell

We have a need in our project to automate the process of creating AppPools and Websites in IIS . We would like to write some batch script to get this done. From my research I found that PowerShell has commands that can be used. However when I tried to run IIS module commands in PowerShell on Windows Server 2012 , it does not recognize the commands. Is it correct that this feature was only available for Windows 7 / IIS 7 ? Is it also available now on Windows 2012 R2 / IIS 8. If so where can I find proper documentation and help ?

This feature is of course available in Windows 8/8.1 and Windows Server 2012/2012 R2.
You probably forgot to run Add-PSSnapin WebAdministration before executing other IIS cmdlets.
You can find the full documentation on the Microsoft Technet.
If you run Windows 8.1 or Windows Server 2012 R2 (i.e. you have Windows PowerShell 4.0) you can also use the new PowerShell Desired State Configuration feature with the xWebAdministration Module to create WebAppPools and Websites.

Related

Powershell Solution: Run modules not supported on a older version of Powershell

I'm currently trying to remote to multiple servers that are on PowerShell 4.0 whereas the local computer currently runs on 5.0+. I am attempting to query servers that are Server 2016 for the Local Administrator group, but will fail for servers that are on 2012. Which upon researching the error messages for cmdlets from Microsoft.Powershell.LocalAccounts indicates that the modules don't exist for 2012.
Rather than updating the PowerShell version, or installing the modules to each server, I wondering if it's possible to execute cmdlets from the local 2016 into remote sessions of the 2012 servers.
Technically, yes, you could copy modules from the local server to one of the module directories on the remote server's $env:PSModulePath and import them in the remote session, but as #mklement0 stated there is no guarantee current modules will work with PowerShell 4.0, let alone Server 2012.
That said, Microsoft.PowerShell.LocalAccounts is a module provided by PowerShell 5.1, not the OS, and the features should still work on 2012. However, I don't have a 2012 instance I can test with. But you may be able to get your task done by upgrading your servers' PowerShell version to PowerShell 5.1 (Windows Management Framework 5.1) to leverage the additional features and built-in modules this version brings. But any modules that are shipped with later Windows versions and not PowerShell itself will remain unavailable.
$localAdminUsers = net localgroup administrators
After some talking with a colleague, I realized I had overcomplicated my script, when I could have used the command prompt. From there, I parse the string for the users I was looking for.
Thank you for your responses.

Packer - Windows Server 2012R2 - Install PowerShell 5

I'm having trouble with installing PowerShell 5 on Windows Server 2012 R2 using Packer.
To install PowerShell 5.1, I'm using chocolatey
powershell
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
choco install PowerShell -y
I need to to do this for two packer builder:
Amazon Web Services EC2 AMI.
Hyper-V Vagrant.
With the Amazon Web Services EC2 AMI I've tried executing the above from the following locations
As part of the user_data_file script.
As an inline provision script.
I've added the windows-restart provision in the flow after the execution of the fragment.
Similarly I've tried the same with the Hyper-V Vagrant both as part of the Autounattend flow and as an inline provision.
In both cases the installation fails because the user profile is not created. At least I think that is the problem. As a reference, I've faced the exact same problem when installing sql server express.
Has anyone managed to accomplish this flow and what is your recommendation?
PowerShell package uses MSU (Windows Update file). There are a couple of considerations here:
Ensure Windows Updates Service is turned on. Chocolatey doesn't do that yet, although there is an issue filed.
MSUs must be run locally from the machine. So if you are running over WinRM, you instead need to have it set up a scheduled task to call choco install and then run it that way.
Yes, that second point is accurate. No, it is not Chocolatey's fault. That's a Microsoft design decision with MSU files. It's a real PITA.
FYI - BoxStarter handles it appropriately, and it can be used with Packer. You will find less pain if you look there.
HTH

Powershell MQ Snap-in MO74 doesn't work correctly

I have downloaded and installed MO74: WebSphere MQ - Windows PowerShell Library on a Windows Server 2012 with IBM WebSphere MQ Explorer Version: 7.5.0.2
The original website is website http://www-01.ibm.com/support/docview.wss?rs=171&uid=swg24017698&loc=en_US&cs=utf-8&lang=en
I have both tried to install for powershell 64bit and for powershell 32bit.
For 64bit I can add the plugin (Add-PSSnapin IBM.Powershell.WebsPhereMQ) without errors.
Afterwards the commands (for instance a simple Get-WMQQueue) gives no errors but no results as well.
For 32bit I can't even load the plugin.
The error is:
Add-PSSnapin : The Windows PowerShell snap-in 'IBM.Powershell.WebsPhereMQ' is not installed on this computer.
Anyone has this working with Windows Server 2012 and have a clue what can be wrong?
Installed MO74 on Windows Server 2012. System already had MQ8.0 installed on it. The Get-WMQQueue cmdlet works for me.
Got to know from the MO74 developers that MO74 can be used with 32 bit PowerShell only. Support for 64 bit PowerShell is not available yet.

Manage web farms from powershell v3.0

I have been searching for a way to create new web farms add add servers to it with PowerShell.
I stumbled on this link http://www.iis.net/learn/web-hosting/microsoft-web-farm-framework-20-for-iis-7/web-farm-framework-20-for-iis-cmdlets-for-windows-powershell which says that you should add a snapin called WebFarmSnapin.
But this does not seem to work at all in powershell v3.0 because it only says:
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 3.
Does anyone know how to manage web farms in PowerShell v3.0?
At last I found a way to do this!
http://brentdacodemonkey.wordpress.com/2014/02/12/automating-arr-configuration/
You can generate a script from the Configuration Editor in IIS Manager. But the funny thing is that on my Windows 7 machine I could not generate PowerShell scripts. I had to do it directly on the 2012 server.

how to run iis 7 express in windows xp in unattended mode

IIS 5.1 shipped with windows xp has 10 connection limit. Singll ASP .NET MVC application can use more connections even if HTTP 1.1 is disabled.
To fix this, Microsoft recommends to use IIS 7 Express in XP.
I tried
iisexpress /path:c:\myapp /port:80 /clr:v2.0
and it works in local computer.
This XP computer has number of users. User can log off antytime.
How to run iisexpress automatically if computer is turned on ? I googled but havent found a way like to run it as XP service ?
How to run IIS Express as a process started via a Windows Service describes how to run it from application. However I'm looking a way to use Windows XP as http server without application. Maybe srvany can help ?