Unable to use best practices library for PowerShell - Request object is empty

I'm trying to use the best practices library for PowerShell, but I keep getting this error:

You cannot call a method on a null-valued expression.

For some reason the $request is always empty when I try to use any of the functions in the library.

Here's an example of the code I'm using:

function onInit($context) {
    $context.UseLibraryScript('Script Modules/Library/One-Identity-Libary')
}

function onPreModify($Request) {
    if ($Request.Class -ne "user") { return }

    $tieredAttributes = @(
        'edsvaTier1Required'
        'edsvaTier2Required'
        'edsvaTier3Required'
    )
    if (AreAttributesModified($tieredAttributes, $Request)) {
        #do stuff with attributes
    }
}

I also tried adding $Request | Get-Member | Out-File C:\Request.txt to the functions in library, this generates an empty file.

Am I missing something obvious? 

Parents
  • Hello, jody.

    First, it's been a while, but I don't believe you need to have the "Script Modules" part of the path specified. Just the "Library/One-Identity-Library" portion.

    Second, your statement on line 13 calls AreAttributesModified. Don't know the contents of your library, of course, but unless you've changed something, then the "best practice" code uses the function name IsAttributeModified - note the word "attribute" is singlular/no "s".

    Lastly, the idea of using onInit at all has, more recently, fallen out-of-favour due to the performance implications it imposes on the Web interface. You might consider using something like Invoke-Command and/or Invoke-Expression instead. That is discussed herein in this thread.

    Cheers!
    Shawn

  • thanks for the tip on Invoke-Expression, I've switched to using that.

    the issue appears to be positional parameters, if I name the parameters I can use the functions from the library.

Reply Children