Create and publish a Project in #ProjectServer via #PowerShell #PS2010 #MSProject #SP2010

Following on from a recent post on Project Server PSI PowerShell scripts, I thought of a nice slightly more advanced example. The script below will create a new project using the specified project template.

$ProjName = Read-Host -Prompt "Enter the Name of the Project"
Write-host "The Project is called $ProjName"
$svcPSProxy = New-WebServiceProxy -uri "http://vm353/pwatest/_vti_bin/PSI/Project.asmx?wsdl" -useDefaultCredential
$NewProjGUID = $svcPSProxy.CreateProjectFromTemplate("01dbd28a-fcb6-4ccf-bb42-645982f48cf3", $ProjName)
$G = [System.Guid]::NewGuid()
$svcPSProxy = New-WebServiceProxy -uri "http://vm353/pwatest/_vti_bin/PSI/Project.asmx?wsdl" -useDefaultCredential
$svcPSProxy.QueuePublish("$G", $NewProjGUID, "true","")
Write-host "********* $ProjName has now been created *********"

Below is a walkthrough:

I have the script saved as CreateProject.ps1 on my desktop:

image

Hit Enter to execute the script:

image

You are prompted for the Project name, give the new Project a name and hit Enter:

image

A message will then appear with the chosen Project Name:

image

The script will then create a new project using the CreateProjectFromTemplate method with the project template and project name specified. In the next step it generates a new GUID ready to be used for the project publish job GUID. The script will then use the QueuePublish method and pass in the new GUID for the publish job, the GUID of the new project, specifies a full publish and creates a project site:

image

Now you can see the project in the Project Centre:

image

And the Project Site:

image

A basic example of creating a project with a 5 or 6 line PowerShell script!

6 thoughts on “Create and publish a Project in #ProjectServer via #PowerShell #PS2010 #MSProject #SP2010

  1. Hello Paul, thanks for posting this awesome script but I’m hoping you can help me understand what I may be doing wrong in getting this to work. When I run it, I get the following exception error:

    PS C:\> .\CreateProject.ps1
    Enter the Name of the Project: testProject120224
    The Project is called testProject120224
    Exception calling “CreateProjectFromTemplate” with “2” argument(s): “Unhandled Communication Fault occurred”
    At C:\CreateProject.ps1:4 char:53
    + $NewProjGUID = $svcPSProxy.CreateProjectFromTemplate <<<< ("09fa52b4-059b-4527-926e-99f9be96437a", $ProjName)
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

    Cannot convert argument "1", with value: "", for "QueuePublish" to type "System.Guid": "Cannot convert null to type "System.Guid"."
    At C:\CreateProject.ps1:7 char:25
    + $svcPSProxy.QueuePublish <<<< ("$G", $NewProjGUID, "true","")
    + CategoryInfo : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

    ********* testProject120224 has now been created *********

    I have tried this a few times, with different configurations, but with no success. Hopefully you can see what I may be doing wrong. Also just to point out, the guid used is of the Enterprise Project Type "Basic Project Plan." Other than this I am not sure what template to specify for the CreateProjectFromTemplate class. I can also get the $svcPSProxy.ReadProjectList().Project script to work so as far as I can tell, I do have things configured correctly.

    Any assistance on this would definitely be appreciated.

    Thanks,
    David

    1. Hi David,

      What Project Template GUID are you using, run this script below against the ProjectServer_Draft database and copy the template GUID from there:

      select Proj_Name
      , Proj_UID
      from MSP_Projects
      where Proj_type = 1

      Also, did you copy and paste the script from the post straight into PowerShell? If so it might be worth copying into notepad first then from notepad into the PowerShell editor in case of any encoding issues or delete and retype the (“)quotes.

      Thanks
      Paul

Comments are closed.

Create a free website or blog at WordPress.com.

Up ↑