locked
Using Poweshell Add-Computer on Script startup RRS feed

  • Question

  • Is it possible to user Add-Computer in a Startup script in windows2008r2? 

    The script works after the computer has been boot, however when we added into the startup script it fails. 

    Any other way to do this on startup 

    Friday, August 22, 2014 3:06 PM

Answers

  • Run and RunOnce Registry Keys
    http://msdn.microsoft.com/en-us/library/aa376977(v=vs.85).aspx
    • Marked as answer by ScriptingWife Tuesday, September 16, 2014 6:44 PM
    Friday, August 22, 2014 6:49 PM
  • Then this is really a Windows systems management question, not a scripting question (since your script works).


    -- Bill Stewart [Bill_Stewart]


    • Edited by Bill_Stewart Friday, August 22, 2014 9:05 PM
    • Proposed as answer by Bill_Stewart Friday, August 29, 2014 9:20 PM
    • Marked as answer by ScriptingWife Tuesday, September 16, 2014 6:44 PM
    Friday, August 22, 2014 7:00 PM

All replies

  • Are you saying that you want to try to create a computer account for the computer every time it reboots?

    Why?


    -- Bill Stewart [Bill_Stewart]

    Friday, August 22, 2014 3:19 PM
  • Let me explain a little bit more the question, I know I wasn't clear. 

    I have a EC2 AMI (Amazon Image) which has things preinstalled. Windows instances are created using the image. 

    As part of the image we have some startup script that perform tasks given the instance. As part of this initial setup we want the instance "auto" register to the AD server. 

    Using a powershell script we able to detect whether the instance is part of the domain, if not we added to the domain using Add-Computer. This means that only when the instance is created the script will register to AD, otherwise it will ignore the command. 

    A snipped of the script is:

    if ((gwmi win32_computersystem).partofdomain -eq $true) {
            //DO other things since it is already joined

          }else{
            
            $username = 'user';
            $domain = 'domain.com';
            $password = 'pass';
            $credential = (New-Object System.Management.Automation.PSCredential ($username, (ConvertTo-SecureString $password -AsPlainText -Force)))

            add-computer -domain $domain -credential $credential -OUPath '#{node["ad"]["ou_string"]}' 
            }

    The script is not the issue. The question is when/where to run the script on startup? 

    Any suggestions? 

    Friday, August 22, 2014 6:45 PM
  • Run and RunOnce Registry Keys
    http://msdn.microsoft.com/en-us/library/aa376977(v=vs.85).aspx
    • Marked as answer by ScriptingWife Tuesday, September 16, 2014 6:44 PM
    Friday, August 22, 2014 6:49 PM
  • Then this is really a Windows systems management question, not a scripting question (since your script works).


    -- Bill Stewart [Bill_Stewart]


    • Edited by Bill_Stewart Friday, August 22, 2014 9:05 PM
    • Proposed as answer by Bill_Stewart Friday, August 29, 2014 9:20 PM
    • Marked as answer by ScriptingWife Tuesday, September 16, 2014 6:44 PM
    Friday, August 22, 2014 7:00 PM