option "reset runspase" (?) in PowerGui causes script error

I uploaded in PowerGui editor script that I debugged Up to this time in it, and it worked.
At some point I have done in the editor option "reset runspase". and thereafter
script stopped working and I'm getting many error messages:

Get-WmiObject: Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null o
r empty and then try the command again.
At C: \ Powershell \ Scripts \ Change3.ps1: 7 char: 62
+ $ ObjCompSys = Get-WmIObject-class "Win32_ComputerSystem"-cn <<<< $ machine-EA silentlyContinue-namespace "root \ CIMV2"
     + CategoryInfo: InvalidData: (:) [Get-WmiObject], ParameterBindingValidationException
     + FullyQualifiedErrorId: ParameterArgumentValidationError, Microsoft.PowerShell.Commands.GetWmiObjectCommand

Open in new window

quote the full text of the script:
$Machine = Get-Content -Path C:\powershell\scripts\Computers.txt
$AllComputers = @()
foreach ($Machine in $Machines)


$objCompSys = Get-WmIObject -class "Win32_ComputerSystem" -cn $machine -EA silentlyContinue  -namespace "root\CIMV2"
  $compname = $objCompSys.Name
  $physicalRAM = [Math]::Ceiling($objCompSys.TotalPhysicalMemory / 1GB)
  $CurrentUser = $objCompSys.username   
  $Motherboard = $objCompSys.Model

$objCompOS = Get-WmIObject -class "Win32_OperatingSystem" -cn $machine -EA silentlyContinue  -namespace "root\CIMV2"
 $WindowsVersion = $objCompOS.Caption
 $ServicePack =  $objCompOS.csdversion
 $WinInsDate = $objCompOS.ConvertToDateTime($objCompOS.InstallDate) | Get-Date -Format d                        

$DiskItems = Get-WMIObject -Class Win32_DiskDrive -Filter {DeviceId = '\\\\.\\PHYSICALDRIVE0'} -comp $machine | select -ExpandProperty size
 $DiskSize = $DiskItems/1GB
$NetAdapters = Get-WmIObject -class "Win32_NetworkAdapterConfiguration" -cn $machine  | where{$_.IPEnabled -eq "True"}
 $IPAddress = foreach($Adapter in $Netadapters){$adapter.ipaddress}

$objProc = Get-WMIObject -class "Win32_Processor" -cn $machine 
 $procType = $objProc.Name
 $Object = New-Object PSObject -Property @{
  CompName     = $compname
  WindowsVersion = $WindowsVersion 
  ServicePack = $ServicePack
  WinInsDate = $WinInsDate
  IPAddress = $IPAddress
  CurrentUser = $CurrentUser 
  Motherboard = $Motherboard
  ProcType = $procType
  DiskSize = $DiskSize
  MemoryCapacity = $physicalRAM
 $AllComputers += $Object
$AllComputers | select CompName,IPaddress,WindowsVersion,ServicePack,WinInsDate,CurrentUser,ProcType,Motherboard,DiskSize,MemoryCapacity  | Export-Csv c:\Powershell\change5.csv -NoTypeInformation

Open in new window

I have checked the file on the computer that there are gaps at the end of lines and did not find them.
What do I have to make the script work again
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Meir RivkinFull stack Software EngineerCommented:
unless you set the powergui to "Reset PowerShell runspace each time debugging is started" in Tools ->Options->Debug Options, just restart powergui and u should be run it fine.
nesher13Author Commented:
to sedgwick,

it did not solve my problem
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
The first line contains a typo ($machine instead of $machines). At some time earlier you defined $machines in PowerGUI, and that var was retained until you restarted PowerGUI or used Reset Runspace.
Correct first line is:
$Machines = Get-Content -Path C:\powershell\scripts\Computers.txt

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Please note that "da rulez" say that a precise and complete answer should receive a grade of "A". The answer was spot on, nothing more to add on value, and nothing really obvious, so I would expect "A" here. Is there any reason for the "B"?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.