how to operate On List of IIS Application Pools On Remote Server Using Powershel

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Jason Helmick Jason Helmick 4 years, 1 month ago.

  • Author
    Posts
  • #4058
    Profile photo of Martin Lawrence
    Martin Lawrence
    Participant

    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! 🙂

  • #4066
    Profile photo of Jason Helmick
    Jason Helmick
    Moderator

    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

     

     

  • #4145
    Profile photo of Martin Lawrence
    Martin Lawrence
    Participant

    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! 🙂

  • #4151
    Profile photo of Lery
    Lery
    Participant

    Hello Martin.  Can you try changing:

    -Authentication PacketPrivacy

    to

    -Authentication 6

     

  • #4157
    Profile photo of Martin Lawrence
    Martin Lawrence
    Participant

    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

  • #4394
    Profile photo of Jason Helmick
    Jason Helmick
    Moderator

    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.

     

You must be logged in to reply to this topic.