none
VBScript to check if the computer is present in Active Driectory RRS feed

  • Question

  • I want to know is there any script to check if the machine is present in AD or not. Like say i have a machine named XYZ and i want to check if this machine is in AD or not.

    Using VBScript how do i do this?

    I am new to LDAP.


    \m/

    Friday, January 17, 2014 7:46 AM

Answers

  • The simplest test for a computer using VBScript in an Active directory domain is the following.

    MsgBox TestComputer("XYZ")
    
    Function TestComputer( strComputer )
         On Error Resume Next
         Set c = GetObject("WinNT://TESTNET/" & strComputer & ",computer")
         If Err.Number = 0 Then TestComputer = True
    End Function
    
    "TESTNET" is the NetBIOS name of the domain.


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, January 17, 2014 1:06 PM
    • Marked as answer by KhushbooPatel Wednesday, January 22, 2014 5:31 AM
    Friday, January 17, 2014 1:05 PM

All replies

  • PowerShell

    Import-Module ActiveDirectory
    $computername = "xyz"
    If ((Get-AdComputer $computername | Measure).count -eq 1){"PC with name $computername are present in AD"}
    It must work on Win 2003/2008/r2/2012 DC with PowerShell v2, v3, v4
    If PC with name "xyz" does not exist you have error
    Cannot find object with identity 'xyz' under: 'DC=Contoso,DC=com'




    • Edited by Vector BCO Friday, January 17, 2014 8:15 AM
    Friday, January 17, 2014 8:09 AM
  • PowerShell

    Import-Module ActiveDirectory
    $computername = "xyz"
    If ((Get-AdComputer $computername | Measure).count -eq 1){"PC with name $computername are present in AD"}
    It must work on Win 2003/2008/r2/2012 DC with PowerShell v2, v3, v4
    If PC with name "xyz" does not exist you have error
    Cannot find object with identity 'xyz' under: 'DC=Contoso,DC=com'




    This is not VBScript and it will not work on WS2003 domains.  You are also using methods that make little sense.

    With the AD Cmdlets the following tests for specific a computer:

    if(Get-AdComputer xyz){
         'computer found'
    }else{
          'cpm[uter not found'
    }

    There are learning resources here.  I recommend that you review them to see how to use PowerShell.

    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx


    ¯\_(ツ)_/¯

    Friday, January 17, 2014 12:56 PM
  • The simplest test for a computer using VBScript in an Active directory domain is the following.

    MsgBox TestComputer("XYZ")
    
    Function TestComputer( strComputer )
         On Error Resume Next
         Set c = GetObject("WinNT://TESTNET/" & strComputer & ",computer")
         If Err.Number = 0 Then TestComputer = True
    End Function
    
    "TESTNET" is the NetBIOS name of the domain.


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, January 17, 2014 1:06 PM
    • Marked as answer by KhushbooPatel Wednesday, January 22, 2014 5:31 AM
    Friday, January 17, 2014 1:05 PM
  • Thanks jrv .It works perfect :)

    \m/

    Wednesday, January 22, 2014 5:31 AM