Author Posts

May 6, 2013 at 5:38 am

I am trying to build powershell program which would:

  1. connect to the remote server
  2. Show number of active IIS app pools on the active server
  3. based on the selection (1,2,3,4,....n etc) it would reset app pool

I am newbie in powershell so I am not sure where to start, can you please give me some tips?

thanks! 🙂

May 6, 2013 at 9:47 am

Hi Martin!

 

The script you want to write is not inherently hard, but the challange you face is that it requires some knowledge of PowerShell. Even if I wrote you one (which is not the goal to these forums) you wouldn't be able to get it to run.  Let me see if I can get you pointed in the right direction.  I'm happy to help with specific questions as you progress.

1. You need to use PowerShell Remoting to manage IIS servers remotly. This needs to be enabled on the target servers, plus may require permission from your security department.

2. You need to know how to access the IIS cmdlets form the WebAdministration Module

3. You need to know what a provider is and how to access information through one. In your case, you will want to access the IIS provider.

The best course of action would be to go through the first 18 chapters of Don Jones "LEarn Windows PowerShell 3 in a Month of Lunches".  This will get you almost everything you need to build the script. I'll be happy to point out specifics if you post your work here.

Also, for IIS spefic information gathering using PowerShell, you can check out the book "Learn Windows IIS in a Month of Lunches" – however it requires that you have the basic PowerShell skills discussed in Don's book first.

Hope this helps getting you started!

 

Jason

 

 

May 7, 2013 at 6:00 am

hi Jason,

thanks for info, I have started writing something:

1. Code is accepting server name

2. I have found iis Get-wmiObject info command which could possibly display/accept IIS application settings

for example:

$server_name = Read-Host 'SERVER NAME:'

foreach($vm in $server_name)

{
$iis = Get-WmiObject -Namespace root\MicrosoftIISv2 -Class IIsApplicationPoolSetting -ComputerName $server_name -Authentication PacketPrivacy

	$iis

	$i = $iis.Count

		for ($k = 0; $k -lt $i; $k++)
		{

			$name = $iis[$k].Name

		}
}

I assume get-WmiObject creates connection between.

when i ran this script i have got:

Get-WmiObject : A parameter cannot be found that matches parameter name 'Authen
tication'.
At H:\scripts\apppool.ps1:6 char:128

any idea what went wrong? 🙂

thanks! 🙂

May 7, 2013 at 6:23 am

Hello Martin.  Can you try changing:

-Authentication PacketPrivacy

to

-Authentication 6

 

May 7, 2013 at 6:43 am

same error as above:

Get-WmiObject : A parameter cannot be found that matches parameter name ‘Authen
tication’.
At H:\scripts\apppool.ps1:6 char:128

May 8, 2013 at 3:38 pm

Well, one way is

Get the list of apppools

Invoke-command -ComputerName web1,web2 {Get-WebAppPool}

Invoke-Command -CompteName Web1,Web2 {Restart-webapppool -name }

 

However – Without PowerShell Remoting this wont work.