header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Get-WmiObject : Access is denied
Last Post 20 Mar 2008 12:46 PM by get-james. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
get-jamesUser is Offline
New Member
New Member
Posts:20
Avatar

--
18 Mar 2008 05:23 PM  

 

 Hi Guys,

I am trying to get gwi to work on a remote server and am getting the following error message:

Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I can run the command agaist my localhost :

Get-WmiObject Win32_UserAccount -computername Localhost -filter "localaccount=true" | Select-Object name, description, status, lockout, passwordExpires | ft -AutoSize

But when I run it agaist a server on my network I get access denied? 

Get-WmiObject Win32_UserAccount -computername server01 -filter "localaccount=true" -credential $cred | Select-Object name, description, status, lockout, passwordExpires | ft -AutoSize

Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At line:1 char:14 + Get-WmiObject  <<<< Win32_UserAccount -computername server01 -filter "localaccount=true" -crede ntial $cred | Select-Object name, description, status, lockout, passwordExpires | ft -AutoSize

I have also tried running powershell using the runas and using my domain admin account.

Has anyone else had this issue?

Cheers

James

marco.shawUser is Offline
Co-Community Director
Basic Member
Basic Member
Posts:188
Avatar

--
18 Mar 2008 06:25 PM  
Sounds like you need to enable WMI through the client firewall on srv1. From a command-line (DOS) or PowerShell:
*Windows VServer 2008:
Netsh firewall set service RemoteAdmin
Netsh advfirewall set currentprofile settings remotemanagement enable

*Windows Server 2003:
netsh firewall set service RemoteAdmin enable
Marco

*Microsoft MVP - Windows PowerShell: http://www.microsoft.com/mvp
*PowerGadgets MVP: http://www.powergadgets.com/mvp
*Blog: http://marcoshaw.blogspot.com
get-jamesUser is Offline
New Member
New Member
Posts:20
Avatar

--
20 Mar 2008 12:46 PM  
Cheers Marco, but in my server environment the windows firewalls are not enabled.

Anyway, I had to quickly todo it vb I needed the results quick,

I have now done a vbscript which using the GetObject("WinNT")..

I have looked around to find a powershell script the to the below but can't find any solutions:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

'Author: James Brown
'Description: List local groups and there members
'version: 1.0

' Variables
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim strComputer, OutFile, Outfilestr

' Const
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
const ForReading = 1, ForWriting = 2, ForAppending = 8

'Arguments
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set objArgs = WScript.Arguments

if WScript.Arguments.Count < 2 then
wscript.echo " Not Enough Parameters "
wscript.echo " Usage:-- Sourcefile"
wscript.echo " i.e: c:\script.vbs c:\listusers.txt c:\output"
wscript.quit (1)
end if

sourcefile=wscript.Arguments(0)
destpath=wscript.Arguments(1)


'File to Read From
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set fso = CreateObject("Scripting.FileSystemObject")
set infile = fso.OpenTextFile( sourcefile, 1 , True)


'Main Part
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Call Main

Sub Main
do until infile.AtEndOfStream
ReadLineTextFile = infile.ReadLine
On Error Resume Next
strComputer = ReadLineTextFile

Outfilestr = destpath &"\" &strComputer &".csv"
Set fso2 = CreateObject("Scripting.FileSystemObject")
Set OutFile = fso2.CreateTextFile(Outfilestr)

Wscript.echo "Server: " &strComputer &vbCrlf &vbCrlf
OutFile.writeline strComputer
OutFile.writeline ""
OutFile.writeline "Group,Users"

Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
GroupName = objGroup.Name
Wscript.Echo "Group: " &GroupName
Wscript.Echo "---------------------------------------------------------"
For Each objUser in objGroup.Members
UserName = objUser.Name
Wscript.Echo vbTab &UserName
OutFile.writeline GroupName &"," &UserName
Next
Wscript.Echo ""
Next
Loop
End Sub


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


I have found the following which lists the local groups, but not there members...

http://www.myitforum.com/articles/40/view.asp?id=10693

$strComputer = "."
$computer = [ADSI]("WinNT://" + $strComputer + ",computer")
$group = $computer.psbase.children |where{$_.psbase.schemaclassname -eq "group"}
foreach ($member in $group.psbase.syncroot)
{$member.name}


Is there a way of modifying the above PS script to get the members ?

Cheers
James
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer