1

I'm trying to use PowerShell with web deployment based on this article

This is how my script looks like

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Deployment") 
function Sync-Provider($provider, $sourceLocation, $destLocation)  
{   
    $destBaseOptions   = new-object Microsoft.Web.Deployment.DeploymentBaseOptions   
    $syncOptions       = new-object Microsoft.Web.Deployment.DeploymentSyncOptions   
    Try  
    {  
      $deploymentObject =                [Microsoft.Web.Deployment.DeploymentManager]::CreateObject($provider, $sourceLocation)     
      $deploymentObject.SyncTo($provider,$destLocation,$destBaseOptions,$syncOptions)  
    }  
    Catch  
    {  
      echo "EXCEPTION THROWN::[ $_ ] "  
      #throw $_  
    }  
}  
Sync-Provider   ("apphostConfig","D:\NerdDinner_2.0\NerdDinner","c:\inetpub\wwwroot") 

Running this gives the following exception

EXCEPTION THROWN::[ Cannot convert argument "0", with value: "System.Object[]",
 for "CreateObject" to type "Microsoft.Web.Deployment.DeploymentWellKnownProvid
er": "Cannot convert value "apphostConfig,D:\NerdDinner_2.0\Ne
rdDinner,c:\inetpub\wwwroot" to type "Microsoft.Web.Deployment.DeploymentWellKn
ownProvider" due to invalid enumeration values. Specify one of the following en
umeration values and try again. The possible enumeration values are "Unknown, A
ppHostConfig, AppHostSchema, AppPoolConfig, ArchiveDir, Auto, Cert, ComObject32
, ComObject64, ContentPath, CreateApp, DirPath, DBFullSql, DBMySql, FilePath, G
acAssembly, IisApp, MachineConfig32, MachineConfig64, Manifest, MetaKey, Packag
e, RecycleApp, RegKey, RegValue, RootWebConfig32, RootWebConfig64, RunCommand, 
SetAcl, WebServer, WebServer60"." ] 

Could you give me some hints on this, please?

2 Answers 2

1

Try to enclose the first parameter [Microsoft.Web.Deployment]::DeploymentWellKnownProvider.AppHostConfig with a pair of extra parenthesis: ([Microsoft.Web.Deployment]::DeploymentWellKnownProvider.AppHostConfig).

Sign up to request clarification or add additional context in comments.

3 Comments

Hmm, perhaps the question was edited and my answer is not relevant anymore. There is "apphostConfig" now in the code. It's a good idea, too. Now you have to remove parens and commas and call your function like this: Sync-Provider "apphostConfig" "D:\NerdDinner_2.0\NerdDinner" "c:\inetpub\wwwroot"
However, I have another error. EXCEPTION THROWN::[ Exception calling "CreateObject" with "2" argument(s): "Obj ect of type 'appHostConfig' and path 'D:\NerdDinner_2.0\NerdDi nner' cannot be created." ]. Any ideas? Thank you
I think that wrong CreateObject(string, string) is called because now you pass strings in. Restore the original version with the enum parameter and try again.
1

In my case I had the same problem, just opened the powershell console as Administrator and it worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.