Changes to support PowerShell 3

Sep 24, 2012 at 6:05 PM

Hey,

I added this change to get this running on PS 3...type accelerators and the "-registered" switch for Get-PSSnapin.

  

if(-not(Get-PSSnapin -Registered |? { $_.Name -eq 'FIMAutomation' })){ Add-PSSnapin FIMAutomation }

function Add-PSTypeAccelerator {
 param(
  [Parameter(Mandatory = $true)]
  [string] $AliasName,
  
  [Parameter(Mandatory = $true)]
  [string] $TypeName,
  
  [switch] $Force = $false
 )
 
 begin
    {
        $PSTypeAccelerators = [psobject].assembly.gettype("System.Management.Automation.TypeAccelerators")::Get
        $Type = Invoke-Expression "[$TypeName]"
 if ($PSTypeAccelerators.ContainsKey($AliasName))
        {
  if ($Force)
             {
   $PSTypeAccelerators.Remove($AliasName) | Out-Null
  } else
             {
    throw 'Type accelerator "{0}" already exists.' -f $AliasName
  }
 }
 }
 end {
  $PSTypeAccelerators.Add($AliasName, $Type)
 }
}

 

Coordinator
Sep 24, 2012 at 6:15 PM

Thanks for the feedback!  I've already been using the activity with PowerShell 3.0 and have not had any issues. 

What advantage did you get from using the type accelerators?  Would love to hear more about it.

 

Sep 24, 2012 at 6:44 PM

I just realized that I pasted that into the wrong window.

Face meet palm. Palm, face.

Coordinator
Sep 24, 2012 at 9:54 PM

Too funny ;-)  Happy Accelerating!

Dec 9, 2012 at 6:46 AM

Hi,

I'm trying to use this activity in FIM R2 and would like to make use of PowerShell v3 functions like ConvertTo-Json... Any idea how I would go about getting this PowerShell activity to use PowerShell v3? I have installed v3 on my portal and FIM service servers, but the workflow keeps complaining that it doesn't understand convertTo-Json...

Have I missed something...?

Thx

Q