Hi!

I'm looking for a script that tells me what domain a computer belogs to, the
script will be run remote.

I have found, or stolen, the following that tells me who is logged on to a
computer and it works fine. I'd like the other one to work in the same way.

ComputerName = InputBox("Enter the name of the computer you wish to query")
who = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
Set Users = GetObject( who ).InstancesOf ("Win32_ComputerSystem")
for each User in Users
MsgBox "The user name for the specified computer is: " & User.UserName
Next

Since I don't know anything about scripting, Iâ??m a copy and paste guy, even
this simple thing is pretty hard for me to solve.

Thanks for any help!

Re: See what domain a computer belongs to! by Jeffery

Jeffery
Thu Jan 24 08:46:49 CST 2008

Here's a function you can use to return the domain name:

Function GetDomain(strServer)

strDomain="NotFound"

Set objWMI=GetObject("WinMgmts://" & strServer)
strQuery="Select Domain from win32_computersystem"

Set colItems=objWMI.ExecQuery(strQuery)
For Each item In colItems
strDomain=item.Domain
Next

GetDomain=strDomain

End Function

You would use lines like this in your script to call the function:
strServer="FILE01"
wscript.echo strServer & " belongs to " & GetDomain(strServer)

Although as written, this code does not support alternate credentials so
you'd need to run it with credentials that have admin rights on the remote
computer.

--
Jeffery Hicks MCSE, MCSA, MCT
Microsoft PowerShell MVP
http://www.scriptinganswers.com
http://www.powershellcommunity.org
http://jdhitsolutions.blogspot.com

Now Available: WSH and VBScript Core: TFM
Now Available: Windows PowerShell v1.0: TFM 2nd Ed.


"Henrik" <Henrik@discussions.microsoft.com> wrote in message
news:6F527330-5C66-4E9B-AA6C-F81A8D2BA506@microsoft.com...
> Hi!
>
> I'm looking for a script that tells me what domain a computer belogs to,
> the
> script will be run remote.
>
> I have found, or stolen, the following that tells me who is logged on to a
> computer and it works fine. I'd like the other one to work in the same
> way.
>
> ComputerName = InputBox("Enter the name of the computer you wish to
> query")
> who = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
> Set Users = GetObject( who ).InstancesOf ("Win32_ComputerSystem")
> for each User in Users
> MsgBox "The user name for the specified computer is: " & User.UserName
> Next
>
> Since I don't know anything about scripting, Iâ??m a copy and paste guy,
> even
> this simple thing is pretty hard for me to solve.
>
> Thanks for any help!
>

Re: See what domain a computer belongs to! by Henrik

Henrik
Thu Jan 24 11:52:03 CST 2008

Thanks Jeffery!

When i added an InputBox it worked just like a wanted.

/Henrik