Import-Csv SomeFile.csv
Given that it's a scripting language you can perform pretty much whatever calculations you can imagine. Of course, you'll have to define what you hope to have for a more realistic example. Import-Csv FileName.csv | Select-Object *, @{n='PingResponds';e={ Test-Connection $_.'IP Hostname' -Quiet -Count 1 }}
That can be exported to another CSV file as follows:Import-Csv FileName.csv | Select-Object *, @{n='PingResponds';e={ Test-Connection $_.'IP Hostname' -Quiet -Count 1 }} | Export-Csv FIleName-Updated.csv -NoTypeInformation
Cheers,$InputFile = "C:\Temp\Scripts\devinv.csv"
$Software = Get-Content $InputFile | Select -Skip 12 | ConvertFrom-CSV
$Software | Group-Object "Device Model" | Where {$_.Name.Trim() -ne ''} | Select Name, Count | Sort Count -Descending | Format-Table -AutoSize
$InputFile = "C:\Temp\Scripts\devinv.csv"
$Software = Get-Content $InputFile | Select -Skip 12
$Software[0] = "NullCol" + $Software[0]
$Software = $Software | ConvertFrom-CSV
$Software | Group-Object "Device Model" | Where {$_.Name.Trim() -ne ''} | Select Name, Count | Sort Count -Descending | Format-Table -AutoSize
-----------------------------------------------------------------------------------
Result
-------------------------------------------------------------------------------
PS C:\temp\Scripts> .\Metrics.ps1
Name Count
---- -----
Xerox WorkCentre 7732 v 71. 1. 0 Multifunction System 102
HP LaserJet 7220 70
HP Color LaserJet 7700 58
HP LaserJet 7320 52
HP LaserJet 7300 24
HP Officejet Pro X276dw MFP 23
HP Color LaserJet 7620 23
HP Color LaserJet 7600 16
HP LaserJet 7200 16
Xerox WorkCentre 7832 v1 Multifunction System 14
HP LaserJet 1320 14
HP LaserJet P2012 Series 14
HP LaserJet 7020 10
FUJI XEROX ApeosPort-IV C3372 v 82. 70. 0 Multifunction System 7
Xerox WorkCentre 7872 v1 Multifunction System 6
FUJI XEROX ApeosPort-IV C3372 v 87. 2. 0 Multifunction System 6
Dell Color Laser 2110cn 5
HP LaserJet 700 color MFP M772 5
HP LaserJet 700 color M721nw 5
Xerox WorkCentre 7272 v1 Multifunction System 3
FUJI XEROX DocuCentre-IV C3372 v 87. 8. 0 Multifunction System 3
HP Color LaserJet 3600 3
HP LaserJet 7000 3
HP LaserJet 7100 3
HP Color LaserJet M621 3
HP LaserJet 8120 3
FUJI XEROX DocuCentre-IV C3372 v 82. 23. 0 Multifunction System 3
FUJI XEROX DocuPrint C1190 FS; Net 12.27,ESS 200907031207 3
$InputFile = "C:\Temp\Scripts\devinv.csv"
$Software = Get-Content $InputFile | Select -Skip 12
$Software[0] = "NullCol" + $Software[0]
$Software = $Software | ConvertFrom-CSV
$arrRanges = [ordered]@{
'0 Pages' = '0'
'1-50 Pages' = '1..50'
'51-100 Pages' = '5..100'
'101-1000 Pages' = '101..1000'
'1001-5000 Pages' = '1001..5000'
'5001-10000 Pages' = '5001..10000'
'** Pages' = '**'
}
$Totals = $null
$arrRanges.GetEnumerator() | ForEach {
$Name = $_.Name
If ($_.Value -eq '**') {
$Expression = "`$Totals += `$Software | Where {`$_.Total -eq '$($_.Value)'} | Select @{n='Name';e={'$Name'}},@{n='PageCount';e={`$_.Total}}"
} Else {
$Expression = "`$Totals += `$Software | Where {`$_.Total -ne '**' -and [int]`$_.Total -in $($_.Value)} | Select @{n='Name';e={'$Name'}},@{n='PageCount';e={`$_.Total}}"
}
Invoke-Expression $Expression
}
$Totals | Group Name | Select Name,Count | Format-Table -AutoSize
integrate these short scripts with GUI(page)Since you have a solution to this question, you should post a new question about the GUI.
$InputFile = "C:\Temp\Scripts\devinv.csv"
$Software = Get-Content $InputFile | Select -Skip 12
$Software[0] = "NullCol" + $Software[0]
$Software = $Software | ConvertFrom-CSV
$Software | Group {
If ("($_.'Install Date')") {
$Date = $_.'Install Date'.Split('/')
If (($Date.Length)-1 -eq 0) {
$Date
} else {
$Date[2].Split(' ')[0]
}
}
} | Sort Name |
Select Count,Name,@{n='Hostname';e={($_.Group.'IP Hostname' | Get-Unique) -join ","}},
@{n='IP Address';e={($_.Group.'IP Address' | Get-Unique) -join ","}},
@{n='Device Model';e={($_.Group.'Device Model' | Get-Unique) -join ","}} | Out-GridView
I can generate spread sheet but then i would like embed excel spreadsheet in webpage and run on the background powershell to pull numbers by tab names
So, if i would like to find out how many printers are on the generated spread i will select total printer count
If i would like to find out how many printer per device groups (EUR, AMERICA) i would select total printer per device groups.Same think with total page count. (total 0 pages: XXX ; total 1-50 pages: XXX; total 51-100 pages: XXX and so on.
Instead of going to spread sheet and looking for the data manually I would like to select these tabs on webpage that would run script against excel file to pull correct info.