Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName PresentationCore,PresentationFramework
$form = New-Object System.Windows.Forms.Form
$form.Text = 'File size and count'
$form.Size = New-Object System.Drawing.Size(300,200)
$form.StartPosition = 'CenterScreen'
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,120)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150,120)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = 'Please Enter Top Level File Path Below:'
$form.Controls.Add($label)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(10,40)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox)
$form.Topmost = $true
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $textBox.Text
$x
}
#script logic
$location = $x
$folders = Get-ChildItem -Path $location -Recurse -Directory
$array = @()
foreach ($folder in $folders)
{
$foldername = $folder.FullName
# Find files in sub-folders
$files = Get-ChildItem $foldername -Attributes !Directory
# Calculate size in MB for files
$size = $Null
$files | ForEach-Object -Process {
$size += $_.Length
}
$sizeinmb = [math]::Round(($size / 1mb), 1)
# Add pscustomobjects to array
$array += [pscustomobject]@{
Folder = $foldername
Count = $files.count
'Size(MB)' = $sizeinmb
}
}
#Get date
$date=get-date -Format M.d.yyyy
$datepath = "$date"+"-file_report.csv"
# Generate Report Results in your Documents Folder
$array|Export-Csv -Path $env:USERPROFILE\documents\$datepath -NoTypeInformation
$path = "$env:USERPROFILE\documents\$datepath"
$ButtonType = [System.Windows.MessageBoxButton]::OK
$MessageboxTitle = “File size and count”
$Messageboxbody = "Reports should be available here: $path"
$MessageIcon = [System.Windows.MessageBoxImage]::Information
[System.Windows.MessageBox]::Show($Messageboxbody,$MessageboxTitle,$ButtonType,$messageicon)
# SIG # Begin signature block
# MIIQTwYJKoZIhvcNAQcCoIIQQDCCEDwCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUuX1bimYYJzu99YhZg2QvtHJB
# oZWggg0uMIIGbTCCBFWgAwIBAgIQbHhbaf7xO+Fe08DSLHaMejANBgkqhkiG9w0B
# AQsFADBWMQswCQYDVQQGEwJQTDEhMB8GA1UEChMYQXNzZWNvIERhdGEgU3lzdGVt
# cyBTLkEuMSQwIgYDVQQDExtDZXJ0dW0gQ29kZSBTaWduaW5nIDIwMjEgQ0EwHhcN
# MjEwNzMwMTI1NjEwWhcNMjIwNzMwMDY1OTQyWjCBkjELMAkGA1UEBhMCUk8xEDAO
# BgNVBAcMB0NoaWFqbmExHjAcBgNVBAoMFU9wZW4gU291cmNlIERldmVsb3BlcjEu
# MCwGA1UEAwwlT3BlbiBTb3VyY2UgRGV2ZWxvcGVyLCBBbmRyZWkgUmFjaGl0YTEh
# MB8GCSqGSIb3DQEJARYSYW5kcmVpQHJhY2hpdGEubmV0MIIBojANBgkqhkiG9w0B
# AQEFAAOCAY8AMIIBigKCAYEAlNccrTm7x5vOwO4gPPyzLN7m61P8sv7I/Etma8Li
# zL48HeTFAyVPT7nfd4nUEO6hEkuCDOyKCwctpq7zu8nwVmxFCSNo2ZHknGy2hlWm
# e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