Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell IF Statements - Moving a PC IF it is in a certain 'CN' in Active Directory

$
0
0

Hi,

I am new to Powershell (and this forum), and I am really hoping someone (anyone...) can assist me with.

I have been using a simple Powershell Script to move PC's in to specific OU's depending on their location. I obtained the information required using SQL.

The powershell script I have been using is:-

Import-module activedirectory

get-adcomputer PCNAMEHERE | Move-ADObject -TargetPath (Get-ADOrganizationalUnit -LDAPFilter "(name=NEW OU HERE)")

This script would simply move the PCNAMEHERE computer in to the NEW OU HERE.

Now, however, I need to move a computer object ONLY IF it is in our 'Computers' container, which is as an example - CN=Computers,DC=domain,DC=local

So is there a way of looking ONLY in the 'Computers' CN in Active Directory to run the above command?

I would appreciate your help.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>