Wednesday, September 7, 2016

Generate HTML static files from Wordpress WXR using Python

Tested on Python 3.5 (32 bit) for Windows

It is fairly common knowledge that plugins are available to export Wordpress into static files. However, to have your static content generated in far more flexible manner, it's always programming to the rescue.

The script is adapted from the original code found in Jon Thysell's excellent WXR to HTML article.

I modified the original script slightly to download images that are included in each article, as well as saving articles as individual files in YYYY\M\xxx.html format.

This script would take 1 argument as input. It expects the full path to the Wordpress WXR export file (in xml format). The WXR file can be exported by going to Wordpress Admin -> Tools -> Export. I used a full export.

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  

Tuesday, February 2, 2016

PowerShell to upload a file into multiple sites under Project Web App (Office 365)

This is a powershell script custom written to upload an Excel report to multiple Project Online sites, but you could easily customize it to suit your own purposes. The same method works on Office 365 and SharePoint Online sites.

Prerequisites:
You will need to install the SharePoint 2013 client components on your client machine. I am running it on Windows 7 so I am actually using the PowerShell 64 bit version and 64bit client components.

 # Load SharePoint Client  
 Add-Type –Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"   
 Add-Type –Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"   

I am using the newest version on Project online, hence the 16 hive. 15 hive works as well!

SP2010 C# CSOM: Update Created and Modified dates and author

Tested on SharePoint 2010 only. I wanted to have something that could run on a client machine that could help update metadata for a folder or file in a list / document library.

This is a console application written in C#. Obviously, to do something in SharePoint 2010 automation, you will need to download the SP2010 foundation and install some runtime components.

(Or if you are feeling lazy, just copy Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll and reference them in your project).

To make this piece of code work, you need to know the ID of your list/folder item. There are other methods of retrieving based on URL.

Tuesday, January 26, 2016

PowerShell to update and refresh Excel data connections

Scenario:
You have multiple Excel files that applies the same template and formatting, but uses different data sources.
*** My requirement was to replace oData connections. I needed a simple script that would open an Excel file, loop through the data connections, and replace the data connection string.

Tested on Excel 2013, run PowerShell 64bit using Windows 7 Pro.

Wednesday, January 13, 2016

PowerShell script to list and export top navigation links

This PowerShell snippet will parse a single site for the top or global navigation links, display in the shell window, and output to an XML file in the following format:

 <Navigation>  
 <Group Title="Regions" Url="http://regions">  
 <Link>  
      <Name>Asia Pacific</Name>  
      <Url>http://apac</Url>  
      <Target />  
 </Link>  
 <Link>  
      <Name>EMEA</Name>  
      <Url>http://emea</Url>  
      <Target />  
 </Link>  
 <Link>  
      <Name>US</Name>  
      <Url>http://us</Url>  
      <Target />  
 </Link>  
 </Group>  
</Navigation>  

Related Posts Plugin for WordPress, Blogger...