Skip to content

Instantly share code, notes, and snippets.

@1RedOne

1RedOne/About.md

Last active Jan 24, 2018
Embed
What would you like to do?
Glorious PowerShell Dashboard Files
param($i = $Global:i)
if ($i -eq $null){$i = 8080}
$i++
$Colors = @{
BackgroundColor = "#FF252525"
FontColor = "#FFFFFFFF"
}
$NavBarLinks = @((New-UDLink -Text "<i class='material-icons' style='display:inline;padding-right:5px'>favorite_border</i> PowerShell Pro Tools" -Url "https://poshtools.com/buy-powershell-pro-tools/"),
(New-UDLink -Text "<i class='material-icons' style='display:inline;padding-right:5px'>description</i> Documentation" -Url "https://adamdriscoll.gitbooks.io/powershell-tools-documentation/content/powershell-pro-tools-documentation/universal-dashboard.html"))
Start-UDDashboard -port $i -Content {
New-UDDashboard -NavbarLinks $NavBarLinks -Title "FoxDeploy Space Management Dashboard - Photos" -NavBarColor '#FF1c1c1c' -NavBarFontColor "#FF55b3ff" -BackgroundColor "#FF333333" -FontColor "#FFFFFFF" -Content {
New-UDRow {
New-UDColumn -size 4 {
New-UDImage -Url http://localhost/Foxdeploy_DEPLOY_large.png
}
New-UDColumn -Size 4 {
New-UDCounter -Title "Total Bytes Saved" -AutoRefresh -RefreshInterval 3 -Format "0.00b" -Icon cloud_download @Colors -Endpoint {
get-content c:\temp\picSpace.txt
}
}
New-UDColumn -Size 4 {
New-UDCounter -Title "Total Files Moved" -Icon file @colors -Endpoint {
get-content C:\temp\totalmoved.txt
}
}
}
New-UDRow {
New-UDColumn -size 6 {
New-UDGrid -Title "$((import-csv C:\temp\movelog.csv)[-1].Files) Files Moved Today" @Colors -Headers @("BaseName", "Directory", "Extension", "FileSize") -Properties @("BaseName", "Directory", "Extension", "FileSize") -AutoRefresh -RefreshInterval 20 -Endpoint {
dir g:\backups\file*.csv | sort LastWriteTime -Descending | select -First 1 -ExpandProperty FullName | import-csv | Out-UDGridData
}
}
New-UDColumn -Size 6 {
New-UDChart -Title "Files moved by Day" -Type Line -AutoRefresh -RefreshInterval 7 @Colors -Endpoint {
import-csv C:\temp\movelog.csv | Out-UDChartData -LabelProperty "Day" -DataProperty "Files" -Dataset @(
New-UDChartDataset -DataProperty "Jpg" -Label "Photos" -BackgroundColor "rgb(134,342,122)"
New-UDChartDataset -DataProperty "MP4" -Label "Movies" -BackgroundColor "rgb(234,33,43)"
)
}
}
}
}
}
Start-Process http://localhost:$i
Day Files Jpg MP4
0 15 13 2
1 77 70 7
2 23 20 3
3 13 10 3
4 8 7 1
5 2 1 1
6 5 5 0
7 17 17 0
8 0 0 0
9 3 3 0
10 0 0 0
11 8 6 2
12 103 94 9
13 198 195 3
14 54 54 0
15 11 11 0
16 0 0 0
####User Params Here ##################################
# Path to the Create-Dashboard.ps1 file
$PathToCreateDashboard = "C:\Users\Stephen\Dropbox\My Code\Powershell\Dashboard\Create-BlogDashboard.ps1"
# \/ This should be the path to your Dropbox camera Uploads folder
$cameraFolder = "C:\Users\Stephen\Dropbox\Camera Uploads"
# \/ Files are MOVED from your Dropbox folder to this path
$BackupFolder = "g:\Photos\LG g4"
# \/ Place to create status reports
$StatusReportPath = "g:\backups"
# \/ Specify the maximum age of files in days here. Anything older than this is moved out of the $cameraFolder path
$MoveFilesOlderThanAge = "-18"
####End user params #####################################
$cutoverDate = ((get-date).AddDays($MoveFilesOlderThanAge))
$backupFiles = new-object System.Collections.ArrayList
$filesToMove = Get-ChildItem $cameraFolder | Where-Object LastWriteTime -le $cutoverDate
$itemCount = $filesToMove | Measure-Object | select -ExpandProperty Count
$FileSize = $filesToMove | Measure-Object -Sum Length
if ($itemCount -eq 0){return}
write-host "Moving files older than $cutoverDate, of which there are `n`t`t`t`t" -nonewline
write-host -fore yellow $itemcount
[int](gc c:\temp\picSpace.txt) + [int]$FileSize.Sum | Set-content c:\temp\picSpace.txt
[int](gc c:\temp\totalmoved.txt) + [int]$itemCount | set-content c:\temp\totalmoved.txt
$movelog = import-csv c:\temp\movelog.csv
"$([int]$movelog[-1].Day+1),$itemCount,$(($filesToMove | ? Extension -ne .mp4).Count),$(($filesToMove | ? Extension -eq .mp4).Count)" | Add-Content C:\temp\movelog.csv
$filesToMove | ForEach-Object {
[void]$backupFiles.Add((Move-Item -Destination $BackupFolder -Path $_.FullName -PassThru -Force| select BaseName,Extension,@{Name=FileSize;Expression={"$([math]::Round($_.Length / 1MB)) MB"}},Length,Directory))
Start-Sleep -Milliseconds 25
}
$companyLogo = '<div align=left><img src="http://127.0.0.1/Style/logo.png"></div>'
$header = @"
<link rel="stylesheet" type="text/css" href="http://127.0.0.1/Style/style.css" />
$companyLogo
<h1>File export from Dropbox Report</h1>
<p>The following automated report was generated at $(Get-Date) and contains the $itemcount files which were older than
$([math]::Abs($MoveFilesOlderThanAge)) days. <Br><Br>This backup job was executed on System: $($Env:Computername)</p>
<hr>
"@
$post = @"
<h3>These items were moved to <b>$BackupFolder</b> for archiving to Azure</h3>
"@
$backupFiles | select BaseName,Extension,@{Name=FileSize;Expression={"$([math]::Round($_.Length / 1MB)) MB"}},Length,Directory | export-csv -NoTypeInformation "G:\Backups\FileList__$((Get-Date -UFormat "%Y-%m-%d"))_Log.csv"
$HTMLbase = $backupFiles | ConvertTo-Html -Head $header `
-Title ("Dropbox Backup Report for $((Get-Date -UFormat "%Y-%m-%d"))") `
-PostContent $post
$HTMLbase | out-file $StatusReportPath\DropboxBackup_$((Get-Date -UFormat "%Y-%m-%d"))_Log.html
& $PathToCreateDashboard -i (get-random -min 8230 -Maximum 8450)
read-host "Press any button to exit (will close the window)"
timeout 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment