I have the following code which in this script is just copying some files over, gathering some variables and re-naming a computer. The script would only work in ISE so I set it to -STA but I am now getting the following error also.
set-executionpolicy Bypass -Force
New-Item -Path C:\Temp\ -ItemType directory
Copy-Item "\\folder\Onboarding" -Destination "C:\Temp\" -Recurse
$credential = Get-Credential -Credential "domain.local\"
$credential.Password | ConvertFrom-SecureString | Set-Content c:\temp\onboarding\cred.txt
$credential.Username | Set-Content c:\temp\onboarding\user.txt
#Gather Info
$localname = Read-Host "Please Enter Local Admin User Name: "
$localpw = Read-Host "Please Enter Local Admin Password: "
$floorou = Read-Host 'What floor will the user be in:'
$Username = Read-Host 'Employee Username'
$Domainpw = Read-Host 'Employee Password'
$name = Read-Host "Please Enter ComputerName: "
$obj = new-object psobject -Property @{
LocalName = $localname
LocalPW = $localpw
Floor = $floorou
User = $Username
DomainPW = $Domainpw
ComputerName = $name
}
if ($obj.PercentFree -lt 10) {
$obj | Format-Table LocalName,LocalPW,Floor,User,DomainPW,ComputerName
$i++
}
$obj | Export-csv "C:\Temp\Onboarding\variables.csv" -notype
# rename the computer
$Computer = Get-WmiObject Win32_ComputerSystem
$Computer.Rename($name)
echo "Renaming Computer...."
#reboot
Write-Host "Rebooting Computer..." -foregroundcolor "magenta"
#Set Auto Login
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value 1
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value $localname
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value $localpw
Copy-Item "C:\Temp\Onboarding\RunScripts\Run1.bat" -Destination "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\"
shutdown /f /r
The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not in the correct sequence. This is likely caused by a user-specified "format-table" command which is conflicting with the default formatting.
+ CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperationException
+ FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand