header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

We have a new sponsor!  Introducting Pragma Systems.  See the home page for details.

Remote IIS 7 management
Last Post 15 Jul 2010 09:13 PM by 0ptikGhost. 23 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
07 Jun 2010 11:23 AM  
Hi,

I'm trying to stop an applicaion pool in IIS 7 remotely using PS v2.

I've installed the webadministration cmdlets, and can easily maintain IIS locally.  But, when I attempt to run anything remotely I recieve errors stating that the cmdlet I am running is not recognised - I have enabled PS Remoting, and can run other cmds on the machine using New-PSSession.

Can anyone point me in the right direction as to what I am doing wrong please?  Here is the part of the script I am working on at the moment.

[System.Reflection.Assembly]::LoadFrom( "C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll" )
$Session = New-PSSession -ComputerName 'QPROVA02'
Invoke-Command -Session $Session -ScriptBlock { import-module 'webAdministration'; Stop-WebAppPool 'manageUsers' }


thanks in advance.

Robbie.
Cruisader03User is Offline
Basic Member
Basic Member
Posts:245
Avatar

--
07 Jun 2010 03:12 PM  
You're loading the dll locally, but expecting to call it remotely. You'll need to load the dll in the remote session.

$Session = New-PSSession -ComputerName 'QPROVA02'

$block = {
[System.Reflection.Assembly]::LoadFrom( "C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll" )
import-module 'webAdministration'
Stop-WebAppPool 'manageUsers'
}

Invoke-Command -Session $Session -ScriptBlock $block
When at first you don't succeed Step-Into

http://theposherlife.blogspot.com
http://www.jandctravels.com

ShayUser is Offline
Veteran Member
Veteran Member
Posts:1140
Avatar

--
07 Jun 2010 03:29 PM  
You can remove the LoadFrom() call. The WebAdministration module loads all the necessary DLL's for you.

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter: @ShayLevy
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
08 Jun 2010 09:24 AM  
I tried both ideas, and got the same error.

Basically saying the start-webapppool is not a valid cmdlet.
ShayUser is Offline
Veteran Member
Veteran Member
Posts:1140
Avatar

--
08 Jun 2010 11:06 AM  
Try interactively:

Enter-PSSession QPROVA02
import-module webAdministration
Stop-WebApp[ PRESS TAB]

The command is tab completed?


Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter: @ShayLevy
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
08 Jun 2010 12:49 PM  
ok tried that...  Getting the same error.

Import-Module : The specified module 'webAdministration' was not loaded because
 no valid module file was found in any module directory.
    + CategoryInfo          : ResourceUnavailable: (webAdministration:String)
   [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
   ands.ImportModuleCommand

Then (obviously)

The term 'stop-webapppool' is not recognized as the name of a cmdlet, function,
 script file, or operable program. Check the spelling of the name, or if a path
 was included, verify that the path is correct and try again.
    + CategoryInfo          :
    + FullyQualifiedErrorId : CommandNotFoundException

What I have also tried is running the same cmds from the box itself, which has produced the same result.  Would that make any difference?  I didn't think it would as PS would just open another session over the network??

Perhaps re-installing the web admin cmdlets again??  I've ran out of knowledge / options now.
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
08 Jun 2010 12:59 PM  
But to answer your question...  No - Tabbing the cmd doesn't initialize the cmdlet.
ShayUser is Offline
Veteran Member
Veteran Member
Posts:1140
Avatar

--
08 Jun 2010 01:06 PM  
Do you get a result when you run the following inside the session:

Get-Module WebAdministration -ListAvailable

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter: @ShayLevy
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
08 Jun 2010 01:09 PM  
No
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
08 Jun 2010 01:09 PM  
PS C:\> get-module webadministration -listavailable
PS C:\>
ShayUser is Offline
Veteran Member
Veteran Member
Posts:1140
Avatar

--
08 Jun 2010 01:16 PM  
Then the webadministration module doesn't exist on the target.

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter: @ShayLevy
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
08 Jun 2010 01:21 PM  
I can use the cmdlets locally on it no problem... Is there a posibility they are named something else?

I am a little confused here as I can use the cmdlets - for example start / stop-webAppPool when I am on the server itself. It works perfectly.

Do you think removing them, and re-installing might offer some relief?
ShayUser is Offline
Veteran Member
Veteran Member
Posts:1140
Avatar

--
08 Jun 2010 01:28 PM  
How do you load the module when you're working locally on the server? 'gmo web* -list' returns the module?

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter: @ShayLevy
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
08 Jun 2010 01:39 PM  
It's quite odd...

ModuleType Name ExportedCommands
---------- ---- ----------------
Manifest BitsTransfer {}
Manifest PSDiagnostics {Enable-PSTrace, Enable-WSManTrace, Start-Trace, Disable-PSWSManCombined...


PS C:\Users\da-rdixon> start-webapppool manageusers
PS C:\Users\da-rdixon>

does this mean that the module is not loading? If so how can I run the cmd - i checked it in IIS GUI, and the app pool was definately started when it was stopped.
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
08 Jun 2010 01:41 PM  
I don't actually manually load the module, I open the powershell modules interface and that loads them for me.

I also tried the power gui from quest software to see if I could load the libraries through it, and it works fine too. Unless I try remote connection, which is my objective.
ShayUser is Offline
Veteran Member
Veteran Member
Posts:1140
Avatar

--
09 Jun 2010 09:45 AM  
What's the OS type on the remote server?

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter: @ShayLevy
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
09 Jun 2010 10:39 AM  
2008 64x...
ShayUser is Offline
Veteran Member
Veteran Member
Posts:1140
Avatar

--
09 Jun 2010 10:43 AM  
You need to install the IIS powershell provider:

http://www.iis.net/download/PowerShell


Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter: @ShayLevy
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
09 Jun 2010 02:44 PM  
I have this installed. I can run the cmdlets when I am on the server itself no problems at all.

I guess trying a re-install might work.
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
09 Jun 2010 03:05 PM  
I didn't work.
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
10 Jun 2010 12:26 PM  
Does the webadministration module need to be installed on the local server?

I mean, I only have it installed on the server I am connecting to then running the script against.
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
10 Jun 2010 01:55 PM  
FINALLY!!!
$Session = New-PSSession -ComputerName QPROVA02
Invoke-Command -Session $Session -ScriptBlock { Add-PSSnapin webadministration ; start-webapppool manageusers }

Life is good!

Thanks for the aid Shay - I honestly didn't have a clue how to do it, but you pointed me in the right direction!

Rob :-)
ShayUser is Offline
Veteran Member
Veteran Member
Posts:1140
Avatar

--
10 Jun 2010 02:48 PM  
Awesome :)

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter: @ShayLevy
0ptikGhostUser is Offline
Basic Member
Basic Member
Posts:123
Avatar

--
15 Jul 2010 09:13 PM  
Posted By bobdee1980 on 08 Jun 2010 04:49 AM

Import-Module : The specified module 'webAdministration' was not loaded because
 no valid module file was found in any module directory.
    + CategoryInfo          : ResourceUnavailable: (webAdministration:String)
   [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
   ands.ImportModuleCommand

This error should have told you that the WebAdministration module is not installed on the remote server. I assume you eventually came to this conclusion but I wanted to point this out explicitly here in case somebody else runs into this issue.

EDIT: This should teach me to read all pages on a topic... The other posts already covered this...

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer