-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathParse-LineDelimFiles.ps1
55 lines (41 loc) · 1.29 KB
/
Parse-LineDelimFiles.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<#
.Description
This script parses multiple line deliminated files into a CSV.
Function: Parse-Files
Author: Matt Kelly, @breakersall
Required Dependencies: PSv3
.PARAMETER Directory
Specify the directory to make into CSV.
.PARAMETER Extension
Specify the extension to parse into a CSV, example _local_admins.txt.
.PARAMETER Extension
Specify the extension to parse into a CSV, example _local_admins.txt.
.PARAMETER Output
Specify the output file, example -Output local_admins.csv.
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false,
HelpMessage='Specify the directory to make into CSV, example: C:\Temp')]
[ValidateScript({Test-Path $_})]
[string]$Directory,
[Parameter(Mandatory=$false,
HelpMessage='Specify the extension to parse into a CSV, example _local_admins.txt')]
[string]$Extension,
[Parameter(Mandatory=$false,
HelpMessage='Specify the output file, example -Output local_admins.csv')]
[string]$Output
)
$Files = Get-ChildItem $Directory\*$Extension | Select-Object -ExpandProperty Name
foreach ($File in $Files)
{
cd $Directory
$admins = get-content $Directory\$File
[string]$line2
$Compname = $File.replace("$Extension","")
foreach ($admin in $admins)
{
$line = $Compname + "," + $admin
$line | Out-File -Encoding ASCII -Append $Output
}
}