none
Powershell script to add tasks to projects MS Project Server 2013 RRS feed

  • Question

  • We have about about 600 new projects that were set up and now they PMO wants to have a number of tasks added to each project (The total will be 2500 tasks and will vary from project to project) So we need to:

    Read a text file with the project GUID, Task name, duration, start date, end date, duration (all are milestones)

    Create the tasks at the bottom of the project schedule Preferably as a sub task

    I have not seen a  script to do this for 2013. 


    Tasks



    • Edited by Bob Leake Wednesday, January 14, 2015 8:35 PM
    Wednesday, January 14, 2015 7:24 PM

Answers

  • So I did come up with a solution. This is based on Jim E. Cox's script to create multiple projects with random tasks. So I want to ensure there is credit given.  

    I was able to create 3,000 total tasks on 600 projects in just about 60 minutes

    You will need to change the path to the CSV and you will need to change the URL. Of course you can change anything else you need.  

    In this script you read from a MSDOS CSV file and it contains 2 columns (Could contain more.) Column 1 is the project name and column 2 is the task name.  Note that column 1 will repeat the same project until a new project name is encountered as follows:

    Project 1: task1

    Project 1: task 2 

    Project 2; task 1

    Etc. 

    The Script will create one Summary task per project and then all the other tasks are sub tasks. 

    Here is the script:

    cls  

    #Lets open the CSV (CSV is faser than Excel) 
    $TaskList = Import-CSV "C:\test.csv"
    $PriorProjGUID = ""

    FOREACH ($Task in $TaskList) 
    {
      
        # Get the project GUID from the file. "ProjectGUID" is the header name of the column in the CSV File
        # And we will grab the task name as well since we are here
        $ProjGUID = $Task.ProjectGUID
        $TaskName = $Task.TaskName 
        # Lets do this while the project is the same
        If ($ProjGUID -ne $PriorProjGUID) 
        {
         #let's save, publish and checkin the project if there is a new one in the list 
          If ($PriorProjGUID -ne "")
            {
                # Add the above dataset to project and publish and check in 
                $ProjSvcProxy.QueueAddToProject($NewJobGuid, $SessionGUID, $ProjDataSet, $false); 
                $ProjSvcProxy.QueuePublish($NewJobGuid, $PriorProjGuid, "true","") 
             ## Start-sleep 20 
                $ProjSvcProxy.QueueCheckInProject($NewJobGuid, $PriorProjGuid, $false, $SessionGuid, $SessionDescr); 
             }  
                
          #Let's set the project name to the prior projct name so we can track our loop
           $PriorProjGUID = $ProjGUID  
              
                  
          # we will open the project in this seciton first we have to set session variables and the like 
            # Set our variables 
            $SessionGuid = [System.Guid]::NewGuid() 
            $SessionDescr = "Add tasks session"  
            #$NewJobGuid = [System.Guid]::NewGuid() 
            $EPMTYGUID = [system.guid]::empty 
            $PWAUrl = “http://msps.itcs.URL.com/pwa” 
            
                    
            # initiate the PSI Web Services 
            #Project Web Service 
            $ProjSvcURL = $PWAUrl + "/_vti_bin/PSI/Project.asmx?wsdl" 
            $ProjSvcProxy = New-WebServiceProxy -uri $ProjSvcURL -useDefaultCredential #-credential $Credential 
            $QSvcUrl = $pwaUrl + "/_vti_bin/PSI/QueueSystem.asmx?wsdl" 
            $QSvcProxy = New-WebServiceProxy -uri $QSvcUrl -useDefaultCredential #-credential $Credential 
             
            # Now let's check the project out 
             $ProjSvcProxy.CheckOutProject("$ProjGuid", $sessionGuid, $SessionDescr); 

            #give it a chance to check out 
            ##Start-sleep 30 

            # Add tasks.  
             $ProjDataset = New-Object Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1_vti_bin_PSI_Project_asmx_wsdl.ProjectDataSet  
              
               #create a summary task
                 $NewTaskGuid = [System.Guid]::NewGuid() 
                 $NewTaskRow1 = $ProjDataSet.Task.NewTaskRow(); 
                 $NewTaskRow1.PROJ_UID = $ProjGuid; 
                 $NewTaskRow1.TASK_UID = $NewTaskGuid; 
                 $NewTaskRow1.Task_IS_SUMMARY = 1;
                 $NewTaskRow1.Task_OUTLINE_LEVEL = 1;
                 $NewTaskRow1.TASK_DUR_FMT = 53;
                 $NewTaskRow1.TASK_NAME = "EPR-ID: Asset Tasks";
                 $NewTaskRow1.Task_DUR_IS_EST = 1;
               $ProjDataSet.Task.AddTaskRow($NewTaskRow1); 
               
               
          }

        
                           
         $NewTaskGuid = [System.Guid]::NewGuid() 
         $NewTaskRow1 = $ProjDataSet.Task.NewTaskRow(); 
         $NewTaskRow1.PROJ_UID = $ProjGuid; 
         $NewTaskRow1.TASK_UID = $NewTaskGuid 
         $NewTaskRow1.TASK_DUR_FMT = 53; 
         $NewTaskRow1.TASK_DUR = 0;   
         $NewTaskRow1.TASK_NAME = $TaskName; 
         $NewTaskRow1.Task_OUTLINE_LEVEL = 2;
         $NewTaskRow1.TASK_START_DATE = '8/1/2015' #[datetime]::Now; 
         $ProjDataSet.Task.AddTaskRow($NewTaskRow1); 
            
                     
     }  
                
    #Check in the last project
        # Add the above dataset to project and publish and check in 
        $ProjSvcProxy.QueueAddToProject($NewJobGuid, $SessionGUID, $ProjDataSet, $false); 
        $ProjSvcProxy.QueuePublish($NewJobGuid, $ProjGuid, "true","") 
      #  Start-sleep 5 
        $ProjSvcProxy.QueueCheckInProject($NewJobGuid, $ProjGuid, $false, $SessionGuid, $SessionDescr); 
      Echo "We are all Done but the Queue has to finish that will take some time"         


    Tasks


    • Marked as answer by Bob Leake Monday, January 19, 2015 5:50 PM
    • Edited by Bob Leake Monday, January 19, 2015 5:51 PM
    Monday, January 19, 2015 5:50 PM

All replies

  • Bob,

    I know that Task Level Operations are possible with PSI, but I am not sure if this can be done with PowerShell.

    An alternative approach could be to build templates, with tasks that you need in these projects, and then use powershell to create projects using these templates. Paul has a good powershell script to do this.

    https://pwmather.wordpress.com/2013/08/30/create-a-projectserver-ps2010-ps2013-project-from-a-template-and-update-the-ept-sp2013-sp2010-powershell/


    Cheers,

    Prasanna Adavi, Project MVP

    Blog:   Podcast:    Twitter:    LinkedIn:   

    Friday, January 16, 2015 1:30 PM
    Moderator
  • Hello,

    This PowerShell script below should help get you started:

    https://gallery.technet.microsoft.com/office/Create-projects-with-tasks-ae97329e

    It will show you how to work with the Project Data set and create new tasks.

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS | MVP | Downloads

    Friday, January 16, 2015 9:02 PM
    Moderator
  • So I did come up with a solution. This is based on Jim E. Cox's script to create multiple projects with random tasks. So I want to ensure there is credit given.  

    I was able to create 3,000 total tasks on 600 projects in just about 60 minutes

    You will need to change the path to the CSV and you will need to change the URL. Of course you can change anything else you need.  

    In this script you read from a MSDOS CSV file and it contains 2 columns (Could contain more.) Column 1 is the project name and column 2 is the task name.  Note that column 1 will repeat the same project until a new project name is encountered as follows:

    Project 1: task1

    Project 1: task 2 

    Project 2; task 1

    Etc. 

    The Script will create one Summary task per project and then all the other tasks are sub tasks. 

    Here is the script:

    cls  

    #Lets open the CSV (CSV is faser than Excel) 
    $TaskList = Import-CSV "C:\test.csv"
    $PriorProjGUID = ""

    FOREACH ($Task in $TaskList) 
    {
      
        # Get the project GUID from the file. "ProjectGUID" is the header name of the column in the CSV File
        # And we will grab the task name as well since we are here
        $ProjGUID = $Task.ProjectGUID
        $TaskName = $Task.TaskName 
        # Lets do this while the project is the same
        If ($ProjGUID -ne $PriorProjGUID) 
        {
         #let's save, publish and checkin the project if there is a new one in the list 
          If ($PriorProjGUID -ne "")
            {
                # Add the above dataset to project and publish and check in 
                $ProjSvcProxy.QueueAddToProject($NewJobGuid, $SessionGUID, $ProjDataSet, $false); 
                $ProjSvcProxy.QueuePublish($NewJobGuid, $PriorProjGuid, "true","") 
             ## Start-sleep 20 
                $ProjSvcProxy.QueueCheckInProject($NewJobGuid, $PriorProjGuid, $false, $SessionGuid, $SessionDescr); 
             }  
                
          #Let's set the project name to the prior projct name so we can track our loop
           $PriorProjGUID = $ProjGUID  
              
                  
          # we will open the project in this seciton first we have to set session variables and the like 
            # Set our variables 
            $SessionGuid = [System.Guid]::NewGuid() 
            $SessionDescr = "Add tasks session"  
            #$NewJobGuid = [System.Guid]::NewGuid() 
            $EPMTYGUID = [system.guid]::empty 
            $PWAUrl = “http://msps.itcs.URL.com/pwa” 
            
                    
            # initiate the PSI Web Services 
            #Project Web Service 
            $ProjSvcURL = $PWAUrl + "/_vti_bin/PSI/Project.asmx?wsdl" 
            $ProjSvcProxy = New-WebServiceProxy -uri $ProjSvcURL -useDefaultCredential #-credential $Credential 
            $QSvcUrl = $pwaUrl + "/_vti_bin/PSI/QueueSystem.asmx?wsdl" 
            $QSvcProxy = New-WebServiceProxy -uri $QSvcUrl -useDefaultCredential #-credential $Credential 
             
            # Now let's check the project out 
             $ProjSvcProxy.CheckOutProject("$ProjGuid", $sessionGuid, $SessionDescr); 

            #give it a chance to check out 
            ##Start-sleep 30 

            # Add tasks.  
             $ProjDataset = New-Object Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1_vti_bin_PSI_Project_asmx_wsdl.ProjectDataSet  
              
               #create a summary task
                 $NewTaskGuid = [System.Guid]::NewGuid() 
                 $NewTaskRow1 = $ProjDataSet.Task.NewTaskRow(); 
                 $NewTaskRow1.PROJ_UID = $ProjGuid; 
                 $NewTaskRow1.TASK_UID = $NewTaskGuid; 
                 $NewTaskRow1.Task_IS_SUMMARY = 1;
                 $NewTaskRow1.Task_OUTLINE_LEVEL = 1;
                 $NewTaskRow1.TASK_DUR_FMT = 53;
                 $NewTaskRow1.TASK_NAME = "EPR-ID: Asset Tasks";
                 $NewTaskRow1.Task_DUR_IS_EST = 1;
               $ProjDataSet.Task.AddTaskRow($NewTaskRow1); 
               
               
          }

        
                           
         $NewTaskGuid = [System.Guid]::NewGuid() 
         $NewTaskRow1 = $ProjDataSet.Task.NewTaskRow(); 
         $NewTaskRow1.PROJ_UID = $ProjGuid; 
         $NewTaskRow1.TASK_UID = $NewTaskGuid 
         $NewTaskRow1.TASK_DUR_FMT = 53; 
         $NewTaskRow1.TASK_DUR = 0;   
         $NewTaskRow1.TASK_NAME = $TaskName; 
         $NewTaskRow1.Task_OUTLINE_LEVEL = 2;
         $NewTaskRow1.TASK_START_DATE = '8/1/2015' #[datetime]::Now; 
         $ProjDataSet.Task.AddTaskRow($NewTaskRow1); 
            
                     
     }  
                
    #Check in the last project
        # Add the above dataset to project and publish and check in 
        $ProjSvcProxy.QueueAddToProject($NewJobGuid, $SessionGUID, $ProjDataSet, $false); 
        $ProjSvcProxy.QueuePublish($NewJobGuid, $ProjGuid, "true","") 
      #  Start-sleep 5 
        $ProjSvcProxy.QueueCheckInProject($NewJobGuid, $ProjGuid, $false, $SessionGuid, $SessionDescr); 
      Echo "We are all Done but the Queue has to finish that will take some time"         


    Tasks


    • Marked as answer by Bob Leake Monday, January 19, 2015 5:50 PM
    • Edited by Bob Leake Monday, January 19, 2015 5:51 PM
    Monday, January 19, 2015 5:50 PM