Script to Configure newly imaged computers

Tagged: ,

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of Michael Orellana Michael Orellana 2 years, 2 months ago.

  • Author
    Posts
  • #19076
    Profile photo of Michael Orellana
    Michael Orellana
    Participant

    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:

    $session = New-PSSession -ComputerName $computer
                   invoke-Command { Import-Module Activedirectory } -Session $session

    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

  • #19077
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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.

  • #19078
    Profile photo of Michael Orellana
    Michael Orellana
    Participant

    And this can be used on a windows 7 workstation?

  • #19079
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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.

  • #19080
    Profile photo of Michael Orellana
    Michael Orellana
    Participant

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

  • #19108
    Profile photo of Michael Orellana
    Michael Orellana
    Participant

    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.

You must be logged in to reply to this topic.