Getting get-nlbclusternode:Access is denied.Exception

am using the following code to do load balancing using powershell script. It works fine on local machine but getting get-nlbclusternode : Access is denied. (Exception from HRESULT: 0x80070005 while doing it from teamcity octopus deployment script. Please guide how can I fix this issue.

import-module NetworkLoadBalancingClusters
$user = “domain\test”
$PWord = ConvertTo-SecureString -String “pa4w0rd” -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
Get-Credential $Credential

#uses the nlb cmdlets to check the state of the current cluster
$clusterstatus = get-nlbclusternode -nodename $RemoteHostName

[string]$status = $clusterstatus | select -expand state
    #if the node has already been stopped dont do anything
if ($status -eq "Stopped")
        "Node already stopped"

    #if the node hasnt been stopped, stop the node

    "Starting to drain stop the node"
        stop-NlbClusterNode -HostName $RemoteHostName -Drain


The PowerShell modules for NLB may have only been installed for a single user. Tentacle runs under the Local System user account by default so it may not have access to those modules.

Please follow this guide to test your script within Tentacle manually to see if it’s related to running under Tentacle, or if it’s a user account problem:


Thank you for your reply. I have a domain user which have all the administrative rights on the remote machine. I run the script locally on that machine by login using that user as described in the link. At first it opens up the UAC prompt as attached in the issue and then it executes the script in another window and closes the window and don’t return back to main window from where I executed the command. Can you please guide. as still cant do it without elevated privileges. Any more information please ask.



Can you open the command prompt as an admin (right click, run as administrator) first, and then run the Tentacle command? This will allow you to see the output.


Yes, It works fine if executed by run as administrator. But how can I run this as an administrator from a remote machine. As I want the octopus Predeploy script to do the load balancing. please guide.

Hi Sam,

Can you try changing the Octopus Tentacle windows service to run under your administrator user account rather than Local System?


Hi Paul,
Many thanks to you as by running under administrator user account this works like a charm. Silly mistake as every other service was running under that account and I didn’t try for this one. Many Thanks again. Just love using octopus in every aspect.