]> apps.delaporte.us Git - dotfiles.git/blob - psmodules/file_management.psm1
wtfutil updates
[dotfiles.git] / psmodules / file_management.psm1
1 <#
2 .SYNOPSIS
3
4 Find 10 largest files on the C drive.
5
6 #>
7 function Show-LargeFiles() {
8 param(
9 [int]$Max=10,
10 [string]$path="C:\Users"
11 )
12 Get-ChildItem $path -r | sort -descending -property length | select -first $Max name, Length, FullName
13 }
14
15 <#
16 .SYNPOSIS
17
18 Display the free space on the C drive.
19
20 #>
21 function Show-Drivespace() {
22 Get-PSDrive C | Select-Object Used,Free | ForEach {
23 Write-Host "Free space GB: " ($_.Free / 1GB)
24 Write-Host "Used space GB: " ($_.Used / 1GB)
25 }
26 }
27
28 function Show-DrivespacePretty() {
29 Start-Job -Name "FileCollection" -ScriptBlock { Show-Drivespace }
30 While((Get-Job -Name "FileCollection").State -eq "Running") {
31 Write-Progress -Activity "Collecting Files..." -PercentComplete $x
32 If($x -eq 100){
33 $x = 1
34 }
35 Else{
36 $x += 1
37 }
38 }
39 Write-Progress -Activity "Collecting Files..." -Completed
40 $Files = Get-Job -Name "FileCollection" | Receive-Job
41 Get-Job -Name "FileCollection" | Remove-Job
42 }
43
44 Export-ModuleMember -Function Show-DriveSpace
45 Export-ModuleMember -Function Show-LargeFiles
46
47 # Stay awake to allow large transfers to complete
48 # without permanently giving up battery saving features
49 function Invoke-StayAwakeWindows() {
50 param($minutes=90)
51 $wsh = New-Object -ComObject WScript.Shell
52 do{
53 "Staying awake for $minutes minutes"
54 $minutes-=1;
55 # Send Shift+F15
56 $wsh.SendKeys('+{F15}')
57 Start-Sleep -seconds 59
58 }until($minutes -lt 0)
59 # Thank you to http://www.zhornsoftware.co.uk/caffeine/
60 }
61
62 Export-ModuleMember -Function Invoke-StayAwakeWindows
63
64 function Invoke-StayAwake() {
65 param($minutes=90)
66 do{
67 "Staying awake for $minutes minutes"
68 systemd-inhibit sleep 60
69 $minutes-=1;
70 }until($minutes -lt 0)
71 }
72
73 Export-ModuleMember -Function Invoke-StayAwake