How to split a loop RRS feed

  • Question

  • Hi,

    I have got this working as I need from a list file. But I want this to run as a startup script on any machine. I am stuck with how to remove the ForEach Computer from list loop. How do I remove this so that it can just run on the fly or as a startup script on any machine?

    Error info:


    An empty pipe element is not allowed.
    At C:\Users\username\Desktop\Computer_Audit.ps1:21 char:3
    +  | <<<<  Sort ComputerName | 
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : EmptyPipeElement


    my.ps1 script


    $bios = Get-WmiObject Win32_BIOS -ComputerName $_
            $cs = Get-WmiObject Win32_ComputerSystem -ComputerName $_
            $date = Get-Date -format "dd-MMM-yyyy"
            $time = Get-Date -format "HH:mm"

            $props = @{
                ComputerName = $_
                Description = $bios.Description
                SerialNumber = $bios.SerialNumber
                Domain = $cs.Domain
                Manufacturer = $cs.Manufacturer
                Model = $cs.Model
                Name = $cs.Name
                NumberOfProcessors = $cs.NumberOfProcessors
                Date = $date
                Time = $time

            New-Object PsObject -Property $props

     | Sort ComputerName | 
            Select ComputerName,SerialNumber,Manufacturer,Model,date,time | 
                Export-Csv "\\server\data_collect\Computer_Audit.csv" -NoTypeInformation



    • Edited by dubla89 Monday, May 20, 2019 12:07 PM
    • Split by jrvModerator Monday, May 20, 2019 5:15 PM New topic
    Monday, May 20, 2019 12:05 PM

All replies

  • There is no "foreach" loop in your code.

    Note that this forum does not modify or fix code that you have found on the Internet.  To post here you must post a script you have written and have studied basic PowerShell.

    If you need someone to write a scrip for you then post here: Forum for Script requests


    Monday, May 20, 2019 6:05 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,


    Just do it.

    Monday, June 3, 2019 7:47 AM