Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

Invoke-Command script needs imported module on remote end

$
0
0

I'm needing the cmdlet New-Website on the remote computers for the script I'm sending them via Invoke-Command.  The thing is, the WebAdministration module containing New-Website exists on all the remote machines I'm targeting, yet the script reports it does not recognize New-Website, I'm guessing because the remote machines need to first import the module.

I tried adding Import-Module WebAdministration at the beginning of my script block, and this seemed to work, but I got an error.  What is the best way to get the remote computers to access their installed module packs when sending them commands via Invoke-Command?

Here is how I was trying to make a website on a remote computer:

Invoke-Command -ComputerName SERVER -command {Import-module webadministration; New-Website -Name "testing site" -Port 80 -HostHeader "testing site" -PhysicalPath c:\TS}

When I do this, it does create the website, but the website is not started, and it gives me the following error:

Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))
    + CategoryInfo          : NotSpecified: (:) [New-Website], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.NewWebsite
   Command

Thank you for your help!

-Delton


Viewing all articles
Browse latest Browse all 8411