Loading

Module

Skip Feed
  1. Another Powershell Question

    The Powershell below works great when I run it straight from Powershell and prompt for the inputs. However when I run inside of the App Store I get the following error. 

    Failed to run expression: . 'C:\Program Files\Snow Software\Snow Automation Platform\Activities\migrategroupmembership\2\migrategroupmembership.ps1' -identity 'CNCLCFZLHC2' -target 'STLVDBUS029'. Row number: 110. Error: Cannot validate argument on parameter 'MemberOf'. The argument is or empty. Provide an argument that is not or empty, and then try the command again.

    It appears to be passing the parameter but from some reason the MemborOf is but I don't get that error when I run manually.

    Thanks for you help!

    Jerry

    Param(

     

    $identity,

     

    $target

     

    )

     

    Function Get-MyModule

     

    {

     

    Param([string]$name)

     

    if(-not(Get-Module -name $name))

     

    {

     

    if(Get-Module -ListAvailable |

     

    Where-Object { $_.name -eq $name })

     

    {

     

    Import-Module -Name $name

     

    $true

     

    } #end if module available then import

     

    else { $false } #module not available

     

    } # end if not module

     

    else { $true } #module already loaded

     

    } #end function get-MyModule

     

    Function Get-GroupsToMigrate

     

    {

     

    Param($identity)

     

    $array = @()

     

    $groups = Get-AdComputer -Identity $identity -property “MemberOf”

     

    Foreach($group in $groups.memberOf)

     

    {

     

    #$reply = Read-Host -Prompt “add group $($group) `r`ny / n”

     

    #if($reply -match “y”) {$array +=$group}

     

    } #end foreach

     

    Return $array

     

    } #end Get-GroupsToMigrate

     

    # *** ENTRY POINT TO SCRIPT ***

     

    If(-not (Get-MyModule -name “ActiveDirectory”)) { exit }

     

    $array = Get-GroupsToMigrate -identity $identity

     

    Get-ADComputer -Identity $target | Add-ADPrincipalGroupMembership -MemberOf $array

    #testing making a change

    Expand Post

    • Community Manager (Flexera Software)

      Hi! I would try running the script logged in as the workflowengine account (or runas). It could be that your own account has permissions to read the memberOf property but the service account does not. //Joakim

End of Feed
1 Chatter Feed Items
ALL CONVERSATIONS
UNSOLVED
ARTICLES
1 Post

Related Topics

    Loading
    Module | Flexera