Publish all Projects in #ProjectServer using #PowerShell #MSProject #PS2010 #SP2010

January 23, 2012 at 5:51 pm | Posted in Add-on, Administration, Configuration, Functionality, PowerShell, PSI | 12 Comments
Tags: , ,

A frequent request from Project Server Administrators is how can I publish all projects on the server to ensure that the reports are current. This is where PowerShell comes in very handy again. Below is the PowerShell script that will publish all project plans in the server.

$svcPSProxy = New-WebServiceProxy -uri "http://vm353/pwatest/_vti_bin/PSI/Project.asmx?wsdl" -useDefaultCredential
$ProjectList = $svcPSProxy.ReadProjectList().Project | Where-Object { $_.PROJ_TYPE -ne 1 } | format-table proj_uid -hidetableheaders | out-string -stream
foreach ($projectUid in $projectList)
{
    if ($projectUid -ne "")
    {
$G = [System.Guid]::NewGuid()
$svcPSProxy.QueuePublish("$G", $projectUid, "true","")}}

This script can be run on demand or scheduled. To schedule this to run on a nightly / weekly basis use the Windows Task Scheduler. Create a new batch file to execute the PowerShell script from the scheduled task. An example of the command need in the batch file can be seen below:

"%SYSTEMROOT%\system32\windowspowershell\v1.0\powershell.exe" -command "& ‘C:\PublishAllProjects.ps1’"

Set the scheduled task to run under the PWA administrator account.

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

January 17, 2012 at 7:53 pm | Posted in Configuration, Customisation, Functionality, PowerShell, PSI | 6 Comments
Tags: , , ,

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!

#ProjectServer 2010 PSI #PowerShell examples #PS2010 #MSProject #SP2010

January 12, 2012 at 10:03 pm | Posted in Customisation, Functionality, PowerShell, PSI | 9 Comments
Tags: , , ,

Following from a post I wrote mid last year on Project Server data export using the PSI and PowerShell I thought I would create a new post to show further simple examples of getting Project data via the PSI using PowerShell (no coding!).

Firstly I will just explain each part of a simple script using the example below:

The first line adds the PWA instance URL to the pwaUrl variable:

$pwaUrl = “http://vm353/pwatest”

The second line concatenates the PWA URL (stored in the pwaUrl variable) and the web service URL and adds both of these to the svcPSUrl variable:

$svcPSUrl = $pwaUrl + "/_vti_bin/PSI/Project.asmx?wsdl"

The next line calls the Get-Credential cmdlet to specify a user name and password and adds the credentials to the c variable:

$c = Get-Credential

The fourth line creates the new web service proxy with the PWA web service URL and the credentials previously entered and adds these details to the svcPSProxy variable:

$svcPSProxy = New-WebServiceProxy -uri $svcPSUrl -credential $c

The last line is used to access and query the web service, the web service details are stored in the svcPSProxy variable, then the ReadProjectList method is called to access the Project details specified in the select statement using the Project property of the ProjectDataSet class:

$svcPSProxy.ReadProjectList().Project | Select Proj_name, Proj_UID, Proj_Type

A shorter version of the same query can be seen below:

$svcPSProxy = New-WebServiceProxy -uri "http://vm353/pwatest/_vti_bin/PSI/Project.asmx?wsdl" -useDefaultCredential
$svcPSProxy.ReadProjectList().Project | Select Proj_name, Proj_UID, Proj_Type

The script above does exactly the same but is structured differently. The PWA web service URL is added directly to the New-WebServiceProxy object and this query will pass through the logged on users credentials rather than having to enter a user name and password by specifying the useDefaultCredential property.

Below are some simple examples.

Read all users and export to a CSV file:

$pwaUrl = "http://vm353/pwatest"
$PSsvcUrl = $pwaUrl + "/_vti_bin/PSI/Resource.asmx?wsdl"
$c = Get-Credential
$svcPSProxy = New-WebServiceProxy -uri $PSsvcUrl -credential $c
$svcPSProxy.ReadUserList("ALL").Resources | Export-CSV C:\Resources.txt -Delimiter "|"

To read a specific resource us the ReadResource method and pass the res_UID to the resourceUID parameter:

$svcPSProxy.ReadResource("2B8767C3-DE3E-4343-8E51-B268697FB10F").Resources

Read Project Team:

$pwaUrl = "http://vm353/pwatest"
$svcProjectUrl = $pwaUrl + "/_vti_bin/PSI/Project.asmx?wsdl"
$c = Get-Credential
$svcProjectProxy = New-WebServiceProxy -uri $svcProjectUrl -credential $c
$svcProjectProxy.ReadProjectTeam("3DC95F6F-60C4-48CB-8DA0-AA28DA6E31FD").ProjectTeam
–will return all fields in the ProjectTeam dataset for the given project  GUID.

To return specified fields add the select command:

$svcProjectProxy.ReadProjectTeam("3DC95F6F-60C4-48CB-8DA0-AA28DA6E31FD").ProjectTeam | Select res_UID, Res_Name — will select limited fields from the dataset, in this case Resource UID and Resource Name.

It is also possible to run certain jobs from PowerShell, in the example below the archive projects job will run when the script is executed:

$pwaUrl = "http://vm353/pwatest"
$svcProjectUrl = $pwaUrl + "/_vti_bin/PSI/Archive.asmx?wsdl"
$c = Get-Credential
$svcProjectProxy = New-WebServiceProxy -uri $svcProjectUrl -credential $c
$svcProjectProxy.QueueArchiveProjects()

The following script will synchronise the PWA users and the SharePoint site membership:

$pwa = "http://vm353/pwatest"
$svcPSUrl = $pwa + "/_vti_bin/PSI/WssInterop.asmx?wsdl"
$c = Get-Credential
$svcPSProxy = New-WebServiceProxy -uri $svcPSUrl -credential $c
$svcPSProxy.SynchronizeMembershipForPwaAppRootSite()

These are just a few simple examples to show how quickly you can access the PSI with no code and not touching Visual Studio!

Details on the Project Server 2010 PSI can be found here:

http://msdn.microsoft.com/en-us/library/ms457477.aspx

Details on PowerShell can be found here:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa973757(v=vs.85).aspx

Create a free website or blog at WordPress.com.
Entries and comments feeds.