• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 469
  • Last Modified:

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
  • 2
1 Solution
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
QlemoBatchelor and DeveloperCommented:
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

QlemoBatchelor and DeveloperCommented:
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"?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now