Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11508

Filter data table in Powershell

$
0
0

Hi All,

I have one script, where i have one datatable, from that datatable i want to get data based on one search filter. 

#Get the excel as csv and load in datatable...
$empTable = New-Object System.Data.DataTable;
$empTable = Import-Csv -Path "~\Employee.csv";

#Get only Month column from the data table...
$empMonthTable = New-Object System.Data.DataTable;
$empMonthTable = $empTable | Select-Object -Property "Month";

#Sort the data table...
$sortMonth = New-Object System.Data.DataTable;
$sortMonth = $empMonthTable | Sort-Object -Property Month;

#Get Unique data from data table...
$unqiueMonth = New-Object System.Data.DataTable;
$uniqueMonth = $sortMonth | Select-Object -Unique Month;

#Get data from datatable with unique month...

foreach ($monthData in $uniqueMonth)
{	

[string] $month = $monthData | Out-String;	
$month;	
$eachMonthData = $empTable | Where-Object {$_.Month -eq $month};		
$eachMonthData;
}

Here in output of "$eachMonthData" is returning null table. But if there am putting hardcoded value like "Mar", then table is returning values.

Could you please suggest me how to achieve this?


Viewing all articles
Browse latest Browse all 11508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>