Link to home
Start Free TrialLog in
Avatar of Axis52401
Axis52401Flag for United States of America

asked on

exclude characters when importing from csv

I am trying to write a script that can modify windows permissions for server shares. With one script I am exporting the server shares to a csv, then with this script I am importing the 'path' of the share. The problem is that default shares like C$ and even printers get imported, and that interferes with my script to run.

I need to explicitly deny permission to certain users and the default admin shares come back with a 'permission denied' error, even from an administrative prompt. So the they are getting in the way and I need ideas on how to exclude them.  

Here is an example of the path:
Path
C:\Windows
C:\
Canon MX490 series FAX (Copy 1),LocalsplOnly
Canon MX490 series Printer (Copy 1),LocalsplOnly
Fax - HP Officejet 5740 series,LocalsplOnly
HP Officejet 5740 series,LocalsplOnly

C:\Windows\system32\spool\drivers
C:\share
C:\Users

My thought is that I could import both the Name and Path and exclude any rows that contain the character $.
Example of Name and Path columns:
Name      Path
ADMIN$      C:\Windows
C$      C:\
Canon MX490 series FAX (Copy 1)      Canon MX490 series FAX (Copy 1),LocalsplOnly
Canon MX490 series Printer (Copy 1)      Canon MX490 series Printer (Copy 1),LocalsplOnly
Fax - HP Officejet 5740 series      Fax - HP Officejet 5740 series,LocalsplOnly
HP Officejet 5740 series      HP Officejet 5740 series,LocalsplOnly
IPC$      
print$      C:\Windows\system32\spool\drivers
share      C:\share
Users      C:\Users

Another thought would be to create a variable, that contains the common shares like C$, D$, IPC$, Print$, etc and telling my script to exclude any rows that match that list, but I am not sure how to go about doing that either. Lot's of options here, just looking for the best one.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Axis52401

ASKER

That's exactly what I needed. Your script filters it to just the shares I need. then with a $ServerShares = $ProcessShares | % {$_.Path} I have just the paths!