12Knocksinna / Office365itpros

Office 365 for IT Pros PowerShell examples
MIT License
1.24k stars 559 forks source link

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

Closed MarcLaf closed 1 year ago

MarcLaf commented 1 year ago

When running this script I keep getting the following for each module. I'm not running it as Administrator and I've changed the -Scope parameter to CurrentUser.

Checking and updating module AIPService InvalidOperation: Update-Office365PowerShellModules.ps1:30 Line | 30 | $CurrentVersion = $CurrentVersion.Major.toString() + "." + $Curr … | ~~~~~~~~~~~~~~~~ | You cannot call a method on a null-valued expression.

12Knocksinna commented 1 year ago

What's in $CurrentVersion?

MarcLaf commented 1 year ago

The version string from the module object.

On Tue, Jul 11, 2023 at 4:33 PM Tony Redmond @.***> wrote:

What's in $CurrentVersion?

— Reply to this email directly, view it on GitHub https://github.com/12Knocksinna/Office365itpros/issues/86#issuecomment-1631472108, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBMF5YGBOOYCM3SMSR7IGTXPW2B7ANCNFSM6AAAAAA2GIVB74 . You are receiving this because you authored the thread.Message ID: @.***>

12Knocksinna commented 1 year ago

Yeah, so is it getting a value? What module is being processed at the time? Forgive me for saying this, but you'll have to debug the script to find the problem in your environment. I cannot see what data is in front of you. I've just run the script with admin permissions (which it needs) on a new PC and it works perfectly.

MarcLaf commented 1 year ago

Right I’ve been trying to off and on. I mentioned in the first post that I did not run as administrator because I only want to install for current user (and modified the script to do so), not all users as is originally built. I’m thinking this could be a reason although I’m not sure how that would affect this issue. It does it for all modules.

I’ll keep at it then.

On Tue, Jul 11, 2023 at 4:42 PM Tony Redmond @.***> wrote:

Yeah, so is it getting a value? What module is being processed at the time? Forgive me for saying this, but you'll have to debug the script to find the problem in your environment. I cannot see what data is in front of you. I've just run the script with admin permissions (which it needs) on a new PC and it works perfectly.

— Reply to this email directly, view it on GitHub https://github.com/12Knocksinna/Office365itpros/issues/86#issuecomment-1631482645, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBMF5ZXOJ4PP4AVZAVQYDLXPW3EVANCNFSM6AAAAAA2GIVB74 . You are receiving this because you authored the thread.Message ID: @.***>

12Knocksinna commented 1 year ago

I still think you need to run PowerShell as an administrator to be able to install or update modules.

12Knocksinna commented 1 year ago

I'm closing this issue.

MarcLaf commented 1 year ago

I know this is closed but I figured out the issue. It wasn't Admin related, it was Windows PowerShell vs PowerShell 7. My default version is PowerShell 7 and I use the majority of the modules there. This script needs Windows PowerShell for what I'm guessing are a few modules dependent on that version. I have no idea if there is a check to implement whether or not it's being run in Windows PowerShell vs PowerShell 7.

12Knocksinna commented 1 year ago

That could be it. I do use the Install-Module and Update-Module cmdlets...