Avatar of sacgar
 asked on

Access is denied error while opening com object in Powershell

I am using below code in my powershell

$Clu = New-Object -com "MSCluster.Cluster"
$GroupOwner = $Clu.ResourceGroups.Item($ClusterName).OwnerNode.Name

but while opening the object it is throwing error of access denied , what permissions is required to run the above code other than adding the account to Admin group that is not permitted..

below is the error I am getting

Exception calling "Open" with "1" argument(s): "Access is denied. (Exception fr
om HRESULT: 0x80070005 (E_ACCESSDENIED))"
At E:\do_not_delete\Script\Main_Task.ps1:3 char:10
+ $Clu.Open <<<< ($ClusterName)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

You cannot call a method on a null-valued expression.
At E:\do_not_delete\Script\Main_Task.ps1:4 char:39
+ $GroupOwner = $Clu.ResourceGroups.Item <<<< ($ClusterName).OwnerNode.Name
    + CategoryInfo          : InvalidOperation: (Item:String) [], RuntimeExcep
    + FullyQualifiedErrorId : InvokeMethodOnNull

IT AdministrationPowershellMicrosoft Server OS

Avatar of undefined
Last Comment

8/22/2022 - Mon
Meir Rivkin


Are you running the Powershell as administrator? Right click on Powershell and click "Run as administrator"..

Thanks , actually there is no issue when I run as admin ,the issue is I am running from an account that is not admin and it is failing with access denied ,even the querying the wmi (get-wmi) , I am looking what minimum permission I can give to that domain account to get it working..
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.

I was talking about running PowerShell console with "Run as administrator"
Run as adminFollowing article may help if you are trying to access  WMI with a non admin account..

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question