Moving Computers to a new OU RRS feed

  • Question

  • hi,

    i'm new to creating scripts and i've flung together a script from a few others we have lying around so i was hoping someone could give me a had with getting it finished.

    i have a script that will take a list of assets from a .CSV and move them all to a quarantine OU that we've had created, i've tested it and it runs without issue, it's just the exported results that i've been having issues with.

    i want it to display something along the lines of

    if the asset was already in that OU to show: "asset already contained within OU"

    if it was sucessfully moved to show: "asset has been moved to OU"

    if the asset doesn't exist in AD to show: "asset could not be located within Active Directory"

    currently it just displays that the "asset has been moved to OU" as i'm not sure how to set it up check and then list the above 


    import-module activedirectory

    $ErrorActionPreference = "silentlycontinue"

    $profile=get-content env:userprofile
    $filename = "move_done"+(get-date -Format ddMMyyyy_HH)+".csv"
    $Spreadsheet = Import-csv -Path $path

    foreach ($Row in $Spreadsheet){
        $AssetNumber = $Row.Machinename
        Get-ADComputer $AssetNumber | Move-ADObject -TargetPath $OU
        Add-Content $profile\desktop\$filename "$AssetNumber, has been Moved to , $OU"

    Read-Host -Prompt "Press Enter to exit"

    any help would be appreciated


    • Moved by Bill_Stewart Friday, July 7, 2017 6:16 PM This is not "scripts on demand"
    Monday, May 15, 2017 11:32 AM

All replies

  • if($c=Get-ADComputer $AssetNumber){
    	$c| Move-ADObject -TargetPath $OU Verbose 4>>$filename
    	"computer not found: $assetnumber" | Out-File $filename -Append


    • Edited by jrv Monday, May 15, 2017 1:32 PM
    Monday, May 15, 2017 1:27 PM