remote application pool recycle using WMI \ PowerShell


  1.    02 Nov 2007 #1
    Bill Guest

    remote application pool recycle using WMI \ PowerShell


    I'm having some trouble finding the best method for recycling remote IIS6
    application pools using PowerShell.

    In the past this has always been very easy using VB script:

    Function PoolRecycle(strServer)

    On Error Resume Next
    Err.Clear

    Dim objWMIService
    Dim colItems
    Dim objItem

    'recycle application pool
    WScript.Echo ""
    Err.Clear
    Set objWMIService = GetObject _
    ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
    & strServer & "\root\microsoftiisv2")

    'connect to WMI
    Set colItems = objWMIService.ExecQuery("Select * From IIsApplicationPool")

    'Step through the objects to be recycled
    For each objItem in colItems
    objItem.Recycle
    If err = 0 Then
    WScript.Echo(strServer & " - " & ObjItem.Name & " Recycled")
    PoolRecycle = "success"
    Else
    WScript.Echo("Unable to recycle the application pool on " & strServer)
    PoolRecycle = "failed"
    End If
    Next

    End Function

    I have attempted to duplicate the same thing in PowerShell, but I believe I
    am still running into an issue with the pktPrivacy authentication setting.
    The following code works when executing localy, but not on a remote host:

    Function PoolRecycle($strServerName)
    {
    $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    $objWMI.Scope.Path = "\\" + $strServerName + "\root\microsoftiisv2"
    $objWMI.Scope.Options.Authentication = 6
    $pools = $objWMI.Get()
    foreach ($pool in $pools)
    {
    $pool.recycle()
    if (!$?)
    {
    Write-Host $pool.name " - ERROR"
    }
    else
    {
    Write-Host $pool.name " - Recycled"
    }
    }
    }


    Any help or better ways of accomplishing this in PowerShell would be very
    much appreciated!

    Thanks
    Bill


      My System SpecsSystem Spec

  2.    02 Nov 2007 #2
    Shay Levi Guest

    Re: remote application pool recycle using WMI \ PowerShell



    If you know the application pool name (the function returns true/false respectively:

    function Recycle-AppPool{
    param([string]$server,[string]$appPool)

    ([WMI]"\\$server\root\MicrosoftIISv2:IIsApplicationPool.Name='W3SVC/AppPools/$appPool'").recycle();
    if($? -ne 0}{$false} else {$true}
    }


    To get a list of application pool names:

    $computer = "your Server name/ip"
    gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2" -computer
    $computer | % {$_.name}



    -----
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com



    > I'm having some trouble finding the best method for recycling remote
    > IIS6 application pools using PowerShell.
    >
    > In the past this has always been very easy using VB script:
    >
    > Function PoolRecycle(strServer)
    >
    > On Error Resume Next
    > Err.Clear
    > Dim objWMIService
    > Dim colItems
    > Dim objItem
    > 'recycle application pool
    > WScript.Echo ""
    > Err.Clear
    > Set objWMIService = GetObject _
    > ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
    > & strServer & "\root\microsoftiisv2")
    > 'connect to WMI
    > Set colItems = objWMIService.ExecQuery("Select * From
    > IIsApplicationPool")
    > 'Step through the objects to be recycled
    > For each objItem in colItems
    > objItem.Recycle
    > If err = 0 Then
    > WScript.Echo(strServer & " - " & ObjItem.Name & " Recycled")
    > PoolRecycle = "success"
    > Else
    > WScript.Echo("Unable to recycle the application pool on " &
    > strServer)
    > PoolRecycle = "failed"
    > End If
    > Next
    > End Function
    >
    > I have attempted to duplicate the same thing in PowerShell, but I
    > believe I am still running into an issue with the pktPrivacy
    > authentication setting. The following code works when executing
    > localy, but not on a remote host:
    >
    > Function PoolRecycle($strServerName)
    > {
    > $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    > $objWMI.Scope.Path = "\\" + $strServerName + "\root\microsoftiisv2"
    > $objWMI.Scope.Options.Authentication = 6
    > $pools = $objWMI.Get()
    > foreach ($pool in $pools)
    > {
    > $pool.recycle()
    > if (!$?)
    > {
    > Write-Host $pool.name " - ERROR"
    > }
    > else
    > {
    > Write-Host $pool.name " - Recycled"
    > }
    > }
    > }
    > Any help or better ways of accomplishing this in PowerShell would be
    > very much appreciated!
    >
    > Thanks
    > Bill

      My System SpecsSystem Spec

  3.    02 Nov 2007 #3
    Shay Levi Guest

    Re: remote application pool recycle using WMI \ PowerShell


    Pinging the remote machine before trying to recycle pools is a recommended
    practice.

    Also, I wrote:

    gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2" -computer
    $computer | % {$_.name}

    for those who are not familiar with gwmi and %, I should say that they are
    aliases for:
    gwmi = get-wmiobject
    % = foreach-object

    I should have written it like:

    get-wmiobject -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    -computer $computer | foreach-object {$_.name}



    -----
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com



    > If you know the application pool name (the function returns true/false
    > respectively:
    >
    > function Recycle-AppPool{
    > param([string]$server,[string]$appPool)
    > ([WMI]"\\$server\root\MicrosoftIISv2:IIsApplicationPool.Name='W3SVC/A
    > ppPools/$appPool'").recycle();
    > if($? -ne 0}{$false} else {$true}
    > }
    > To get a list of application pool names:
    >
    > $computer = "your Server name/ip"
    > gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    > -computer
    > $computer | % {$_.name}
    > -----
    > Shay Levi
    > $cript Fanatic
    > http://scriptolog.blogspot.com

    >> I'm having some trouble finding the best method for recycling remote
    >> IIS6 application pools using PowerShell.
    >>
    >> In the past this has always been very easy using VB script:
    >>
    >> Function PoolRecycle(strServer)
    >>
    >> On Error Resume Next
    >> Err.Clear
    >> Dim objWMIService
    >> Dim colItems
    >> Dim objItem
    >> 'recycle application pool
    >> WScript.Echo ""
    >> Err.Clear
    >> Set objWMIService = GetObject _
    >> ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
    >> & strServer & "\root\microsoftiisv2")
    >> 'connect to WMI
    >> Set colItems = objWMIService.ExecQuery("Select * From
    >> IIsApplicationPool")
    >> 'Step through the objects to be recycled
    >> For each objItem in colItems
    >> objItem.Recycle
    >> If err = 0 Then
    >> WScript.Echo(strServer & " - " & ObjItem.Name & " Recycled")
    >> PoolRecycle = "success"
    >> Else
    >> WScript.Echo("Unable to recycle the application pool on " &
    >> strServer)
    >> PoolRecycle = "failed"
    >> End If
    >> Next
    >> End Function
    >> I have attempted to duplicate the same thing in PowerShell, but I
    >> believe I am still running into an issue with the pktPrivacy
    >> authentication setting. The following code works when executing
    >> localy, but not on a remote host:
    >>
    >> Function PoolRecycle($strServerName)
    >> {
    >> $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    >> $objWMI.Scope.Path = "\\" + $strServerName + "\root\microsoftiisv2"
    >> $objWMI.Scope.Options.Authentication = 6
    >> $pools = $objWMI.Get()
    >> foreach ($pool in $pools)
    >> {
    >> $pool.recycle()
    >> if (!$?)
    >> {
    >> Write-Host $pool.name " - ERROR"
    >> }
    >> else
    >> {
    >> Write-Host $pool.name " - Recycled"
    >> }
    >> }
    >> }
    >> Any help or better ways of accomplishing this in PowerShell would be
    >> very much appreciated!
    >> Thanks
    >> Bill

      My System SpecsSystem Spec

  4.    02 Nov 2007 #4
    Bill Guest

    Re: remote application pool recycle using WMI \ PowerShell


    Shay,

    Thanks for the help, but I see the namespace "root\MicrosoftIISv2" operate
    differently when attempting to access it on a remote IIS6 computer (default
    W2K3 installs).


    The code examples you pointed out all work fine when targeting the namespace
    locally, but I recieve access denied messages when useing the same commands
    remotely.

    I have tried from multiple machines to multiple servers. The VB Script I
    supplied still works in all cases, which leads me to believe I am not setting
    the PowerShell WMI object authentication to use pktPrivacy correctly.

    Any advice would be appreciated.

    Thanks
    Bill

    "Shay Levi" wrote:

    > Pinging the remote machine before trying to recycle pools is a recommended
    > practice.
    >
    > Also, I wrote:
    >
    > gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2" -computer
    > $computer | % {$_.name}
    >
    > for those who are not familiar with gwmi and %, I should say that they are
    > aliases for:
    > gwmi = get-wmiobject
    > % = foreach-object
    >
    > I should have written it like:
    >
    > get-wmiobject -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    > -computer $computer | foreach-object {$_.name}
    >
    >
    >
    > -----
    > Shay Levi
    > $cript Fanatic
    > http://scriptolog.blogspot.com
    >
    >
    >

    > > If you know the application pool name (the function returns true/false
    > > respectively:
    > >
    > > function Recycle-AppPool{
    > > param([string]$server,[string]$appPool)
    > > ([WMI]"\\$server\root\MicrosoftIISv2:IIsApplicationPool.Name='W3SVC/A
    > > ppPools/$appPool'").recycle();
    > > if($? -ne 0}{$false} else {$true}
    > > }
    > > To get a list of application pool names:
    > >
    > > $computer = "your Server name/ip"
    > > gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    > > -computer
    > > $computer | % {$_.name}
    > > -----
    > > Shay Levi
    > > $cript Fanatic
    > > http://scriptolog.blogspot.com

    > >> I'm having some trouble finding the best method for recycling remote
    > >> IIS6 application pools using PowerShell.
    > >>
    > >> In the past this has always been very easy using VB script:
    > >>
    > >> Function PoolRecycle(strServer)
    > >>
    > >> On Error Resume Next
    > >> Err.Clear
    > >> Dim objWMIService
    > >> Dim colItems
    > >> Dim objItem
    > >> 'recycle application pool
    > >> WScript.Echo ""
    > >> Err.Clear
    > >> Set objWMIService = GetObject _
    > >> ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
    > >> & strServer & "\root\microsoftiisv2")
    > >> 'connect to WMI
    > >> Set colItems = objWMIService.ExecQuery("Select * From
    > >> IIsApplicationPool")
    > >> 'Step through the objects to be recycled
    > >> For each objItem in colItems
    > >> objItem.Recycle
    > >> If err = 0 Then
    > >> WScript.Echo(strServer & " - " & ObjItem.Name & " Recycled")
    > >> PoolRecycle = "success"
    > >> Else
    > >> WScript.Echo("Unable to recycle the application pool on " &
    > >> strServer)
    > >> PoolRecycle = "failed"
    > >> End If
    > >> Next
    > >> End Function
    > >> I have attempted to duplicate the same thing in PowerShell, but I
    > >> believe I am still running into an issue with the pktPrivacy
    > >> authentication setting. The following code works when executing
    > >> localy, but not on a remote host:
    > >>
    > >> Function PoolRecycle($strServerName)
    > >> {
    > >> $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    > >> $objWMI.Scope.Path = "\\" + $strServerName + "\root\microsoftiisv2"
    > >> $objWMI.Scope.Options.Authentication = 6
    > >> $pools = $objWMI.Get()
    > >> foreach ($pool in $pools)
    > >> {
    > >> $pool.recycle()
    > >> if (!$?)
    > >> {
    > >> Write-Host $pool.name " - ERROR"
    > >> }
    > >> else
    > >> {
    > >> Write-Host $pool.name " - Recycled"
    > >> }
    > >> }
    > >> }
    > >> Any help or better ways of accomplishing this in PowerShell would be
    > >> very much appreciated!
    > >> Thanks
    > >> Bill
    >
    >
    >
      My System SpecsSystem Spec

  5.    03 Nov 2007 #5
    Shay Levi Guest

    Re: remote application pool recycle using WMI \ PowerShell


    Bill

    I can't test it right now. Try this on the remote server(s

    1. Start > Run > dcomcnfg > ENTER
    2. In the left pane (Compnent Services.msc) expand "Component Services" >
    Computers
    3. Right click "My Computer"
    4. In the "Default Properties" tab tick the "Enable COM Internet Services
    on this computer" checkbox
    5. Reboot remote server
    6. Test again

    I can't recall if you need to add Access Permissions in the "COM Security"
    tab.



    -----
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com



    > Shay,
    >
    > Thanks for the help, but I see the namespace "root\MicrosoftIISv2"
    > operate differently when attempting to access it on a remote IIS6
    > computer (default W2K3 installs).
    >
    > The code examples you pointed out all work fine when targeting the
    > namespace locally, but I recieve access denied messages when useing
    > the same commands remotely.
    >
    > I have tried from multiple machines to multiple servers. The VB
    > Script I supplied still works in all cases, which leads me to believe
    > I am not setting the PowerShell WMI object authentication to use
    > pktPrivacy correctly.
    >
    > Any advice would be appreciated.
    >
    > Thanks
    > Bill
    > "Shay Levi" wrote:
    >

    >> Pinging the remote machine before trying to recycle pools is a
    >> recommended practice.
    >>
    >> Also, I wrote:
    >>
    >> gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    >> -computer $computer | % {$_.name}
    >>
    >> for those who are not familiar with gwmi and %, I should say that
    >> they are
    >> aliases for:
    >> gwmi = get-wmiobject
    >> % = foreach-object
    >> I should have written it like:
    >>
    >> get-wmiobject -class IIsApplicationPool -namespace
    >> "root\MicrosoftIISv2" -computer $computer | foreach-object {$_.name}
    >>
    >> -----
    >> Shay Levi
    >> $cript Fanatic
    >> http://scriptolog.blogspot.com

    >>> If you know the application pool name (the function returns
    >>> true/false respectively:
    >>>
    >>> function Recycle-AppPool{
    >>> param([string]$server,[string]$appPool)
    >>> ([WMI]"\\$server\root\MicrosoftIISv2:IIsApplicationPool.Name='W3SVC/
    >>> A
    >>> ppPools/$appPool'").recycle();
    >>> if($? -ne 0}{$false} else {$true}
    >>> }
    >>> To get a list of application pool names:
    >>> $computer = "your Server name/ip"
    >>> gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    >>> -computer
    >>> $computer | % {$_.name}
    >>> -----
    >>> Shay Levi
    >>> $cript Fanatic
    >>> http://scriptolog.blogspot.com
    >>>> I'm having some trouble finding the best method for recycling
    >>>> remote IIS6 application pools using PowerShell.
    >>>>
    >>>> In the past this has always been very easy using VB script:
    >>>>
    >>>> Function PoolRecycle(strServer)
    >>>>
    >>>> On Error Resume Next
    >>>> Err.Clear
    >>>> Dim objWMIService
    >>>> Dim colItems
    >>>> Dim objItem
    >>>> 'recycle application pool
    >>>> WScript.Echo ""
    >>>> Err.Clear
    >>>> Set objWMIService = GetObject _
    >>>> ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
    >>>> & strServer & "\root\microsoftiisv2")
    >>>> 'connect to WMI
    >>>> Set colItems = objWMIService.ExecQuery("Select * From
    >>>> IIsApplicationPool")
    >>>> 'Step through the objects to be recycled
    >>>> For each objItem in colItems
    >>>> objItem.Recycle
    >>>> If err = 0 Then
    >>>> WScript.Echo(strServer & " - " & ObjItem.Name & " Recycled")
    >>>> PoolRecycle = "success"
    >>>> Else
    >>>> WScript.Echo("Unable to recycle the application pool on " &
    >>>> strServer)
    >>>> PoolRecycle = "failed"
    >>>> End If
    >>>> Next
    >>>> End Function
    >>>> I have attempted to duplicate the same thing in PowerShell, but I
    >>>> believe I am still running into an issue with the pktPrivacy
    >>>> authentication setting. The following code works when executing
    >>>> localy, but not on a remote host:
    >>>> Function PoolRecycle($strServerName)
    >>>> {
    >>>> $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    >>>> $objWMI.Scope.Path = "\\" + $strServerName + "\root\microsoftiisv2"
    >>>> $objWMI.Scope.Options.Authentication = 6
    >>>> $pools = $objWMI.Get()
    >>>> foreach ($pool in $pools)
    >>>> {
    >>>> $pool.recycle()
    >>>> if (!$?)
    >>>> {
    >>>> Write-Host $pool.name " - ERROR"
    >>>> }
    >>>> else
    >>>> {
    >>>> Write-Host $pool.name " - Recycled"
    >>>> }
    >>>> }
    >>>> }
    >>>> Any help or better ways of accomplishing this in PowerShell would
    >>>> be
    >>>> very much appreciated!
    >>>> Thanks
    >>>> Bill

      My System SpecsSystem Spec

  6.    04 Nov 2007 #6
    Bill Guest

    Re: remote application pool recycle using WMI \ PowerShell


    Hi Shay,

    I have tested this and it still does not resolve the issue.

    I guess I must be missing something. The fact that the VB Script works and
    the PowerShell does not, leads me to believe that I have an issue with my
    script and not the security on the target server.

    I may have to use PowerShell to call the actual .Net class instead of using
    the built in commands.

    Funny, I would have never believed that something as simple as recycling a
    remote application pool would be so hard

    Thanks again for the help.
    Bill


    "Shay Levi" wrote:

    > Bill
    >
    > I can't test it right now. Try this on the remote server(s
    >
    > 1. Start > Run > dcomcnfg > ENTER
    > 2. In the left pane (Compnent Services.msc) expand "Component Services" >
    > Computers
    > 3. Right click "My Computer"
    > 4. In the "Default Properties" tab tick the "Enable COM Internet Services
    > on this computer" checkbox
    > 5. Reboot remote server
    > 6. Test again
    >
    > I can't recall if you need to add Access Permissions in the "COM Security"
    > tab.
    >
    >
    >
    > -----
    > Shay Levi
    > $cript Fanatic
    > http://scriptolog.blogspot.com
    >
    >
    >

    > > Shay,
    > >
    > > Thanks for the help, but I see the namespace "root\MicrosoftIISv2"
    > > operate differently when attempting to access it on a remote IIS6
    > > computer (default W2K3 installs).
    > >
    > > The code examples you pointed out all work fine when targeting the
    > > namespace locally, but I recieve access denied messages when useing
    > > the same commands remotely.
    > >
    > > I have tried from multiple machines to multiple servers. The VB
    > > Script I supplied still works in all cases, which leads me to believe
    > > I am not setting the PowerShell WMI object authentication to use
    > > pktPrivacy correctly.
    > >
    > > Any advice would be appreciated.
    > >
    > > Thanks
    > > Bill
    > > "Shay Levi" wrote:
    > >

    > >> Pinging the remote machine before trying to recycle pools is a
    > >> recommended practice.
    > >>
    > >> Also, I wrote:
    > >>
    > >> gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    > >> -computer $computer | % {$_.name}
    > >>
    > >> for those who are not familiar with gwmi and %, I should say that
    > >> they are
    > >> aliases for:
    > >> gwmi = get-wmiobject
    > >> % = foreach-object
    > >> I should have written it like:
    > >>
    > >> get-wmiobject -class IIsApplicationPool -namespace
    > >> "root\MicrosoftIISv2" -computer $computer | foreach-object {$_.name}
    > >>
    > >> -----
    > >> Shay Levi
    > >> $cript Fanatic
    > >> http://scriptolog.blogspot.com
    > >>> If you know the application pool name (the function returns
    > >>> true/false respectively:
    > >>>
    > >>> function Recycle-AppPool{
    > >>> param([string]$server,[string]$appPool)
    > >>> ([WMI]"\\$server\root\MicrosoftIISv2:IIsApplicationPool.Name='W3SVC/
    > >>> A
    > >>> ppPools/$appPool'").recycle();
    > >>> if($? -ne 0}{$false} else {$true}
    > >>> }
    > >>> To get a list of application pool names:
    > >>> $computer = "your Server name/ip"
    > >>> gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    > >>> -computer
    > >>> $computer | % {$_.name}
    > >>> -----
    > >>> Shay Levi
    > >>> $cript Fanatic
    > >>> http://scriptolog.blogspot.com
    > >>>> I'm having some trouble finding the best method for recycling
    > >>>> remote IIS6 application pools using PowerShell.
    > >>>>
    > >>>> In the past this has always been very easy using VB script:
    > >>>>
    > >>>> Function PoolRecycle(strServer)
    > >>>>
    > >>>> On Error Resume Next
    > >>>> Err.Clear
    > >>>> Dim objWMIService
    > >>>> Dim colItems
    > >>>> Dim objItem
    > >>>> 'recycle application pool
    > >>>> WScript.Echo ""
    > >>>> Err.Clear
    > >>>> Set objWMIService = GetObject _
    > >>>> ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
    > >>>> & strServer & "\root\microsoftiisv2")
    > >>>> 'connect to WMI
    > >>>> Set colItems = objWMIService.ExecQuery("Select * From
    > >>>> IIsApplicationPool")
    > >>>> 'Step through the objects to be recycled
    > >>>> For each objItem in colItems
    > >>>> objItem.Recycle
    > >>>> If err = 0 Then
    > >>>> WScript.Echo(strServer & " - " & ObjItem.Name & " Recycled")
    > >>>> PoolRecycle = "success"
    > >>>> Else
    > >>>> WScript.Echo("Unable to recycle the application pool on " &
    > >>>> strServer)
    > >>>> PoolRecycle = "failed"
    > >>>> End If
    > >>>> Next
    > >>>> End Function
    > >>>> I have attempted to duplicate the same thing in PowerShell, but I
    > >>>> believe I am still running into an issue with the pktPrivacy
    > >>>> authentication setting. The following code works when executing
    > >>>> localy, but not on a remote host:
    > >>>> Function PoolRecycle($strServerName)
    > >>>> {
    > >>>> $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    > >>>> $objWMI.Scope.Path = "\\" + $strServerName + "\root\microsoftiisv2"
    > >>>> $objWMI.Scope.Options.Authentication = 6
    > >>>> $pools = $objWMI.Get()
    > >>>> foreach ($pool in $pools)
    > >>>> {
    > >>>> $pool.recycle()
    > >>>> if (!$?)
    > >>>> {
    > >>>> Write-Host $pool.name " - ERROR"
    > >>>> }
    > >>>> else
    > >>>> {
    > >>>> Write-Host $pool.name " - Recycled"
    > >>>> }
    > >>>> }
    > >>>> }
    > >>>> Any help or better ways of accomplishing this in PowerShell would
    > >>>> be
    > >>>> very much appreciated!
    > >>>> Thanks
    > >>>> Bill
    >
    >
    >
      My System SpecsSystem Spec

  7.    04 Nov 2007 #7
    Shay Levi Guest

    Re: remote application pool recycle using WMI \ PowerShell


    Are you able to list the Application poll names?

    $server="server"
    $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    $objWMI.Scope.Path = "\\$server\root\microsoftiisv2"
    $objWMI.Scope.Options.Authentication = [System.Management.AuthenticationLevel]::PacketPrivacy
    $pools = $objWMI.Get()
    $pools | foreach { $_.name }


    -----
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com



    > Hi Shay,
    >
    > I have tested this and it still does not resolve the issue.
    >
    > I guess I must be missing something. The fact that the VB Script
    > works and the PowerShell does not, leads me to believe that I have an
    > issue with my script and not the security on the target server.
    >
    > I may have to use PowerShell to call the actual .Net class instead of
    > using the built in commands.
    >
    > Funny, I would have never believed that something as simple as
    > recycling a remote application pool would be so hard
    >
    > Thanks again for the help.
    > Bill
    > "Shay Levi" wrote:
    >

    >> Bill
    >>
    >> I can't test it right now. Try this on the remote server(s
    >>
    >> 1. Start > Run > dcomcnfg > ENTER
    >> 2. In the left pane (Compnent Services.msc) expand "Component
    >> Services" >
    >> Computers
    >> 3. Right click "My Computer"
    >> 4. In the "Default Properties" tab tick the "Enable COM Internet
    >> Services
    >> on this computer" checkbox
    >> 5. Reboot remote server
    >> 6. Test again
    >> I can't recall if you need to add Access Permissions in the "COM
    >> Security" tab.
    >>
    >> -----
    >> Shay Levi
    >> $cript Fanatic
    >> http://scriptolog.blogspot.com

    >>> Shay,
    >>>
    >>> Thanks for the help, but I see the namespace "root\MicrosoftIISv2"
    >>> operate differently when attempting to access it on a remote IIS6
    >>> computer (default W2K3 installs).
    >>>
    >>> The code examples you pointed out all work fine when targeting the
    >>> namespace locally, but I recieve access denied messages when useing
    >>> the same commands remotely.
    >>>
    >>> I have tried from multiple machines to multiple servers. The VB
    >>> Script I supplied still works in all cases, which leads me to
    >>> believe I am not setting the PowerShell WMI object authentication to
    >>> use pktPrivacy correctly.
    >>>
    >>> Any advice would be appreciated.
    >>>
    >>> Thanks
    >>> Bill
    >>> "Shay Levi" wrote:
    >>>> Pinging the remote machine before trying to recycle pools is a
    >>>> recommended practice.
    >>>>
    >>>> Also, I wrote:
    >>>>
    >>>> gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    >>>> -computer $computer | % {$_.name}
    >>>>
    >>>> for those who are not familiar with gwmi and %, I should say that
    >>>> they are
    >>>> aliases for:
    >>>> gwmi = get-wmiobject
    >>>> % = foreach-object
    >>>> I should have written it like:
    >>>> get-wmiobject -class IIsApplicationPool -namespace
    >>>> "root\MicrosoftIISv2" -computer $computer | foreach-object
    >>>> {$_.name}
    >>>>
    >>>> -----
    >>>> Shay Levi
    >>>> $cript Fanatic
    >>>> http://scriptolog.blogspot.com
    >>>>> If you know the application pool name (the function returns
    >>>>> true/false respectively:
    >>>>>
    >>>>> function Recycle-AppPool{
    >>>>> param([string]$server,[string]$appPool)
    >>>>> ([WMI]"\\$server\root\MicrosoftIISv2:IIsApplicationPool.Name='W3SV
    >>>>> C/
    >>>>> A
    >>>>> ppPools/$appPool'").recycle();
    >>>>> if($? -ne 0}{$false} else {$true}
    >>>>> }
    >>>>> To get a list of application pool names:
    >>>>> $computer = "your Server name/ip"
    >>>>> gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    >>>>> -computer
    >>>>> $computer | % {$_.name}
    >>>>> -----
    >>>>> Shay Levi
    >>>>> $cript Fanatic
    >>>>> http://scriptolog.blogspot.com
    >>>>>> I'm having some trouble finding the best method for recycling
    >>>>>> remote IIS6 application pools using PowerShell.
    >>>>>>
    >>>>>> In the past this has always been very easy using VB script:
    >>>>>>
    >>>>>> Function PoolRecycle(strServer)
    >>>>>>
    >>>>>> On Error Resume Next
    >>>>>> Err.Clear
    >>>>>> Dim objWMIService
    >>>>>> Dim colItems
    >>>>>> Dim objItem
    >>>>>> 'recycle application pool
    >>>>>> WScript.Echo ""
    >>>>>> Err.Clear
    >>>>>> Set objWMIService = GetObject _
    >>>>>> ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
    >>>>>> & strServer & "\root\microsoftiisv2")
    >>>>>> 'connect to WMI
    >>>>>> Set colItems = objWMIService.ExecQuery("Select * From
    >>>>>> IIsApplicationPool")
    >>>>>> 'Step through the objects to be recycled
    >>>>>> For each objItem in colItems
    >>>>>> objItem.Recycle
    >>>>>> If err = 0 Then
    >>>>>> WScript.Echo(strServer & " - " & ObjItem.Name & " Recycled")
    >>>>>> PoolRecycle = "success"
    >>>>>> Else
    >>>>>> WScript.Echo("Unable to recycle the application pool on " &
    >>>>>> strServer)
    >>>>>> PoolRecycle = "failed"
    >>>>>> End If
    >>>>>> Next
    >>>>>> End Function
    >>>>>> I have attempted to duplicate the same thing in PowerShell, but I
    >>>>>> believe I am still running into an issue with the pktPrivacy
    >>>>>> authentication setting. The following code works when executing
    >>>>>> localy, but not on a remote host:
    >>>>>> Function PoolRecycle($strServerName)
    >>>>>> {
    >>>>>> $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    >>>>>> $objWMI.Scope.Path = "\\" + $strServerName +
    >>>>>> "\root\microsoftiisv2"
    >>>>>> $objWMI.Scope.Options.Authentication = 6
    >>>>>> $pools = $objWMI.Get()
    >>>>>> foreach ($pool in $pools)
    >>>>>> {
    >>>>>> $pool.recycle()
    >>>>>> if (!$?)
    >>>>>> {
    >>>>>> Write-Host $pool.name " - ERROR"
    >>>>>> }
    >>>>>> else
    >>>>>> {
    >>>>>> Write-Host $pool.name " - Recycled"
    >>>>>> }
    >>>>>> }
    >>>>>> }
    >>>>>> Any help or better ways of accomplishing this in PowerShell would
    >>>>>> be
    >>>>>> very much appreciated!
    >>>>>> Thanks
    >>>>>> Bill

      My System SpecsSystem Spec

  8.    04 Nov 2007 #8
    Shay Levi Guest

    Re: remote application pool recycle using WMI \ PowerShell


    Bill

    Just to clarify, I'm not able to recycle remote app pools, just list their
    names (Access denied).
    Even adding full security on IIsApplicationPool (WMI Properties) didn't resolve
    it.
    I'm still on it...

    -----
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com



    > Are you able to list the Application poll names?
    >
    > $server="server"
    > $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    > $objWMI.Scope.Path = "\\$server\root\microsoftiisv2"
    > $objWMI.Scope.Options.Authentication =
    > [System.Management.AuthenticationLevel]::PacketPrivacy
    > $pools = $objWMI.Get()
    > $pools | foreach { $_.name }
    > -----
    > Shay Levi
    > $cript Fanatic
    > http://scriptolog.blogspot.com

    >> Hi Shay,
    >>
    >> I have tested this and it still does not resolve the issue.
    >>
    >> I guess I must be missing something. The fact that the VB Script
    >> works and the PowerShell does not, leads me to believe that I have an
    >> issue with my script and not the security on the target server.
    >>
    >> I may have to use PowerShell to call the actual .Net class instead of
    >> using the built in commands.
    >>
    >> Funny, I would have never believed that something as simple as
    >> recycling a remote application pool would be so hard
    >>
    >> Thanks again for the help.
    >> Bill
    >> "Shay Levi" wrote:

    >>> Bill
    >>>
    >>> I can't test it right now. Try this on the remote server(s
    >>>
    >>> 1. Start > Run > dcomcnfg > ENTER
    >>> 2. In the left pane (Compnent Services.msc) expand "Component
    >>> Services" >
    >>> Computers
    >>> 3. Right click "My Computer"
    >>> 4. In the "Default Properties" tab tick the "Enable COM Internet
    >>> Services
    >>> on this computer" checkbox
    >>> 5. Reboot remote server
    >>> 6. Test again
    >>> I can't recall if you need to add Access Permissions in the "COM
    >>> Security" tab.
    >>> -----
    >>> Shay Levi
    >>> $cript Fanatic
    >>> http://scriptolog.blogspot.com
    >>>> Shay,
    >>>>
    >>>> Thanks for the help, but I see the namespace "root\MicrosoftIISv2"
    >>>> operate differently when attempting to access it on a remote IIS6
    >>>> computer (default W2K3 installs).
    >>>>
    >>>> The code examples you pointed out all work fine when targeting the
    >>>> namespace locally, but I recieve access denied messages when useing
    >>>> the same commands remotely.
    >>>>
    >>>> I have tried from multiple machines to multiple servers. The VB
    >>>> Script I supplied still works in all cases, which leads me to
    >>>> believe I am not setting the PowerShell WMI object authentication
    >>>> to use pktPrivacy correctly.
    >>>>
    >>>> Any advice would be appreciated.
    >>>>
    >>>> Thanks
    >>>> Bill
    >>>> "Shay Levi" wrote:
    >>>>> Pinging the remote machine before trying to recycle pools is a
    >>>>> recommended practice.
    >>>>>
    >>>>> Also, I wrote:
    >>>>>
    >>>>> gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    >>>>> -computer $computer | % {$_.name}
    >>>>>
    >>>>> for those who are not familiar with gwmi and %, I should say that
    >>>>> they are
    >>>>> aliases for:
    >>>>> gwmi = get-wmiobject
    >>>>> % = foreach-object
    >>>>> I should have written it like:
    >>>>> get-wmiobject -class IIsApplicationPool -namespace
    >>>>> "root\MicrosoftIISv2" -computer $computer | foreach-object
    >>>>> {$_.name}
    >>>>> -----
    >>>>> Shay Levi
    >>>>> $cript Fanatic
    >>>>> http://scriptolog.blogspot.com
    >>>>>> If you know the application pool name (the function returns
    >>>>>> true/false respectively:
    >>>>>>
    >>>>>> function Recycle-AppPool{
    >>>>>> param([string]$server,[string]$appPool)
    >>>>>> ([WMI]"\\$server\root\MicrosoftIISv2:IIsApplicationPool.Name='W3S
    >>>>>> V
    >>>>>> C/
    >>>>>> A
    >>>>>> ppPools/$appPool'").recycle();
    >>>>>> if($? -ne 0}{$false} else {$true}
    >>>>>> }
    >>>>>> To get a list of application pool names:
    >>>>>> $computer = "your Server name/ip"
    >>>>>> gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    >>>>>> -computer
    >>>>>> $computer | % {$_.name}
    >>>>>> -----
    >>>>>> Shay Levi
    >>>>>> $cript Fanatic
    >>>>>> http://scriptolog.blogspot.com
    >>>>>>> I'm having some trouble finding the best method for recycling
    >>>>>>> remote IIS6 application pools using PowerShell.
    >>>>>>>
    >>>>>>> In the past this has always been very easy using VB script:
    >>>>>>>
    >>>>>>> Function PoolRecycle(strServer)
    >>>>>>>
    >>>>>>> On Error Resume Next
    >>>>>>> Err.Clear
    >>>>>>> Dim objWMIService
    >>>>>>> Dim colItems
    >>>>>>> Dim objItem
    >>>>>>> 'recycle application pool
    >>>>>>> WScript.Echo ""
    >>>>>>> Err.Clear
    >>>>>>> Set objWMIService = GetObject _
    >>>>>>> ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
    >>>>>>> & strServer & "\root\microsoftiisv2")
    >>>>>>> 'connect to WMI
    >>>>>>> Set colItems = objWMIService.ExecQuery("Select * From
    >>>>>>> IIsApplicationPool")
    >>>>>>> 'Step through the objects to be recycled
    >>>>>>> For each objItem in colItems
    >>>>>>> objItem.Recycle
    >>>>>>> If err = 0 Then
    >>>>>>> WScript.Echo(strServer & " - " & ObjItem.Name & " Recycled")
    >>>>>>> PoolRecycle = "success"
    >>>>>>> Else
    >>>>>>> WScript.Echo("Unable to recycle the application pool on " &
    >>>>>>> strServer)
    >>>>>>> PoolRecycle = "failed"
    >>>>>>> End If
    >>>>>>> Next
    >>>>>>> End Function
    >>>>>>> I have attempted to duplicate the same thing in PowerShell, but
    >>>>>>> I
    >>>>>>> believe I am still running into an issue with the pktPrivacy
    >>>>>>> authentication setting. The following code works when executing
    >>>>>>> localy, but not on a remote host:
    >>>>>>> Function PoolRecycle($strServerName)
    >>>>>>> {
    >>>>>>> $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    >>>>>>> $objWMI.Scope.Path = "\\" + $strServerName +
    >>>>>>> "\root\microsoftiisv2"
    >>>>>>> $objWMI.Scope.Options.Authentication = 6
    >>>>>>> $pools = $objWMI.Get()
    >>>>>>> foreach ($pool in $pools)
    >>>>>>> {
    >>>>>>> $pool.recycle()
    >>>>>>> if (!$?)
    >>>>>>> {
    >>>>>>> Write-Host $pool.name " - ERROR"
    >>>>>>> }
    >>>>>>> else
    >>>>>>> {
    >>>>>>> Write-Host $pool.name " - Recycled"
    >>>>>>> }
    >>>>>>> }
    >>>>>>> }
    >>>>>>> Any help or better ways of accomplishing this in PowerShell
    >>>>>>> would
    >>>>>>> be
    >>>>>>> very much appreciated!
    >>>>>>> Thanks
    >>>>>>> Bill

      My System SpecsSystem Spec

  9.    04 Nov 2007 #9
    Bill Guest

    Re: remote application pool recycle using WMI \ PowerShell


    Hi Shay,

    Yeah, I can list the pools, but only after specifing the authentication
    setting.

    It's almost like it does not carry to the other objects.

    I appreciate the help.

    Thanks
    Bill


    "Shay Levi" wrote:

    > Bill
    >
    > Just to clarify, I'm not able to recycle remote app pools, just list their
    > names (Access denied).
    > Even adding full security on IIsApplicationPool (WMI Properties) didn't resolve
    > it.
    > I'm still on it...
    >
    > -----
    > Shay Levi
    > $cript Fanatic
    > http://scriptolog.blogspot.com
    >
    >
    >

    > > Are you able to list the Application poll names?
    > >
    > > $server="server"
    > > $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    > > $objWMI.Scope.Path = "\\$server\root\microsoftiisv2"
    > > $objWMI.Scope.Options.Authentication =
    > > [System.Management.AuthenticationLevel]::PacketPrivacy
    > > $pools = $objWMI.Get()
    > > $pools | foreach { $_.name }
    > > -----
    > > Shay Levi
    > > $cript Fanatic
    > > http://scriptolog.blogspot.com

    > >> Hi Shay,
    > >>
    > >> I have tested this and it still does not resolve the issue.
    > >>
    > >> I guess I must be missing something. The fact that the VB Script
    > >> works and the PowerShell does not, leads me to believe that I have an
    > >> issue with my script and not the security on the target server.
    > >>
    > >> I may have to use PowerShell to call the actual .Net class instead of
    > >> using the built in commands.
    > >>
    > >> Funny, I would have never believed that something as simple as
    > >> recycling a remote application pool would be so hard
    > >>
    > >> Thanks again for the help.
    > >> Bill
    > >> "Shay Levi" wrote:
    > >>> Bill
    > >>>
    > >>> I can't test it right now. Try this on the remote server(s
    > >>>
    > >>> 1. Start > Run > dcomcnfg > ENTER
    > >>> 2. In the left pane (Compnent Services.msc) expand "Component
    > >>> Services" >
    > >>> Computers
    > >>> 3. Right click "My Computer"
    > >>> 4. In the "Default Properties" tab tick the "Enable COM Internet
    > >>> Services
    > >>> on this computer" checkbox
    > >>> 5. Reboot remote server
    > >>> 6. Test again
    > >>> I can't recall if you need to add Access Permissions in the "COM
    > >>> Security" tab.
    > >>> -----
    > >>> Shay Levi
    > >>> $cript Fanatic
    > >>> http://scriptolog.blogspot.com
    > >>>> Shay,
    > >>>>
    > >>>> Thanks for the help, but I see the namespace "root\MicrosoftIISv2"
    > >>>> operate differently when attempting to access it on a remote IIS6
    > >>>> computer (default W2K3 installs).
    > >>>>
    > >>>> The code examples you pointed out all work fine when targeting the
    > >>>> namespace locally, but I recieve access denied messages when useing
    > >>>> the same commands remotely.
    > >>>>
    > >>>> I have tried from multiple machines to multiple servers. The VB
    > >>>> Script I supplied still works in all cases, which leads me to
    > >>>> believe I am not setting the PowerShell WMI object authentication
    > >>>> to use pktPrivacy correctly.
    > >>>>
    > >>>> Any advice would be appreciated.
    > >>>>
    > >>>> Thanks
    > >>>> Bill
    > >>>> "Shay Levi" wrote:
    > >>>>> Pinging the remote machine before trying to recycle pools is a
    > >>>>> recommended practice.
    > >>>>>
    > >>>>> Also, I wrote:
    > >>>>>
    > >>>>> gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    > >>>>> -computer $computer | % {$_.name}
    > >>>>>
    > >>>>> for those who are not familiar with gwmi and %, I should say that
    > >>>>> they are
    > >>>>> aliases for:
    > >>>>> gwmi = get-wmiobject
    > >>>>> % = foreach-object
    > >>>>> I should have written it like:
    > >>>>> get-wmiobject -class IIsApplicationPool -namespace
    > >>>>> "root\MicrosoftIISv2" -computer $computer | foreach-object
    > >>>>> {$_.name}
    > >>>>> -----
    > >>>>> Shay Levi
    > >>>>> $cript Fanatic
    > >>>>> http://scriptolog.blogspot.com
    > >>>>>> If you know the application pool name (the function returns
    > >>>>>> true/false respectively:
    > >>>>>>
    > >>>>>> function Recycle-AppPool{
    > >>>>>> param([string]$server,[string]$appPool)
    > >>>>>> ([WMI]"\\$server\root\MicrosoftIISv2:IIsApplicationPool.Name='W3S
    > >>>>>> V
    > >>>>>> C/
    > >>>>>> A
    > >>>>>> ppPools/$appPool'").recycle();
    > >>>>>> if($? -ne 0}{$false} else {$true}
    > >>>>>> }
    > >>>>>> To get a list of application pool names:
    > >>>>>> $computer = "your Server name/ip"
    > >>>>>> gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    > >>>>>> -computer
    > >>>>>> $computer | % {$_.name}
    > >>>>>> -----
    > >>>>>> Shay Levi
    > >>>>>> $cript Fanatic
    > >>>>>> http://scriptolog.blogspot.com
    > >>>>>>> I'm having some trouble finding the best method for recycling
    > >>>>>>> remote IIS6 application pools using PowerShell.
    > >>>>>>>
    > >>>>>>> In the past this has always been very easy using VB script:
    > >>>>>>>
    > >>>>>>> Function PoolRecycle(strServer)
    > >>>>>>>
    > >>>>>>> On Error Resume Next
    > >>>>>>> Err.Clear
    > >>>>>>> Dim objWMIService
    > >>>>>>> Dim colItems
    > >>>>>>> Dim objItem
    > >>>>>>> 'recycle application pool
    > >>>>>>> WScript.Echo ""
    > >>>>>>> Err.Clear
    > >>>>>>> Set objWMIService = GetObject _
    > >>>>>>> ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
    > >>>>>>> & strServer & "\root\microsoftiisv2")
    > >>>>>>> 'connect to WMI
    > >>>>>>> Set colItems = objWMIService.ExecQuery("Select * From
    > >>>>>>> IIsApplicationPool")
    > >>>>>>> 'Step through the objects to be recycled
    > >>>>>>> For each objItem in colItems
    > >>>>>>> objItem.Recycle
    > >>>>>>> If err = 0 Then
    > >>>>>>> WScript.Echo(strServer & " - " & ObjItem.Name & " Recycled")
    > >>>>>>> PoolRecycle = "success"
    > >>>>>>> Else
    > >>>>>>> WScript.Echo("Unable to recycle the application pool on " &
    > >>>>>>> strServer)
    > >>>>>>> PoolRecycle = "failed"
    > >>>>>>> End If
    > >>>>>>> Next
    > >>>>>>> End Function
    > >>>>>>> I have attempted to duplicate the same thing in PowerShell, but
    > >>>>>>> I
    > >>>>>>> believe I am still running into an issue with the pktPrivacy
    > >>>>>>> authentication setting. The following code works when executing
    > >>>>>>> localy, but not on a remote host:
    > >>>>>>> Function PoolRecycle($strServerName)
    > >>>>>>> {
    > >>>>>>> $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    > >>>>>>> $objWMI.Scope.Path = "\\" + $strServerName +
    > >>>>>>> "\root\microsoftiisv2"
    > >>>>>>> $objWMI.Scope.Options.Authentication = 6
    > >>>>>>> $pools = $objWMI.Get()
    > >>>>>>> foreach ($pool in $pools)
    > >>>>>>> {
    > >>>>>>> $pool.recycle()
    > >>>>>>> if (!$?)
    > >>>>>>> {
    > >>>>>>> Write-Host $pool.name " - ERROR"
    > >>>>>>> }
    > >>>>>>> else
    > >>>>>>> {
    > >>>>>>> Write-Host $pool.name " - Recycled"
    > >>>>>>> }
    > >>>>>>> }
    > >>>>>>> }
    > >>>>>>> Any help or better ways of accomplishing this in PowerShell
    > >>>>>>> would
    > >>>>>>> be
    > >>>>>>> very much appreciated!
    > >>>>>>> Thanks
    > >>>>>>> Bill
    >
    >
    >
      My System SpecsSystem Spec

  10.    04 Nov 2007 #10
    Shay Levi Guest

    Re: remote application pool recycle using WMI \ PowerShell


    I'll keep looking for it :-)

    -----
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com



    > Hi Shay,
    >
    > Yeah, I can list the pools, but only after specifing the
    > authentication setting.
    >
    > It's almost like it does not carry to the other objects.
    >
    > I appreciate the help.
    >
    > Thanks
    > Bill
    > "Shay Levi" wrote:
    >

    >> Bill
    >>
    >> Just to clarify, I'm not able to recycle remote app pools, just list
    >> their
    >> names (Access denied).
    >> Even adding full security on IIsApplicationPool (WMI Properties)
    >> didn't resolve
    >> it.
    >> I'm still on it...
    >> -----
    >> Shay Levi
    >> $cript Fanatic
    >> http://scriptolog.blogspot.com

    >>> Are you able to list the Application poll names?
    >>>
    >>> $server="server"
    >>> $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    >>> $objWMI.Scope.Path = "\\$server\root\microsoftiisv2"
    >>> $objWMI.Scope.Options.Authentication =
    >>> [System.Management.AuthenticationLevel]::PacketPrivacy
    >>> $pools = $objWMI.Get()
    >>> $pools | foreach { $_.name }
    >>> -----
    >>> Shay Levi
    >>> $cript Fanatic
    >>> http://scriptolog.blogspot.com
    >>>> Hi Shay,
    >>>>
    >>>> I have tested this and it still does not resolve the issue.
    >>>>
    >>>> I guess I must be missing something. The fact that the VB Script
    >>>> works and the PowerShell does not, leads me to believe that I have
    >>>> an issue with my script and not the security on the target server.
    >>>>
    >>>> I may have to use PowerShell to call the actual .Net class instead
    >>>> of using the built in commands.
    >>>>
    >>>> Funny, I would have never believed that something as simple as
    >>>> recycling a remote application pool would be so hard
    >>>>
    >>>> Thanks again for the help.
    >>>> Bill
    >>>> "Shay Levi" wrote:
    >>>>> Bill
    >>>>>
    >>>>> I can't test it right now. Try this on the remote server(s
    >>>>>
    >>>>> 1. Start > Run > dcomcnfg > ENTER
    >>>>> 2. In the left pane (Compnent Services.msc) expand "Component
    >>>>> Services" >
    >>>>> Computers
    >>>>> 3. Right click "My Computer"
    >>>>> 4. In the "Default Properties" tab tick the "Enable COM Internet
    >>>>> Services
    >>>>> on this computer" checkbox
    >>>>> 5. Reboot remote server
    >>>>> 6. Test again
    >>>>> I can't recall if you need to add Access Permissions in the "COM
    >>>>> Security" tab.
    >>>>> -----
    >>>>> Shay Levi
    >>>>> $cript Fanatic
    >>>>> http://scriptolog.blogspot.com
    >>>>>> Shay,
    >>>>>>
    >>>>>> Thanks for the help, but I see the namespace
    >>>>>> "root\MicrosoftIISv2" operate differently when attempting to
    >>>>>> access it on a remote IIS6 computer (default W2K3 installs).
    >>>>>>
    >>>>>> The code examples you pointed out all work fine when targeting
    >>>>>> the namespace locally, but I recieve access denied messages when
    >>>>>> useing the same commands remotely.
    >>>>>>
    >>>>>> I have tried from multiple machines to multiple servers. The VB
    >>>>>> Script I supplied still works in all cases, which leads me to
    >>>>>> believe I am not setting the PowerShell WMI object authentication
    >>>>>> to use pktPrivacy correctly.
    >>>>>>
    >>>>>> Any advice would be appreciated.
    >>>>>>
    >>>>>> Thanks
    >>>>>> Bill
    >>>>>> "Shay Levi" wrote:
    >>>>>>> Pinging the remote machine before trying to recycle pools is a
    >>>>>>> recommended practice.
    >>>>>>>
    >>>>>>> Also, I wrote:
    >>>>>>>
    >>>>>>> gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    >>>>>>> -computer $computer | % {$_.name}
    >>>>>>>
    >>>>>>> for those who are not familiar with gwmi and %, I should say
    >>>>>>> that
    >>>>>>> they are
    >>>>>>> aliases for:
    >>>>>>> gwmi = get-wmiobject
    >>>>>>> % = foreach-object
    >>>>>>> I should have written it like:
    >>>>>>> get-wmiobject -class IIsApplicationPool -namespace
    >>>>>>> "root\MicrosoftIISv2" -computer $computer | foreach-object
    >>>>>>> {$_.name}
    >>>>>>> -----
    >>>>>>> Shay Levi
    >>>>>>> $cript Fanatic
    >>>>>>> http://scriptolog.blogspot.com
    >>>>>>>> If you know the application pool name (the function returns
    >>>>>>>> true/false respectively:
    >>>>>>>>
    >>>>>>>> function Recycle-AppPool{
    >>>>>>>> param([string]$server,[string]$appPool)
    >>>>>>>> ([WMI]"\\$server\root\MicrosoftIISv2:IIsApplicationPool.Name='W
    >>>>>>>> 3S
    >>>>>>>> V
    >>>>>>>> C/
    >>>>>>>> A
    >>>>>>>> ppPools/$appPool'").recycle();
    >>>>>>>> if($? -ne 0}{$false} else {$true}
    >>>>>>>> }
    >>>>>>>> To get a list of application pool names:
    >>>>>>>> $computer = "your Server name/ip"
    >>>>>>>> gwmi -class IIsApplicationPool -namespace "root\MicrosoftIISv2"
    >>>>>>>> -computer
    >>>>>>>> $computer | % {$_.name}
    >>>>>>>> -----
    >>>>>>>> Shay Levi
    >>>>>>>> $cript Fanatic
    >>>>>>>> http://scriptolog.blogspot.com
    >>>>>>>>> I'm having some trouble finding the best method for recycling
    >>>>>>>>> remote IIS6 application pools using PowerShell.
    >>>>>>>>>
    >>>>>>>>> In the past this has always been very easy using VB script:
    >>>>>>>>>
    >>>>>>>>> Function PoolRecycle(strServer)
    >>>>>>>>>
    >>>>>>>>> On Error Resume Next
    >>>>>>>>> Err.Clear
    >>>>>>>>> Dim objWMIService
    >>>>>>>>> Dim colItems
    >>>>>>>>> Dim objItem
    >>>>>>>>> 'recycle application pool
    >>>>>>>>> WScript.Echo ""
    >>>>>>>>> Err.Clear
    >>>>>>>>> Set objWMIService = GetObject _
    >>>>>>>>> ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
    >>>>>>>>> & strServer & "\root\microsoftiisv2")
    >>>>>>>>> 'connect to WMI
    >>>>>>>>> Set colItems = objWMIService.ExecQuery("Select * From
    >>>>>>>>> IIsApplicationPool")
    >>>>>>>>> 'Step through the objects to be recycled
    >>>>>>>>> For each objItem in colItems
    >>>>>>>>> objItem.Recycle
    >>>>>>>>> If err = 0 Then
    >>>>>>>>> WScript.Echo(strServer & " - " & ObjItem.Name & " Recycled")
    >>>>>>>>> PoolRecycle = "success"
    >>>>>>>>> Else
    >>>>>>>>> WScript.Echo("Unable to recycle the application pool on " &
    >>>>>>>>> strServer)
    >>>>>>>>> PoolRecycle = "failed"
    >>>>>>>>> End If
    >>>>>>>>> Next
    >>>>>>>>> End Function
    >>>>>>>>> I have attempted to duplicate the same thing in PowerShell,
    >>>>>>>>> but
    >>>>>>>>> I
    >>>>>>>>> believe I am still running into an issue with the pktPrivacy
    >>>>>>>>> authentication setting. The following code works when
    >>>>>>>>> executing
    >>>>>>>>> localy, but not on a remote host:
    >>>>>>>>> Function PoolRecycle($strServerName)
    >>>>>>>>> {
    >>>>>>>>> $objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
    >>>>>>>>> $objWMI.Scope.Path = "\\" + $strServerName +
    >>>>>>>>> "\root\microsoftiisv2"
    >>>>>>>>> $objWMI.Scope.Options.Authentication = 6
    >>>>>>>>> $pools = $objWMI.Get()
    >>>>>>>>> foreach ($pool in $pools)
    >>>>>>>>> {
    >>>>>>>>> $pool.recycle()
    >>>>>>>>> if (!$?)
    >>>>>>>>> {
    >>>>>>>>> Write-Host $pool.name " - ERROR"
    >>>>>>>>> }
    >>>>>>>>> else
    >>>>>>>>> {
    >>>>>>>>> Write-Host $pool.name " - Recycled"
    >>>>>>>>> }
    >>>>>>>>> }
    >>>>>>>>> }
    >>>>>>>>> Any help or better ways of accomplishing this in PowerShell
    >>>>>>>>> would
    >>>>>>>>> be
    >>>>>>>>> very much appreciated!
    >>>>>>>>> Thanks
    >>>>>>>>> Bill

      My System SpecsSystem Spec

Page 1 of 3 123 LastLast
remote application pool recycle using WMI \ PowerShell

Similar Threads
Thread Forum
Remote Application
I recently installed Vista Business 64 on my laptop. I had been using XP Pro (32). I have a Terminal Server that I have set up in Remote...
Vista networking & sharing
Looking for a free remote desktop application
I am looking for a free remote desktop application. Here is what I want to be able to do: 1) Be able to access my home computer from any...
Vista General
Re: Remote Development of VB.NET Application
The impersonation needs to be implemented by the programmer in the application itself. The programmer must be provided with the correct username...
.NET General
RE: How do you run a One-Click application from PowerShell
RickB, How do you supply an argument for this application if you do not use the "Open file" dialog box? Do the users interact with this...
PowerShell
How to install an application using PowerShell
I was not able to find anything on this on the Internet, which surprised me since I would have figured it would be a common task, but anyways, I...
PowerShell
Uninstall an application using Powershell
Hello, guys, Can I uninstall an application installed on my WindowsXP machine using powershell? And how can I do it? Thanks very much. Bob
PowerShell
Creating an IIS7 application with PowerShell
I seem to be stuck trying to create a new IIS application using WMI and PowerShell. Based on code generated from WMIExplorer, I created the...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 15:34.
    .