Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBookV2
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
Using .Net
»
Slideshow
Using .Net Slideshow
Share
|
Browse Library
Module Library
QuickClick Library
Script Library
Active Directory
BizTalk
Citrix
Clustering
Desktop
Exchange Server 2003
Exchange Server 2007
File System
Group Policy
Internet Information Server (IIS)
Local Accounts
Logs
Microsoft Office
Microsoft Team Foundation Server
MySQL
Networking
Registry
Remote Desktop Services
Remoting
Security
SharePoint
SQL Server
System Center Virtual Machine Manager
System Center Configuration Manager
System Center Operations Manager
Tutorial
Terminal Server
Using .Net
Virtual Server
VMware
Windows 7
Windows HPC
Windows Server 2000
Windows Server 2003
Windows Server 2008
Windows XP
WMI
Misc
Snippet Library
Video Library
Members Only
Tags
Get Leap Year
View more
Convert and Compare CSVs
Function
convertToCSV {
Param
([
string
]
$toConvert
)
$excel
=
New-Object
-ComObject
"Excel.Application"
$workBook
=
$excel
.
workbooks.open
(
$toConvert
)
if
(
$toConvert
-match
".xlsx"
){
$global:target
=
$toConvert
.
replace
(
".xlsx"
,
".csv"
)}
else
{
$target
=
$toConvert
.
replace
(
".xls"
,
".csv"
)}
$workBook
.
SaveAs
(
$target
,6)
$excel
.
displayalerts
=
$False
$excel
.
quit
()
}
$toConvert
=
Read-Host
"Type the path of the excel file"
convertToCSV
$toConvert
$converted
=
Import-Csv
-Path
$target
Get-Process
|
Export-Csv
"d:\myTools\Compare\toCompare.csv"
###
### Change this for your needs. Get-Process is just an example.
$toCompare
=
Import-Csv
-Path
"d:\myTools\Compare\toCompare.csv"
###
$newCSV
=
New-Object
System.Collections.ArrayList
for(
$i
=
0;
$i
-lt
$converted
.
length
;
$i
++
){
for(
$j
=
0;
$j
-lt
$toCompare
.
length
;
$j
++
){
if
(
$converted
[
$i
].
processname
-eq
$toCompare
[
$j
].
processname
){
## Also change here to attend your requirements
if
(
!
$newCSV
.
contains
(
$converted
[
$i
])){
$newCSV
.
add
(
$converted
[
$i
]) |
Out-Null
}}
}}
$newCSV
|
Export-Csv
d:\myTools\Compare\
newCSV.csv
## Change here as well.
Loading...
Convert and...
Send emails
Get-DateTime
Get-LeapYear
Get-BillTotal
Get-MachineConfig
Get-Stack
Clear-Stack
Use-Queue
Show-QueueProperties
View all files
Copyright 2011 PowerShell.com. All rights reserved.