0

I am currently trying to improve on the the current WDS install of Windows 10 that we use for basically all schools that we do sys admin work for.

The install needs to contain some apps and some basic changes here and there. I also need it to join a domain and rename the computer, regardless of the domain name and without entering credentials. I use PowerShell scripts for this I used to use one script for this, it would use the add-computer PowerShell command and rename the computer using -NewName and it would reboot it. This works fine its just that every once in a while it likes to throw errors, so the solution for that is to separate the renaming and joining.

Now the issue I'm having is that it will either join the domain just fine (or change name depending on the order), but will not run the rename script after reboot.

It's not throwing errors and there is nothing to be seen in the logbook, its just not running the script...

I have been working on this for some time and now I honestly don't know where to look or what to try...

I'm running Windows 10 enterprise LTSB x64

<SynchronousCommand wcm:action="
<CommandLine>Powershell.exe -ExecutionPolicy unrestricted -File c:\System\RenameComputer.ps1 </CommandLine>
<Description>Change computername</Description>
<Order>10</Order>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<CommandLine>Powershell.exe -ExecutionPolicy unrestricted -File c:\System\JoinDomain.ps1 </CommandLine>
<Description>Join computer into domain</Description>
<Order>9</Order>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
</FirstLogonCommands>

Scripts im running

Get-WmiObject Win32_NetworkAdapterConfiguration | ForEach-Object { IF($_.IPEnabled -eq "True" -and $_.DNSDomain.Length  -gt  1)  { 
 $Domain = $_.DNSDomain } }
$DomainPass = ConvertTo-SecureString “nope” -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("$Domain\nope" , $DomainPass) 
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$name = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Desired Computer Name ")
$name = $name.ToUpper()
Write-Output $name $Domain $Cred
Rename-Computer -NewName $name -DomainCredential $Cred
Read-Host  "press enter to continue"
Restart-Computer -Force


Get-WmiObject Win32_NetworkAdapterConfiguration | ForEach-Object { IF($_.IPEnabled -eq "True" -and $_.DNSDomain.Length  -gt  1)  { 
$Domain = $_.DNSDomain } }
$DomainPass = ConvertTo-SecureString “nope” -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("$Domain\nope" , $DomainPass) 
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') |  Out-Null
Add-Computer -DomainName $Domain -Credential $Cred 
Read-Host  "press enter to continue"
Restart-Computer -Force
  • The first line of that XML fragment has an unmatched quote; could that be causing the problem? Also try bypass instead of unrestricted for the execution policy. – Ben N Mar 6 '17 at 16:45
  • The unmatched quote got lost in the copy pasta. I changed it to bypass and it changed nothing. I think I will remove the last command and just use powershell to add either the renaming or the domain joining as a runonce register key. – legopc Mar 7 '17 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.