Running Powershell Script from Workflow

Oct 17, 2012 at 3:37 PM
Edited Oct 17, 2012 at 3:44 PM

Hello, I'm trying to run the following script as a SPD workflow step:


if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
#Set up default variables
$mySiteUrl = "http://servername"
$adAccount = <sharepointlistfield>
$Attribute1 = "CustomUserProfileProperty"
$AttributeValue1 = <sharepointlistfield>

#Get site objects and connect to User Profile Manager service
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

#Check to see if user profile exists
if ($profileManager.UserExists($adAccount))
    #Get user profile and change the value
    	$up = $profileManager.GetUserProfile($adAccount)
    	$up[$Attribute1].Value = $AttributeValue1
    write-host "Profile for user"$adAccount "cannot be found"

#Dispose of site object

This is part of a workflow action that, upon user profile sync will update the new user profile just created with a bunch of more field extracted from a custom list. Running it from sharepoint powershell or powergui, everything works like a charm, but when I insert it as a step of the workflow, i receive this error:
Error while executing PowerShell Script: Cannot invoke this function because the current host does not implement it.

Actually, I cannot run any powershell script using the custom action. Any way to get rid of it? Thanks in advance for any help Renato