So that worked except it doesn't matter if I hit Y or N, it repeats the script. I replaced "Run yours script here" with my script and that's it.
In fact, here's the script I'm inserting:
-----------------------------------------------------------------------------------------------
$choices = [System.Management.Automation.Host.ChoiceDescription[]] @("&Y","&N")
while ( $true ){
$userinput = Read-Host "Input Hostname"
$ArrComputers = $userinput
#Specify the list of PC names in the line above. "." means local system
foreach ($Computer in $ArrComputers)
{
$computerSystem = get-wmiobject Win32_ComputerSystem -Computer $Computer
$computerBIOS = get-wmiobject Win32_BIOS -Computer $Computer
$computerOS = get-wmiobject Win32_OperatingSystem -Computer $Computer
$computerCPU = get-wmiobject Win32_Processor -Computer $Computer
write-host "System Information for: " $computerSystem.Name -BackgroundColor DarkCyan
"-------------------------------------------------------"
"Manufacturer: " + $computerSystem.Manufacturer
"Model: " + $computerSystem.Model
"Serial Number: " + $computerBIOS.SerialNumber
"CPU: " + $computerCPU.Name
"RAM: " + "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
"Operating System: " + $computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
"User logged In: " + $computerSystem.UserName
"Last Reboot: " + $computerOS.ConvertToDateTime($computerOS.LastBootUpTime)
""
"-------------------------------------------------------"
$choice = $Host.UI.PromptForChoice("Repeat the script?","",$choices,0)
if ( $choice -ne 0 ) {
break
}
}
}
--------------------------------------------------------------------------------------------------------
- Edited by USMCGrunt0307 10 hours 29 minutes ago
So that worked except it doesn't matter if I hit Y or N, it repeats the script. I replaced "Run yours script here" with my script and that's it.
In fact, here's the script I'm inserting:
-----------------------------------------------------------------------------------------------
$choices = [System.Management.Automation.Host.ChoiceDescription[]] @("&Y","&N")
while ( $true ){
$userinput = Read-Host "Input Hostname"
$ArrComputers = $userinput
#Specify the list of PC names in the line above. "." means local system
foreach ($Computer in $ArrComputers)
{
$computerSystem = get-wmiobject Win32_ComputerSystem -Computer $Computer
$computerBIOS = get-wmiobject Win32_BIOS -Computer $Computer
$computerOS = get-wmiobject Win32_OperatingSystem -Computer $Computer
$computerCPU = get-wmiobject Win32_Processor -Computer $Computer
write-host "System Information for: " $computerSystem.Name -BackgroundColor DarkCyan
"-------------------------------------------------------"
"Manufacturer: " + $computerSystem.Manufacturer
"Model: " + $computerSystem.Model
"Serial Number: " + $computerBIOS.SerialNumber
"CPU: " + $computerCPU.Name
"RAM: " + "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
"Operating System: " + $computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
"User logged In: " + $computerSystem.UserName
"Last Reboot: " + $computerOS.ConvertToDateTime($computerOS.LastBootUpTime)
""
"-------------------------------------------------------"
$choice = $Host.UI.PromptForChoice("Repeat the script?","",$choices,0)
if ( $choice -ne 0 ) {
break
}
}
}
--------------------------------------------------------------------------------------------------------
- Edited by USMCGrunt0307 Saturday, June 20, 2015 8:40 PM
That is because the break statement terminates your foreach loop, not the while loop.
You don't need a foreach loop in your script, unless you also want to create code that splits the input into an array.
Take out the foreach loop and just repeat for one computer at a time.