Tuesday, August 23, 2016

Calling AgilePoint web services with PowerShell

AgilePoint has 2 main APIs that are really handy - Workflow.asmx and Admin.asmx. You could also access it via REST.
Today I'm going to show an example of how you could batch reassign tasks to users by making use of the workflow web service.

The services could be found here.
  • Workflow API - http://[qualified machine name]:[port]/[AgilePoint virtual directory]/workflow.asmx?WSDL
  • Administration API - http://[qualified machine name]:[port]/[AgilePoint virtual directory]/admin.asmx?WSDL

With PowerShell here is a very straightforward example of a classic web service that accepts simple data types.
Using a CSV file that contains user account mapping from DOMAIN1\user to NEWDOMAIN\user, first declare the variables you need. Here is a sample CSV

oldlogin,newlogin
DOMAIN1\user1,NEWDOMAIN\user1new
DOMAIN1\user2,NEWDOMAIN\user2new

 #****************************************************  
 # Variables  
 #****************************************************  
 $username = "DOMAIN\admin"  
 $password = "Password"  
 $wsWorkflowUrl = "http://agilepointserver:8000/AgilePointServer/Workflow.asmx?WSDL"  
 $wsAdminUrl = "http://agilepointserver:8000/AgilePointServer/Admin.asmx?WSDL"  
 $csvFile = "Users.csv"  


Then, create the credentials object and connect to the webservice. PowerShell has a built-in WebServiceProxy class which is really handy.

 #****************************************************  
 # Credentials and proxy to connect to web service  
 #****************************************************  
 $cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))  
 $workflowProxy = New-WebServiceProxy -Uri $wsWorkflowUrl -Credential $cred  
 $adminProxy = New-WebServiceProxy -Uri $wsAdminUrl -Credential $cred  

In order to consume the service, here is a function to search for tasks assigned to a user, list all tasks, and reassign it to the new (migrated) user. It makes use of GetWorkListByUserID and ReassignWorkItem services.

 Function Reassign-AgilePointTasks ($originalUser, $migratedUser)   
 {  
   $response = $workflowProxy.GetWorkListByUserID($originalUser, "Assigned;Overdue")  
   ForEach ($item in $response) {  
     # Reassigns each task to the migrated user account in AgilePoint.  
     Write-Host "Reassigning task $($item.Name) $($item.WorkItemID)" -foregroundcolor "Yellow"  
     $reassign = $workflowProxy.ReassignWorkItem($item.WorkItemID, $migratedUser)  
     $textLogFileOK = "Reassignment to $($reassign.UserID) complete. $($reassign.Error)"  
        Add-Content -path $LogFileOK -value $textLogFileOK  
     Write-Host "Reassignment to $($reassign.UserID) complete. $($reassign.Error)" -backgroundcolor "Green"  
   }    
 }  

Finally, put all the pieces together by looping through the csv file, and reassigning the tasks user by user:

 #****************************************************  
 # Start Bulk AgilePoint migration  
 #****************************************************  
 Import-Csv $csvFile | ForEach-Object{  
         $originalUser = $_.oldlogin  
         $migratedUser = $_.newlogin  
         Reassign-AgilePointTasks -originalUser $originalUser -migratedUser $migratedUser  
         Write-Host "Migrated User " + $originalUser + " to " + $migratedUser  
}   

And we're done!

Wednesday, August 17, 2016

SharePoint online: Add site collection administrator using PowerShell

Prerequisites: You need Microsoft SharePoint Online Management Shell installed on your machine.

Script:

 $loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")  
 $loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")  
 $loadInfo3 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")  
 #Must be SharePoint Administrator URL  
 $webUrl = "https://tenant-admin.sharepoint.com"  
 $username = "admin@tenant.onmicrosoft.com"  
 $password = "password"  
 $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)  
 Connect-SPOService -Url $webUrl -Credential $cred  
 $site = Get-SPOSite -Identity https://tenant-my.sharepoint.com/personal/mysites_domain_com  
 Set-SPOUser -Site $site.Url -LoginName username@email.com -IsSiteCollectionAdmin $true  

Wednesday, August 10, 2016

PowerShell: Pull AD user information from multiple forests into CSV

Script example to discover the forests available on a domain, and retrieve user information, outputting in a CSV format. It makes use of System.DirectoryServices interface so there is no need to be a domain administrator or install additional ActiveDirectory components/features. All you need is Windows running PowerShell. I tested this on a 64bit machine.

 # Get the user's Distinguished Name   
 Function Get-UserInfo ()   
 {   
   $Target = @()  
   #Get Domain List  
   $objForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()  
   $DomainList = @($objForest.Domains | Select-Object Name)  
   $Domains = $DomainList | foreach {$_.Name}  
   foreach($Domain in ($Domains))  
   {  
    Write-Host "Checking $Domain" -fore red  
    $ADsPath = [ADSI]"LDAP://$Domain"  
    $searcher = New-Object System.DirectoryServices.DirectorySearcher($ADsPath)  
    $searcher.Filter = "(&(objectClass=User)(extensionAttribute1>=1)(company=SAMPLEFILTER))"   
    $searcher.SearchScope = "Subtree"  
    $searcher.PageSize = 1000  
    $searcher.PropertiesToLoad.Add("name")  
    $searcher.PropertiesToLoad.Add("sAMAccountName")  
    $searcher.PropertiesToLoad.Add("mailNickname")  
    $searcher.PropertiesToLoad.Add("altRecipient")  
    $searcher.PropertiesToLoad.Add("extensionAttribute1")  
    $searcher.PropertiesToLoad.Add("co")  
    $colResults = $searcher.FindAll()   
    foreach ($objResult in $colResults)  {
      $objItem = $objResult.Properties  
      $objUser = new-object System.Object   
      $objUser | Add-Member -MemberType NoteProperty -Name "userName" -Value ([string]$objItem.Item("name"))  
      $objUser | Add-Member -MemberType NoteProperty -Name "login" -Value ([string]$objItem.Item("sAMAccountName"))  
      $objUser | Add-Member -MemberType NoteProperty -Name "altRecipient" -Value ([string]$objItem.Item("altRecipient"))  
      $objUser | Add-Member -MemberType NoteProperty -Name "mailAccount" -Value ([string]$objItem.Item("mailNickname"))  
      $objUser | Add-Member -MemberType NoteProperty -Name "customID" -Value ([string]$objItem.Item("extensionAttribute1"))  
      $objUser | Add-Member -MemberType NoteProperty -Name "country" -Value ([string]$objItem.Item("co"))  
      $Target += $objUser  
   }  
 }  
   $Target | select userName, login, alternateRecipient, mailAccount, customID, co | Export-csv "c:temp\QueryUser.csv"  
 }   
 Get-UserInfo  

Related Posts Plugin for WordPress, Blogger...