locked
How to Import Webadministration Module on Remote Command RRS feed

  • Question

  • User-277966266 posted

    Question about how to import modules on a remote server. I'm trying to remotely stop an IIS website with the following command but it doesnt seem to work (although it doesnt report an error either).

    powershell -command "icm hydrogen {import-module webadministration | stop-webitem iis:\sites\mysite}"

    Any thought on why this doesnt work?

    CT

    Monday, December 21, 2009 11:13 PM

Answers

  • User-277966266 posted

    I "resolved" this issue by working around it. I gave up on using the Powershell IIS7 cmdlets and switched to use appcmd. It's a far easier and more flexible solution as it allows you to use ANY command. I'm using this for a TFS 2010 build and deployment workflow. You can see the full details here...

    http://www.tadlockenterprises.com/2009/12/remote-admin-iis-for-tfs-2010-builds/

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Thursday, December 24, 2009 3:35 PM
  • User-1088088894 posted
    Yep... That doesn't work for me either. Replace your pipe(|) with a semicolon (;) and it works: powershell -command "icm tome-mac {import-module webadministration; stop-webitem 'IIS:\Sites\Default Web Site'}" That works for me
    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, December 28, 2009 12:25 PM

All replies

  • User-277966266 posted

    I "resolved" this issue by working around it. I gave up on using the Powershell IIS7 cmdlets and switched to use appcmd. It's a far easier and more flexible solution as it allows you to use ANY command. I'm using this for a TFS 2010 build and deployment workflow. You can see the full details here...

    http://www.tadlockenterprises.com/2009/12/remote-admin-iis-for-tfs-2010-builds/

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Thursday, December 24, 2009 3:35 PM
  • User-1088088894 posted
    Yep... That doesn't work for me either. Replace your pipe(|) with a semicolon (;) and it works: powershell -command "icm tome-mac {import-module webadministration; stop-webitem 'IIS:\Sites\Default Web Site'}" That works for me
    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, December 28, 2009 12:25 PM
  • User-277966266 posted

     This command works perfectly for me; it also will print the textual result and return the exit code.

    powershell -noprofile -command “$x = icm DeploymentServer {c:\windows\system32\inetsrv\appcmd.exe stop site TestWebsite; $lastexitcode}; if ($x.length -gt 1){$x[0]}; exit $x[$x.length - 1]“

     I tested out your command; looks like it works. Nice work! I'm going to stick with mine though as it better suites my needs in that it allows me to execute any remote command.

     Thanks

    CT

     

    Monday, December 28, 2009 12:53 PM