Welcome to EMC Consulting Blogs Sign in | Join | Help

James Broome Blog

Commerce Server blog #1 - Connecting to web services using PowerShell

 

I've been working on an eCommerce Project for the last 18 months built around Microsoft Commerce Server and over that time have picked up a lot of hints, tips, hacks etc. I've been meaning to document a lot of this stuff for a while so it may be old news to some of my current colleagues, but might help out those of you who are starting out on a similar project.

 

Recently I had to make some changes to our live Marketing data - update a load of existing Page Groups that were being used by Advertisements on the live site. The Marketing system does not have the same import/export capabilities that the catalog has - there's no equivalent to exportcatalog.exe or importcatalog.exe so running incremental import scripts was not an option.

 

So, I decided to write a PowerShell script that could be run as part of our deployment to make the updates to the data. This was my first real experience of PowerShell - I've played around with it a bit, but hadn't yet used it "for real".

Here is the script - it creates a Marketing Context for the Marketing web service and then updates all the necessary Page Groups accordingly:

 

######################################################################################################
# Connect to the Marketing Web service and update the existing page groups
######################################################################################################

# Global Variables to set:

#Url of marketing webservice
$Url = "localhost"

#Connect to the Marketing web service and update the existing Test1 page groups to Test2

[reflection.assembly]::loadwithpartialname("Microsoft.CommerceServer.Marketing.CrossTierTypes");

$marketingAgent = new-object -typename Microsoft.CommerceServer.Marketing.MarketingServiceAgent -argumentlist ("http://" + $Url + "/MarketingWebService/MarketingWebService.asmx");

$marketingContext = [Microsoft.CommerceServer.Marketing.MarketingContext]::Create($marketingAgent);
$marketingContext;

$pageGroups = $marketingContext.PageGroups.GetAllPageGroups();

foreach ($pageGroup in $pageGroups)
{

$pageGroup.Tag = $pageGroup.Tag -replace 'Test1','Test2';
$pageGroup.Description = $pageGroup.Description -replace 'Test1','Test2';

$pageGroup.Save();

}

######################################################################################################
# End
######################################################################################################

 

I found that (ignoring my PowerShell learning curve) this was fairly straightforward and realised that the same principles could be applied to any of the Commerce Server APIs. We already have complete automated build process in place on our project and now that I have realised how easy it is to call the Commerce Server APIs via PowerShell, I will start to consider this option more for future data updates.

Published Tuesday, December 16, 2008 3:43 PM by james.broome

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Bayapa Reddy M said:

Hi James,

            Could you please share powershell scripts for creating commerce server 2009 site.

Thanks,

Bayapa Reddy M

October 26, 2010 6:25 AM
 

Bill W said:

This article was just what I needed.  I've been trying to convert a short C# set of code into PowerShell and I couldn't figure out how to call the Create method on the CatalogContext object.

Your example gave me the answer (::Create) - that did the trick.

AWESOME!  Thank you for sharing your knowledge.

Bill

January 20, 2014 4:02 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit

About james.broome

James is a Technical Consultant at Conchango
Powered by Community Server (Personal Edition), by Telligent Systems