Link to home
Start Free TrialLog in
Avatar of sacgar
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"
$ClusterName="xx"
$Clu.Open($ClusterName)
$GroupOwner = $Clu.ResourceGroups.Item($ClusterName).OwnerNode.Name
$Servername=Hostname

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
   tion
    + FullyQualifiedErrorId : InvokeMethodOnNull




Thanks
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

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

ASKER

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..
I was talking about running PowerShell console with "Run as administrator"
User generated imageFollowing article may help if you are trying to access  WMI with a non admin account..
http://unlockpowershell.wordpress.com/2009/11/20/script-remote-dcom-wmi-access-for-a-domain-user/
ASKER CERTIFIED SOLUTION
Avatar of sacgar
sacgar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial