Hello Folks,
I am trying to read csv file using PowerShell which has values like 100 GB (107,374,182,400 bytes) or 50 GB (53,687,091,200 bytes) and column name like ProhibitSendReceiveQuota. I tried below code just for a test but it is not working and no error as well
foreach ($line in (Import-Csv "C:\Temp\data.csv"))
{
# Check if the 'ProhibitSendReceiveQuota' value in the line is 50 GB
if ($line.ProhibitSendReceiveQuota -eq "50 GB")
{
#If ProhibitSendReceiveQuota is 50 GB then store output in csv file
$line.Alias | Out-File -FilePath "C:\Temp\Test_50GB.csv" -Append
}
}
I even tried using pattern like below
$csv = Import-Csv "C:\Temp\data.csv"
$pattern = "^.*?ProhibitSendReceiveQuota Size: (?50\d+(?:\.\d+){0,1}.*)$"
$csv | Select-String -Pattern $pattern
And I got error -
Select-String : The string ^.*?ProhibitSendReceiveQuota Size: (?50\d+(?:\.\d+){0,1}.*)$ is not a valid regular expression: parsing
"^.*?ProhibitSendReceiveQuota Size: (?50\d+(?:\.\d+){0,1}.*)$" - Unrecognized grouping construct.
At line:1 char:17
+ $finds = $csv | Select-String -Pattern $pattern
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Select-String], ArgumentException
+ FullyQualifiedErrorId : InvalidRegex,Microsoft.PowerShell.Commands.SelectStringCommand
How can I achieve this? Any help in this regards is greatly appreciated.
Thank you
Abhay
Abhay