Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Powershell 3.0

$
0
0

Hey Guys.  Kind of new here, but have been doing some coding (or attempting to).  I've ran into a snag and not sure where to go from here.  The below code does not output into my CSV file.  I've tried set-content and a bunch of other different parameters.  I guess my question is can I have the code below be executed inside of an Expression. 

 

If I were to change the line "testing" to write-host "testing"  It would display 2 results (which is the same amount of computers in my csv file containing "WHIT"

 

$ImportAll = import-csv C:\temp\noncurrent.csv
$ImportAll | select name | Select *,@{Name="DSAgent";Expression={
foreach-object{
            if($_.name.startswith("WHIT"))
                {
                 "testing"
                }
        }
     Else
        {
                 "null"
                }
     End
}},@{Name="Ticket Title";Expression={'SCCM Client Update for ' + $_.name}} | sort-object -property name, ws -descending | export-csv C:\temp\exported2.csv -notype


Viewing all articles
Browse latest Browse all 6937

Trending Articles