Solved

Can I use "Get-QADComputer -Name $computers" and pull from a csv file for the var $computers

Posted on 2010-09-22
2
811 Views
Last Modified: 2012-05-10
Im looking to modify a list of Servers that are in AD.  Like to be able to use a csv or txt file to pull the name from and then have it modify them based on what I need done.  I can do this using a var for one machine and it will prompt me, but want to make sure I can do this for multible machines as well.   I am using the Quest Software "ActiveRoles Management Shell for Active Directory x64".

I have attached a txt file of what I have so far.  I think Imay need to use foreach but not sure where to put it.  I am still a NOOB working with powershell so be nice to me  :-).
decomm-ps-script.txt
0
Comment
Question by:gzugg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:gzugg
ID: 33736023
Just adding a note, when I runt he script without the part for the csv file it works great, so I know the sytax is correct fro that part.  This will give you an option to run for one machine or use a csv file for multible machines to modify.
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 33741751

Something like this...

You'll need PowerShell 2 if you don't have it already.

Chris
# NAME:decommAD.ps1
#
# AUTHOR: George Zugg
# DATE  : 9/22/2010
# 
# COMMENT: This is for the ### domain only.  This script moves a 
# computer object to the retired server OU, changes the server
# object description to say "Remove After (Date)". The date is
# filled in automatically based on todays date plus 30 days out.  
# The final step is to disabled the computer account.
# 
#
# Ver 1.2.7
#
#
#################################################################
## Create necessary variables to use throughout the script for logging

<#
  .Synopsis
    Moves the specified computers to the specified OU
  .Description
    Moves the specified computers to the specified OU
  .Parameter Computer
    A single computer, or list of computers
  .Parameter CSVFile
    Read computer names from a CSV File. File must exist.
  .Parameter ColumnName
    By default  the script will look for a Name column in the CSV file.
  .Parameter Credential
    Credentials used to perform this action
  .Parameter LogFolder
    A folder for log files. Files will be appended with todays date. By default the Log Folder path is C:\scripts\decommAD\logs\.
#>

[CmdLetBinding(DefaultParameterSetName = "ManualList")]
Param(
  [Parameter(ParameterSetName = "ManualList")]
  [String[]]$Computer,
  [Parameter(ParameterSetName = "CSVList")]
  [ValidateScript( { Test-Path $_ } )]
  [String]$CSVFile,
  [Parameter(ParameterSetName = "CSVList")]
  [String]$ColumnName = "Name",
  [Parameter(ParameterSetName = "")]
  [Management.Automation.PsCredential]$Credential,
  [Parameter(ParameterSetName = "")]
  [String]$LogFolder = "C:\Scripts\decommAD\Logs\"
)


$DateTime = Get-Date -Format "dd-MM-yyyy"
$ActivityLog = $logFolder + "decommAD_$DateTime.log"

If (!(Test-Path $logFolder)) { New-Item -Path $logFolder -Type Directory -Force }

$Date = (Get-Date).AddDays(30).ToString("d")

# If explicit credentials are passed
If ($Credential) { Connect-QADService -Credential $Credential }

If ($PsCmdLet.ParameterSetName = "CSVList") {
  $Computer = Import-Csv $CSVFile | ForEach-Object { $_.$ColumnName }
}

Get-Date | Add-Content -Path $ActivityLog 

$Computer | ForEach-Object {
  "Moving Server name to RetiredServer OU" >> $ActivityLog

  $ComputerAccount = Get-QADComputer $_

  Move-QADObject $ComputerAccount.DN -NewParentContainer 'domain.com/Servers/BackOffice/RetiredServers' >> $ActivityLog

  "Adding Description Remove after ($Date)" >> Add-Content -Path $ActivityLog
  Set-QADObject $ComputerAccount.DN -Description "Remove After $Date" >> $ActivityLog

}

Disconnect-QADService

Open in new window

0

Featured Post

IoT Devices - Fast, Cheap or Secure…Pick Two

The IoT market is growing at a rapid pace and manufacturers are under pressure to quickly provide new products. Can you be sure that your devices do what they're supposed to do, while still being secure?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question