Active Directory Help

Welcome Forums General PowerShell Q&A Active Directory Help

This topic contains 6 replies, has 4 voices, and was last updated by

1 year, 9 months ago.

  • Author
  • #70699

    Points: 1
    Rank: Member

    I am fairly new and need help on 2 active Directory tasks.

    1) Checking if a pc name is in AD or not
    2) adding a PC to AD

    I saw Get-ADComputer but the module needed is not on all pc's. these will be freshly imaged pc's that need to be added to the domain. Is there another way or way to include any needed module in my script (it will be eventually compiled using Powershell studio)

    For item 2 I want to add a pc if not in AD to the domain and a specific OU.

    Any help would be great.


  • #70814

    Points: 1
    Rank: Member

    Here is a function to test if an Computer Account is in AD or not, and returns a Boolian(True,False)

    Function Test-ADComputer {
    #		Helper Funtion that check's if an ADgroup (still) Exist in Active Directory.
    #		Helper Funtion that check's if an ADgroup (still) Exist in Active Directory.
    #	.PARAMETER ComputerName
    #		The ActiveDirecory Computername / Identity
    #	.EXAMPLE
    #		PS C:\> Test-ADComputer -ComputerName $ComputerName
    #		If (Test-ADComputer -ComputerName $ComputerName) {Do-SomeThing}
    #	.OUTPUTS
    #		System.Boolean
    #	.NOTES
    #		Made By Julien Zweverink
    	[CmdletBinding(ConfirmImpact = 'None',
    				   PositionalBinding = $true,
    				   SupportsPaging = $false,
    				   SupportsShouldProcess = $false)]
    		[Parameter(Mandatory = $true,
    				   ValueFromPipeline = $true,
    				   ValueFromPipelineByPropertyName = $true,
    				   ValueFromRemainingArguments = $false,
    				   Position = 0)]
    		[Alias('CSName', 'PSComputerName', '__SERVER', 'HostName', 'Identity')]
    	Begin {
    		Write-Verbose -Message "[BEGIN  ] Starting: $($MyInvocation.Mycommand)"
    	} #Begin
    	Process {
    		Try {
    			Write-Verbose -Message "[Process] Test if: $ComputerName can be found in Active Directory"
    			$null = Get-ADComputer -Identity $ComputerName -ErrorAction Stop
    			Write-Verbose -Message "[Process] $ComputerName was found in Active Directory"
    			return $true
    		} #Try
    		Catch {
    			Write-Verbose "[Process] Computer: $ComputerName not found in Active Directory"
    			Return $false
    		} #Catch
    	} #Process
    	End {
    		Write-Verbose -Message "[End    ] Ending:   $($MyInvocation.Mycommand)"
    	} #End
    } #Function

    To Use it:

    Test-ADComputer -ComputerName Computer123 #-Verbose
    If (Test-ADComputer -ComputerName Computer123) {'Do-SomeTing'}
  • #70822

    Points: 1
    Rank: Member

    That wont work as it relies on Get-ADComputer. I asked for something that doesnt. these are new pc's and that requires an install to work. It is also available as part of the Windows 7 and Windows 8 Remote Server Administration Toolkits (RSATs). It is not a Windows feature.

    I need somethinbg out of the box

  • #70823

    Points: 642
    Helping Hand
    Rank: Major Contributor

    Implicit Remoting might be helpful in this case ....

  • #70912

    Points: 3
    Rank: Member

    As ugly as this might be, it still works. You should do all that fancy stuff for the function as in above.

    function get-ldapComputer ($computer) {
        $strFilter = "(&(objectCategory=computer)(Name=$computer))"
        $objDomain = New-Object System.DirectoryServices.DirectoryEntry
        $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
        $objSearcher.SearchRoot = $objDomain
        $objSearcher.PageSize = 1000
        $objSearcher.Filter = $strFilter
        $objSearcher.PropertiesToLoad.Add('name') |out-null
        $result = $objSearcher.Findone()
        if ($result) {
            write-output "Found $($"
        Else {
            write-output "DANG! There was no $computer"
  • #71084

    Points: 1
    Rank: Member

    My bad,

    This Module should do the trick, it uses ADSI and not the AD Module.

  • #71090

    Points: 1
    Rank: Member

    Thanks guys the adsi and code samples worked perfect.


The topic ‘Active Directory Help’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort