locked
exclude data with Export-csv RRS feed

  • Question

  • I am using a workflow and within the workflow I use pscustomobjects.  The get-wmiobject information I get from each machine is there in my .csv file but I also see 3 additional columns.   PSComputerName PSShowComputerName PSSourceJobInstanceId

    How do I exclude these from being written to the .csv file?

    workflow Get-PCData {
    
    $computers = (Get-ADComputer -Filter * -SearchBase "ou=Test,dc=company,dc=org").Name
    
    
    ForEach -Parallel -ThrottleLimit 5000 ($machine in $computers) {
    
    
    if (Test-Connection -ComputerName $machine -Count 1 ) {
    
        $ComputerInfo = Get-WMIObject -class Win32_ComputerSystem -PSComputerName $machine -Property *
        $computerName = $ComputerInfo.name
        $computerModel = $ComputerInfo.Model
        $osInfo= Get-WMIObject -Class Win32_Operatingsystem -PSComputerName $machine
        $getip = ([version](Test-Connection $machine -Count 1).IPV4Address.IPAddressToString).Build; 
        $desc = (Get-ADComputer $machine -Properties Description).description
        $BiosInfo = Get-WmiObject -Class Win32_BIOS -PSComputerName $machine -Property *
        $BIOSVer = $BiosInfo.SMBIOSBIOSVersion
        $BIOSMan = $BiosInfo.Manufacturer
        
    
        [PSCustomObject]@{
            PCName=$computerName
            'OS Version'=$osInfo.Version
            'OS Type'=$osInfo.Caption
            'IP vLan'=$getip
            'Description'=$desc
            'Manufacturer'=$BIOSMan
            'Model'=$computerModel
            'BIOS Version'=$BIOSVer
        
        }
    }}}
    
    
    Get-PCData | export-csv "c:\temp\PCData.csv" -NoTypeInformation 


    mqh7

    Thursday, July 13, 2017 4:54 PM

All replies

  • Select-Object * -Exclude PSComputerName,PSShowComputerName,PSSourceJobInstanceId

    \_(ツ)_/

    Thursday, July 13, 2017 5:00 PM
  • You say it is the Get-WMIObject that is giving you the extra properties, but you have three different calls, so which everyone it is why not pipe over to Select-Object and select only the properties you want?

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Thursday, July 13, 2017 5:02 PM
  •     $BiosInfo = Get-WmiObject -Class Win32_BIOS -PSComputerName $machine -Property *
        $BIOSVer = $BiosInfo.SMBIOSBIOSVersion
        $BIOSMan = $BiosInfo.Manufacturer

    Hi, you said to use select-object, isn't that what I'm basically doing above?  I then write this out in the PSCustomObjects

    'Manufacturer'=$BIOSMan
    'BIOS Version'=$BIOSVer


    mqh7

    Thursday, July 13, 2017 5:18 PM
  • Heads up.

    All collections returned from a workflow have the workflow identities added.  They can be filtered as noted above.

    There is also a command line switch on the workflow call that will remove them.

    They cannot be removed inside the workflow.


    \_(ツ)_/

    Thursday, July 13, 2017 5:21 PM
  • I repeat ...  it must be done outside of the workflow. 

    \_(ツ)_/

    Thursday, July 13, 2017 5:22 PM