Q. In a PowerShell workflow how can I load assemblies for certain actions?

ITPro Today

September 17, 2015

1 Min Read
Q. In a PowerShell workflow how can I load assemblies for certain actions?

Q. In a PowerShell workflow how can I load assemblies for certain actions?

 

A. In regular PowerShell assemblies can be loaded using Add-Type or [Reflection.Assembly]::LoadWithPartialName() however this is not legal in a PowerShell workflow. Instead you need to use a section of InlineScript and contain the assembly load and usage within it. For example:

 $NewPassword = InlineScript {
    Add-Type -AssemblyName System.Web
    [System.Web.Security.Membership]::GeneratePassword(16,2)
}

Note the code in the InlineScript outputs a value which I then save into a variable on the outside of the InlineScript section.

Here's more information and tips on using variables when using InlineScript can be found.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like