1

I want to remove [Company]:IT Test column. But no luck.

input CSV file :

[Company]:IT Test,[CompanyXYZ]:IT Test12,[CompanyXY]:IT Test222
data11,tst11,user11
data23,tst44,user44

my desired output:

[CompanyXYZ]:IT Test12,[CompanyXY]:IT Test222
tst11,user11
tst44,user44

Script :

Import-Csv 'C:\input.csv' -Delimiter "," | Select * -ExcludeProperty '[Company]:IT Test' |
    Export-Csv "c:\output.csv" -Delimiter "," -Encoding UTF8 -notypeinfo

1 Answer 1

1

By looking at the source code of Select-Object Cmdlet, the value of ExcludeProperty is first compiled as a wildcards pattern before performing the matching. See the relevant part of source code here.

As per the official about_Wildcards docs, powershell supports following set of wildcards.

Wildcard Description Example Match No Match
* Match zero or more characters a* aA, ag, Apple banana
? Match one character in that position ?n an,in, on ran
[ ] Match a range of characters [a-l]ook book, cook, look took
[ ] Match specific characters [bc]ook book, cook hook
`* Match any character as a literal (not a wildcard character) 12`*4 12*4 1234

Since [ ] is part of wildcard pattern syntax you need to escape it using ` to literally match with []

select * -ExcludeProperty '`[Company`]:IT Test'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.