Script to Configure newly imaged computers

I will try and outline this in the clearest way possible but it may be confusing so bare with me. Hopefully it makes sense and it can be done, without too much tinkering around.

Currently trying to develop a script to automate some configuration tasks of new computers that were just imaged using a basic menu script that allows the tech to select option 1 and it executes the corresponding task so on and so forth.

Here are some of the tasks:

  1. Running Windows updates with PSWindowsUpdate Module
  2. Change Computer Name
  3. Move New Computer Object from Computers OU to Proper OU
  4. Activate Windows and Office
  5. Join computer to Domain

Now I know the commands in which I need in order to execute these tasks with but I am having a bit of trouble with the logic and the best way to go about it.

  1. Windows update

    import-module PSWindowsUpdate
             Get-WUInstall -NotCategory "Language Packs" -AcceptAll -IgnoreRebootRequired 

    Issue I AM having is that this module only works on the local machine, all well and fine, I can deal with that

  2. Change computer name (Most of these new computers have an image that comes with PS 2.0)

    Set-Variable(Get-WmiObject win32_computersystem).rename($compName); Restart-Computer -Force 

    All well and good here.

  3. Move New Computer Object from Computers OU to Proper OU

    Move-ADObject “CN=$computer,OU=Computers,OU=Faculty,OU=xxxxxx,DC=xxxxx,DC=xxxxx” -TargetPath “OU=Computers,OU=IT Personnel,DC=xxxx,DC=xxxx”

    Now I can import the module to the newly imaged computer, if im doing this from my own machine using:
    <pre class="prettyprint">$session = New-PSSession -ComputerName $computer
            invoke-Command { Import-Module Activedirectory } -Session $session</pre>
    
    But as you can see I cannot figure out a way to logically have both options 1 and 3 in the same script as I need to run the Windows update command locally on the newly imaged computer but I cannot import the Active     Directory module into the newly imaged computer easily without downloading the remote administration toolkit (at least I havent figured out how yet). So I am having this battle with should I try and do this all remotely from my actual computer and just use PSSessions to invoke all these commands or do I make script that I copy to each computer I want to image and run everything locally.
    

Any help will be appreciate, even if its telling me im just running in circles and this script wont benefit anything. Im learning powershell and just trying to help automate some things in my free time

With the exception of moving computer accounts to a different OU, everything you’ve described is already part of the sconfig.vbs script, which is what’s typically used to configure installations of Server Core (typically by typing “sconfig” at a command prompt.) Just thought I’d mention it, in case you don’t feel like reinventing that particular wheel.

And this can be used on a windows 7 workstation?

I haven’t tried that, personally. I did take a quick look through the code, though, and what I saw was all based on command-line tools and COM classes that should work just as well on a workstation. (netdom.exe , whoami.exe, etc.) It’s probably worth a try.

Very interesting. I will see what I can do with it.

ok so I extracted sconfig from server 2012

now im not super familiar with vbs script, but how would I make this run on windows 7? or 8?

Everytime I try to run it, a command window pops up and then it disappears. attached are the files.