You've probably resolved this - but here is what I do here.
"# Get the ID and security principal of the current user account$myWindowsID=[system.Security.Principal.WindowsIdentity]::GetCurrent()$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID) # Get the security principal for the Administrator role$adminRole=[system.Security.Principal.WindowsBuiltInRole]::Administrator # Check to see if we are currently running "as Administrator"if ($myWindowsPrincipal.IsInRole($adminRole)) { # We are running "as Administrator" - so change the title and background color to indicate this $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)" $Host.UI.RawUI.BackgroundColor = "DarkBlue" clear-host }else { # We are not running "as Administrator" - so relaunch as administrator # Create a new process object that starts PowerShell $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell"; # Specify the current script path and name as a parameter $newProcess.Arguments = $myInvocation.MyCommand.Definition; # Indicate that the process should be elevated $newProcess.Verb = "runas"; # Start the new process [system.Diagnostics.Process]::Start($newProcess); # Exit from the current, unelevated, process exit } # Run your code that needs to be elevated here#rename Computer to Lab+S/NWrite-Host "Renaming PC"$computername = Get-Content env:computername$servicetag = Get-WmiObject win32_bios | Select-Object -ExpandProperty SerialNumberIf ($computername -ne $servicetag) { Write-Host "Renaming computer to Lab-$servicetag..." Rename-Computer -NewName "Lab-$servicetag" }Else { Write-Host "Done Renaming PC" }#Place script2.ps1 in Run once for rebootWrite-Host "Setting Registry Commands for Next Reboot..."Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce -Name final -Value "C:\WINDOWS\SYSTEM32\WindowsPowershell\v1.0\powershell.exe C:\SETUP\script2.ps1"Write-Host "Script2 added!"#Read-Host 'Please press ENTER' | Out-NullRestart-Computer
#Join PC to DomainWrite-Host "Joining Domain"$cred = New-Object System.Management.Automation.PsCredential("*YouRDomainHere*\*YourDomainLoginIdHere*", (ConvertTo-SecureString "Domainloginpasswordhere" -AsPlainText -Force))Add-Computer -DomainName "EnteryourDomainhere" -Credential $credWrite-Host "Computer added to domain"#Activate WindowsWrite-Host "Activating Windows"cscript.exe //B c:\windows\system32\slmgr.vbs /ipk xxxxx-cxxxx--xxxxx-xxx-(enter your key here)cscript.exe //B c:\windows\system32\slmgr.vbs /atoWrite-Host "Windows is now activated"#Activating office productscscript "C:\Program Files (x86)\Microsoft Office\Office16\ospp.vbs" /actWrite-Host "Office Products are now activated"Start-Sleep -s 5# Install the Semantic Antivirus agent -- do not update on install and reboot now.Write-Host "Installing SEP"Start-Process "C:\setup\Sep\Sep64.msi" /QN -Wait#Wait for the install to completeWrite-Host "Done installing Symantec Endpoint Protection!! Will reboot shortly"Start-Sleep -s 10# Deactivating Administrator account net user administrator /active:no# Now rebootWrite-Host "Rebooting..."#Read-Host 'Please press ENTER' | Out-NullRestart-Computer