Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Powershell syntax...

  • 01-06-2014 11:22am
    #1
    Registered Users, Registered Users 2 Posts: 1,002 ✭✭✭


    I have a CSV file - two columns: Accountname, Groupname

    I have a loop that creates the Groupname
    I have a sub loop that checks the Accountname validity and adds the Accountname to the Groupname

    My sub loop works, it correctly adds the right Accountname to the right Groupname. But I get this error "You cannot call a method on a null-valued expression." even though I don't believe the value is Null.

    I believe my method runs successfully but is badly written :o

    foreach($group in $UserList)
    {     
        $GroupName = $group.GroupName
        if($web.SiteGroups[$GroupName] -ne $null)
        {
            write-host "$GroupName already exists"
        }
         else
        {
            write-host "$GroupName does not exist, creating new $GroupName group"
            $web.SiteGroups.Add($GroupName, $siteownergroup, $null, $description)
            $spgroup = $web.SiteGroups["$GroupName"]
            $spgroup.Update()      
            
            foreach($Row in $UserList)
            {
                #### Get the Group name
                $UserGroup = $web.Groups[$Row.GroupName]
                $user = $web.site.RootWeb.EnsureUser($Row.AccountName)
                if ($user -ne $Null)
                 {
                   $UserGroup.AddUser($user)
                 }        
             }
        }
     }
    

    The ERROR message is

    You cannot call a method on a null-valued expression.
    At C:\Scripts\groups-externalcsv.ps1:49 char:14
    + $UserGroup.AddUser($user)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull


    It errors each time at $UserGroup.AddUser($user)


Comments

  • Closed Accounts Posts: 751 ✭✭✭SeanPuddin


    I've never used Powershell but is this legal? Capital N for null?

    if ($user -ne $Null)
    {
    $UserGroup.AddUser($user)
    }

    Very difficult to diagnose the problem without full script and line numbers.


Advertisement