Question

I found online a VBscript that joins a computer to a group in the Users OU for Direct Access to work. It works perfectly in the task sequence for our OSD using SCCM 2012 but we've come to a road block where we only want laptops to be added rather then all computers.

If someone would be so kind, I need a script (Powershell, VB, JScript) that will detect that the computer was added to the group in AD.

Was it helpful?

Solution

Set the task sequence step to run based on a condition.

enter image description here

The above conditions detects if the computer is a laptop. The first one will only work when you have MDT integrated and the second uses a simple WMI query to detect the system type.

The WMI query might not be as reliable, so I would advice you integrate MDT into your environment.

OTHER TIPS

You could try something like this in PowerShell to check that the named computer is in the OU or not:

Script:

import-module activedirectory

$OU = @() 
$CheckOU = "LaptopOU"
$computerName = "Laptop12345"

$user = get-adcomputer $computerName -Properties *
$user.DistinguishedName -split "," | %{If($_ -match "OU="){$OU += $_ -replace "OU=",""}}

If($OU -match $CheckOU){
    "Computer:$computerName is in the OU:$CheckOU"
    # Do something...
}
Else{
    "Computer:$computerName is not in the OU:$CheckOU"
    # Do something else..
}

This will take a $computerName and get all the OU's that it's in from Active Directory and stores them in an $OU array.

Then you can use that array to simply check if the computer is in the given OU ($CheckOU) or not by using the -match operator.

Note: You need to make sure that you import the activedirectory module. If you do not have this to import follow this link for how to get it: activedirectory module

For more Cmdlet's and syntax on the Powershell Active Directory module follow this Link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top