From e455935474d79752bd101d821758c1913ece7bb7 Mon Sep 17 00:00:00 2001 From: Daniel Marquardt Date: Fri, 18 Jul 2025 07:43:27 -0700 Subject: [PATCH] Import --- .gitignore | 7 + README.md | 3 +- powershell-scripts.psproj | 27 ++ .../FolderManipulator/FolderManipulator.psm1 | 162 ++++++++++++ .../KnownFolderPaths/KnownFolderPaths.psm1 | 238 ++++++++++++++++++ src/scripts/Do-YesNoInputLoop.ps1 | 55 ++++ src/scripts/Write-Disclaimer.ps1 | 108 ++++++++ src/scripts/raw/dimensions.ps1 | 51 ++++ src/scripts/raw/print-folder-sizes.ps1 | 16 ++ src/scripts/raw/process-images.ps1 | 56 +++++ src/scripts/raw/resize.ps1 | 12 + src/scripts/raw/split-large-folder.ps1 | 43 ++++ 12 files changed, 776 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 powershell-scripts.psproj create mode 100644 src/modules/FolderManipulator/FolderManipulator.psm1 create mode 100644 src/modules/KnownFolderPaths/KnownFolderPaths.psm1 create mode 100644 src/scripts/Do-YesNoInputLoop.ps1 create mode 100644 src/scripts/Write-Disclaimer.ps1 create mode 100644 src/scripts/raw/dimensions.ps1 create mode 100644 src/scripts/raw/print-folder-sizes.ps1 create mode 100644 src/scripts/raw/process-images.ps1 create mode 100644 src/scripts/raw/resize.ps1 create mode 100644 src/scripts/raw/split-large-folder.ps1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6d4ced6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.TempPoint.* +*.Export.* +*.psprojs +*.RestorePoint.* +*.Run.ps1 +*.Package.ps1 +CustomMenu.inf \ No newline at end of file diff --git a/README.md b/README.md index 538e9c0..50f2013 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -# powershell-scripts - +powershell-scripts diff --git a/powershell-scripts.psproj b/powershell-scripts.psproj new file mode 100644 index 0000000..fa1cb76 --- /dev/null +++ b/powershell-scripts.psproj @@ -0,0 +1,27 @@ + + 2.1 + 83d67b78-feef-44e2-98f6-9cf3e01e5949 + 2 + + src + src\modules + src\scripts + src\modules\KnownFolderPaths + src\scripts\raw + src\modules\FolderManipulator + + + .gitignore + src\scripts\raw\dimensions.ps1 + src\scripts\raw\print-folder-sizes.ps1 + src\scripts\raw\process-images.ps1 + src\scripts\raw\resize.ps1 + src\scripts\raw\split-large-folder.ps1 + src\modules\KnownFolderPaths\KnownFolderPaths.psm1 + src\modules\FolderManipulator\FolderManipulator.psm1 + src\scripts\Do-YesNoInputLoop.ps1 + src\scripts\Write-Disclaimer.ps1 + + Project + + \ No newline at end of file diff --git a/src/modules/FolderManipulator/FolderManipulator.psm1 b/src/modules/FolderManipulator/FolderManipulator.psm1 new file mode 100644 index 0000000..cc523b8 --- /dev/null +++ b/src/modules/FolderManipulator/FolderManipulator.psm1 @@ -0,0 +1,162 @@ +<# + =========================================================================== + Created on: 9/28/2021 8:24 PM + Created by: D. Marquardt + Organization: inCrypto Software + Filename: FolderManipulator.psm1 + ------------------------------------------------------------------------- + Module Name: Folder Manipulator + =========================================================================== +#> +<# + .SYNOPSIS + Split Large File Count Into Subfolders + + .DESCRIPTION + Takes a folder of files and a file count, and will move the files into subfolders in groups of X files. + + .PARAMETER directory + The folder containing the items to split up + + .PARAMETER groupsize + How many files to put in each sub-folder + + .EXAMPLE + PS C:\> Split-DirectoryIntoSubdirs -directory 'C:\Photos' -groupsize 100 + + .NOTES + Additional information about the function. +#> +function Split-DirectoryIntoSubdirs +{ + [OutputType([int])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string]$directory, + [Parameter(Mandatory = $true)] + [ValidateRange(10000, 1)] + [int]$groupsize + ) + + # Fetch the total count of the files to split + $totalcount = (Get-ChildItem $directory | Measure-Object).Count + + # Tracking Vars + $processed = 0 + $currGroupFileCount = 0 + $currGroupNumber = 0 + + Get-ChildItem -path $directory -File | ForEach-Object { + # Write out the current progress + $processed++ + Write-Progress -Activity 'Processing' -Status ('Fetching File ' + $processed + ' of ' + $totalcount) -PercentComplete ($processed / $totalcount * 100) + + # If we are starting a new group, increase the group number + if ($currGroupFileCount -eq 0) + { + # Start a new group + $currGroupNumber++ + } + # Track how many files we've processed in this group so far + $currGroupFileCount++ + + # Calculate the target folder name and check to see if it exists... if not create it + $currGroupFolder = ($processdir + $currGroupNumber) + if (!(Test-Path -Path $currGroupFolder)) + { + New-Item -Path $processdir -Name $currGroupNumber -ItemType "directory" + } + + # Move the file into the dir + $_ | Move-Item -Destination $currGroupFolder + + # If we've reached the max count for this dir, reset the counter so we can create a new folder + if ($currGroupFileCount -eq $groupsize) + { + $currGroupFileCount = 0 + } + } + return $currGroupNumber +} + +<# + .SYNOPSIS + Return the size of everything in the folder + + .DESCRIPTION + Returns the total size of the directory + + .PARAMETER dir + The directory to get the size of + + .EXAMPLE + PS C:\> Get-FolderSize -dir 'C:\Windows\System32' + + .NOTES + Additional information about the function. +#> +function Get-FolderSize +{ + [OutputType([double])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string]$dir + ) + + $folder = Get-Item -Path $dir + $name = $folder.Name + $size = (Get-ChildItem -Path ($dir) -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum + $foldersize = '{0:N2}' -f ($size) + return $foldersize +} + +<# + .SYNOPSIS + Return the size of each sub-folder in the path + + .DESCRIPTION + Returns the total size of the directories + + .PARAMETER dir + The directory to get the size of + + .EXAMPLE + PS C:\> Get-ChildFolderSizes -dir 'C:\Windows\System32' + + .NOTES + Additional information about the function. +#> +function Get-ChildFolderSizes +{ + [OutputType([array])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string]$dir + ) + + $dataColl = @() + + Get-ChildItem $dir -Directory | + Foreach-Object { + $name = $_.Name + $size = (Get-ChildItem -Path ($dir_to_process + $name) -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum + $foldersizeGb = '{0:N2}' -f ($size / 1Gb) + $foldersizeMb = '{0:N2}' -f ($size / 1Mb) + $dataObject = New-Object PSObject + Add-Member -inputObject $dataObject -memberType NoteProperty -name "FolderName" -value $name + Add-Member -inputObject $dataObject -memberType NoteProperty -name "foldersizeGb" -value $foldersizeGb + Add-Member -InputObject $dataObject -MemberType NoteProperty -Name "foldersizeMb" -Value $foldersizeMb + $dataColl += $dataObject + } + return $dataColl +} + + + + diff --git a/src/modules/KnownFolderPaths/KnownFolderPaths.psm1 b/src/modules/KnownFolderPaths/KnownFolderPaths.psm1 new file mode 100644 index 0000000..2ef89e9 --- /dev/null +++ b/src/modules/KnownFolderPaths/KnownFolderPaths.psm1 @@ -0,0 +1,238 @@ +<# +.SYNOPSIS + Requires powershell 5 or later + Provides Get and Set functions for KnownFolders +.EXAMPLE + PS> Set-KnownFolderPath Desktop $ENV:USERPROFILE/Desktop +.EXAMPLE + PS> $Path="" + PS> Get-KnownFolderPath Desktop ([ref]$Path) +.LINK + https://docs.microsoft.com/en-us/windows/win32/shell/known-folders +.LINK + https://stackoverflow.com/questions/25709398/set-location-of-special-folders-with-powershell +.LINK + https://gist.github.com/YoraiLevi/0f333d520f502fdb1244cdf0524db6d2 +#> + +# using namespace System.Management.Automation + +# Define known folder GUIDs +$KnownFolders = @{ + '3DObjects' = '31C0DD25-9439-4F12-BF41-7FF4EDA38722'; + 'AddNewPrograms' = 'de61d971-5ebc-4f02-a3a9-6c82895e5c04'; + 'AdminTools' = '724EF170-A42D-4FEF-9F26-B60E846FBA4F'; + 'AppUpdates' = 'a305ce99-f527-492b-8b1a-7e76fa98d6e4'; + 'CDBurning' = '9E52AB10-F80D-49DF-ACB8-4330F5687855'; + 'ChangeRemovePrograms' = 'df7266ac-9274-4867-8d55-3bd661de872d'; + 'CommonAdminTools' = 'D0384E7D-BAC3-4797-8F14-CBA229B392B5'; + 'CommonOEMLinks' = 'C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D'; + 'CommonPrograms' = '0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8'; + 'CommonStartMenu' = 'A4115719-D62E-491D-AA7C-E74B8BE3B067'; + 'CommonStartup' = '82A5EA35-D9CD-47C5-9629-E15D2F714E6E'; + 'CommonTemplates' = 'B94237E7-57AC-4347-9151-B08C6C32D1F7'; + 'ComputerFolder' = '0AC0837C-BBF8-452A-850D-79D08E667CA7'; + 'ConflictFolder' = '4bfefb45-347d-4006-a5be-ac0cb0567192'; + 'ConnectionsFolder' = '6F0CD92B-2E97-45D1-88FF-B0D186B8DEDD'; + 'Contacts' = '56784854-C6CB-462b-8169-88E350ACB882'; + 'ControlPanelFolder' = '82A74AEB-AEB4-465C-A014-D097EE346D63'; + 'Cookies' = '2B0F765D-C0E9-4171-908E-08A611B84FF6'; + 'Desktop' = 'B4BFCC3A-DB2C-424C-B029-7FE99A87C641'; + 'Documents' = 'FDD39AD0-238F-46AF-ADB4-6C85480369C7'; + 'Downloads' = '374DE290-123F-4565-9164-39C4925E467B'; + 'Favorites' = '1777F761-68AD-4D8A-87BD-30B759FA33DD'; + 'Fonts' = 'FD228CB7-AE11-4AE3-864C-16F3910AB8FE'; + 'Games' = 'CAC52C1A-B53D-4edc-92D7-6B2E8AC19434'; + 'GameTasks' = '054FAE61-4DD8-4787-80B6-090220C4B700'; + 'History' = 'D9DC8A3B-B784-432E-A781-5A1130A75963'; + 'InternetCache' = '352481E8-33BE-4251-BA85-6007CAEDCF9D'; + 'InternetFolder' = '4D9F7874-4E0C-4904-967B-40B0D20C3E4B'; + 'Links' = 'bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968'; + 'LocalAppData' = 'F1B32785-6FBA-4FCF-9D55-7B8E7F157091'; + 'LocalAppDataLow' = 'A520A1A4-1780-4FF6-BD18-167343C5AF16'; + 'LocalizedResourcesDir' = '2A00375E-224C-49DE-B8D1-440DF7EF3DDC'; + 'Music' = '4BD8D571-6D19-48D3-BE97-422220080E43'; + 'NetHood' = 'C5ABBF53-E17F-4121-8900-86626FC2C973'; + 'NetworkFolder' = 'D20BEEC4-5CA8-4905-AE3B-BF251EA09B53'; + 'OriginalImages' = '2C36C0AA-5812-4b87-BFD0-4CD0DFB19B39'; + 'PhotoAlbums' = '69D2CF90-FC33-4FB7-9A0C-EBB0F0FCB43C'; + 'Pictures' = '33E28130-4E1E-4676-835A-98395C3BC3BB'; + 'Playlists' = 'DE92C1C7-837F-4F69-A3BB-86E631204A23'; + 'PrintersFolder' = '76FC4E2D-D6AD-4519-A663-37BD56068185'; + 'PrintHood' = '9274BD8D-CFD1-41C3-B35E-B13F55A758F4'; + 'Profile' = '5E6C858F-0E22-4760-9AFE-EA3317B67173'; + 'ProgramData' = '62AB5D82-FDC1-4DC3-A9DD-070D1D495D97'; + 'ProgramFiles' = '905e63b6-c1bf-494e-b29c-65b732d3d21a'; + 'ProgramFilesX64' = '6D809377-6AF0-444b-8957-A3773F02200E'; + 'ProgramFilesX86' = '7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E'; + 'ProgramFilesCommon' = 'F7F1ED05-9F6D-47A2-AAAE-29D317C6F066'; + 'ProgramFilesCommonX64' = '6365D5A7-0F0D-45E5-87F6-0DA56B6A4F7D'; + 'ProgramFilesCommonX86' = 'DE974D24-D9C6-4D3E-BF91-F4455120B917'; + 'Programs' = 'A77F5D77-2E2B-44C3-A6A2-ABA601054A51'; + 'Public' = 'DFDF76A2-C82A-4D63-906A-5644AC457385'; + 'PublicDesktop' = 'C4AA340D-F20F-4863-AFEF-F87EF2E6BA25'; + 'PublicDocuments' = 'ED4824AF-DCE4-45A8-81E2-FC7965083634'; + 'PublicDownloads' = '3D644C9B-1FB8-4f30-9B45-F670235F79C0'; + 'PublicGameTasks' = 'DEBF2536-E1A8-4c59-B6A2-414586476AEA'; + 'PublicMusic' = '3214FAB5-9757-4298-BB61-92A9DEAA44FF'; + 'PublicPictures' = 'B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5'; + 'PublicVideos' = '2400183A-6185-49FB-A2D8-4A392A602BA3'; + 'QuickLaunch' = '52a4f021-7b75-48a9-9f6b-4b87a210bc8f'; + 'Recent' = 'AE50C081-EBD2-438A-8655-8A092E34987A'; + 'RecycleBinFolder' = 'B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC'; + 'ResourceDir' = '8AD10C31-2ADB-4296-A8F7-E4701232C972'; + 'RoamingAppData' = '3EB685DB-65F9-4CF6-A03A-E3EF65729F3D'; + 'SampleMusic' = 'B250C668-F57D-4EE1-A63C-290EE7D1AA1F'; + 'SamplePictures' = 'C4900540-2379-4C75-844B-64E6FAF8716B'; + 'SamplePlaylists' = '15CA69B3-30EE-49C1-ACE1-6B5EC372AFB5'; + 'SampleVideos' = '859EAD94-2E85-48AD-A71A-0969CB56A6CD'; + 'SavedGames' = '4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4'; + 'SavedSearches' = '7d1d3a04-debb-4115-95cf-2f29da2920da'; + 'SEARCH_CSC' = 'ee32e446-31ca-4aba-814f-a5ebd2fd6d5e'; + 'SEARCH_MAPI' = '98ec0e18-2098-4d44-8644-66979315a281'; + 'SearchHome' = '190337d1-b8ca-4121-a639-6d472d16972a'; + 'SendTo' = '8983036C-27C0-404B-8F08-102D10DCFD74'; + 'SidebarDefaultParts' = '7B396E54-9EC5-4300-BE0A-2482EBAE1A26'; + 'SidebarParts' = 'A75D362E-50FC-4fb7-AC2C-A8BEAA314493'; + 'StartMenu' = '625B53C3-AB48-4EC1-BA1F-A1EF4146FC19'; + 'Startup' = 'B97D20BB-F46A-4C97-BA10-5E3608430854'; + 'SyncManagerFolder' = '43668BF8-C14E-49B2-97C9-747784D784B7'; + 'SyncResultsFolder' = '289a9a43-be44-4057-a41b-587a76d7e7f9'; + 'SyncSetupFolder' = '0F214138-B1D3-4a90-BBA9-27CBC0C5389A'; + 'System' = '1AC14E77-02E7-4E5D-B744-2EB1AE5198B7'; + 'SystemX86' = 'D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27'; + 'Templates' = 'A63293E8-664E-48DB-A079-DF759E0509F7'; + 'TreeProperties' = '5b3749ad-b49f-49c1-83eb-15370fbd4882'; + 'UserProfiles' = '0762D272-C50A-4BB0-A382-697DCD729B80'; + 'UsersFiles' = 'f3ce0f7c-4901-4acc-8648-d5d44b04ef8f'; + 'Videos' = '18989B1D-99B5-455B-841C-AB7C74E4DDFC'; + 'Windows' = 'F38BF404-1D43-42F2-9305-67DE0B28FC23'; +} +# Settings KnownFolders to be in script scope breaks the validator when Import-module is used 2 times. +# New-Variable -Name KnownFolders -Value $KnownFolders -Scope Script -Force +# class ValidKnownFoldersGenerator : IValidateSetValuesGenerator { +# #Preferably I would hide this class but I don't know enough powershell to scope it out of global +# [string[]] GetValidValues() { +# $Values = $global:KnownFolders.Keys +# echo $Values +# return $Values +# } +# } +function Set-KnownFolderPath { + <# + .SYNOPSIS + Sets a known folder's path using SHSetKnownFolderPath. + .PARAMETER KnownFolder + The known folder whose path to set. + .PARAMETER Path + The path. + .INPUTS + None. You cannot pipe objects to Set-KnownFolderPath. + .OUTPUTS + Int. Set-KnownFolderPath returns an int with the return code of SHSetKnownFolderPath + .EXAMPLE + PS> Set-KnownFolderPath Desktop $ENV:USERPROFILE/Desktop + 0 + .EXAMPLE + PS> Set-KnownFolderPath -KnownFolder Desktop -Path $ENV:USERPROFILE/Desktop + 0 + .LINK + https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shsetknownfolderpath + .LINK + https://stackoverflow.com/questions/25709398/set-location-of-special-folders-with-powershell + #> + Param ( + [Parameter(Mandatory = $true)] + # [ValidateSet([ValidKnownFoldersGenerator])] + [ValidateSet('3DObjects', 'AddNewPrograms', 'AdminTools', 'AppUpdates', 'CDBurning', 'ChangeRemovePrograms', 'CommonAdminTools', 'CommonOEMLinks', 'CommonPrograms', 'CommonStartMenu', 'CommonStartup', 'CommonTemplates', 'ComputerFolder', 'ConflictFolder', 'ConnectionsFolder', 'Contacts', 'ControlPanelFolder', 'Cookies', 'Desktop', 'Documents', 'Downloads', 'Favorites', 'Fonts', 'Games', 'GameTasks', 'History', 'InternetCache', 'InternetFolder', 'Links', 'LocalAppData', 'LocalAppDataLow', 'LocalizedResourcesDir', 'Music', 'NetHood', 'NetworkFolder', 'OriginalImages', 'PhotoAlbums', 'Pictures', 'Playlists', 'PrintersFolder', 'PrintHood', 'Profile', 'ProgramData', 'ProgramFiles', 'ProgramFilesX64', 'ProgramFilesX86', 'ProgramFilesCommon', 'ProgramFilesCommonX64', 'ProgramFilesCommonX86', 'Programs', 'Public', 'PublicDesktop', 'PublicDocuments', 'PublicDownloads', 'PublicGameTasks', 'PublicMusic', 'PublicPictures', 'PublicVideos', 'QuickLaunch', 'Recent', 'RecycleBinFolder', 'ResourceDir', 'RoamingAppData', 'SampleMusic', 'SamplePictures', 'SamplePlaylists', 'SampleVideos', 'SavedGames', 'SavedSearches', 'SEARCH_CSC', 'SEARCH_MAPI', 'SearchHome', 'SendTo', 'SidebarDefaultParts', 'SidebarParts', 'StartMenu', 'Startup', 'SyncManagerFolder', 'SyncResultsFolder', 'SyncSetupFolder', 'System', 'SystemX86', 'Templates', 'TreeProperties', 'UserProfiles', 'UsersFiles', 'Videos', 'Windows')] + [string]$KnownFolder, + + [Parameter(Mandatory = $true)] + [string]$Path + ) + + # Define SHSetKnownFolderPath if it hasn't been defined already + $Type = ([System.Management.Automation.PSTypeName]'KnownFolders.SHSetKnownFolderPathPS').Type + if (-not $Type) { + # http://www.pinvoke.net/default.aspx/shell32/SHSetKnownFolderPath.html + $Signature = @' +[DllImport("shell32.dll")] +public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, IntPtr token, [MarshalAs(UnmanagedType.LPWStr)] string path); +'@ + $Type = Add-Type -MemberDefinition $Signature -Namespace 'KnownFolders' -Name 'SHSetKnownFolderPathPS' -PassThru + } + + ### ORIGINAL ### + # Validate the path + #if (Test-Path $Path -PathType Container) { + # Call SHSetKnownFolderPath + # return $Type::SHSetKnownFolderPath([ref]$KnownFolders[$KnownFolder], 0, 0, $Path) + #} + #else { + # throw New-Object System.IO.DirectoryNotFoundException "Could not find part of the path $Path." + #} + ### END ORIGINAL ### + + # Validate the path + if (!(Test-Path $Path -PathType Container)) { + New-Item -Path $Path -type Directory -Force + } + + # Call SHSetKnownFolderPath + $Type::SHSetKnownFolderPath([ref]$KnownFolders[$KnownFolder], 0, 0, $Path) + attrib +r $Path + + $Leaf = Split-Path -Path "$Path" -Leaf + Move-Item "$HOME\$Leaf\*" $Path + # rd $HOME\$Leaf -recurse -Force +} +function Get-KnownFolderPath { + <# + .SYNOPSIS + Gets a known folder's path using SHGetKnownFolderPath. + .PARAMETER KnownFolder + The known folder whose path to get. + .PARAMETER Path + The path. + .INPUTS + None. You cannot pipe objects to Get-KnownFolderPath. + .OUTPUTS + Int. Get-KnownFolderPath returns an int with the return code of SHGetKnownFolderPath + .EXAMPLE + PS> Get-KnownFolderPath Desktop ([ref]$Path) + 0 + .EXAMPLE + PS> $Path = "" + PS> Get-KnownFolderPath -KnownFolder Desktop -Path ([ref]$Path) + 0 + PS>$Path #Check the value of path + C:\Users\user\Desktop + .LINK + https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath + .LINK + https://stackoverflow.com/questions/25709398/set-location-of-special-folders-with-powershell + #> + Param ( + [Parameter(Mandatory = $true)] + # [ValidateSet([ValidKnownFoldersGenerator])] + [ValidateSet('3DObjects', 'AddNewPrograms', 'AdminTools', 'AppUpdates', 'CDBurning', 'ChangeRemovePrograms', 'CommonAdminTools', 'CommonOEMLinks', 'CommonPrograms', 'CommonStartMenu', 'CommonStartup', 'CommonTemplates', 'ComputerFolder', 'ConflictFolder', 'ConnectionsFolder', 'Contacts', 'ControlPanelFolder', 'Cookies', 'Desktop', 'Documents', 'Downloads', 'Favorites', 'Fonts', 'Games', 'GameTasks', 'History', 'InternetCache', 'InternetFolder', 'Links', 'LocalAppData', 'LocalAppDataLow', 'LocalizedResourcesDir', 'Music', 'NetHood', 'NetworkFolder', 'OriginalImages', 'PhotoAlbums', 'Pictures', 'Playlists', 'PrintersFolder', 'PrintHood', 'Profile', 'ProgramData', 'ProgramFiles', 'ProgramFilesX64', 'ProgramFilesX86', 'ProgramFilesCommon', 'ProgramFilesCommonX64', 'ProgramFilesCommonX86', 'Programs', 'Public', 'PublicDesktop', 'PublicDocuments', 'PublicDownloads', 'PublicGameTasks', 'PublicMusic', 'PublicPictures', 'PublicVideos', 'QuickLaunch', 'Recent', 'RecycleBinFolder', 'ResourceDir', 'RoamingAppData', 'SampleMusic', 'SamplePictures', 'SamplePlaylists', 'SampleVideos', 'SavedGames', 'SavedSearches', 'SEARCH_CSC', 'SEARCH_MAPI', 'SearchHome', 'SendTo', 'SidebarDefaultParts', 'SidebarParts', 'StartMenu', 'Startup', 'SyncManagerFolder', 'SyncResultsFolder', 'SyncSetupFolder', 'System', 'SystemX86', 'Templates', 'TreeProperties', 'UserProfiles', 'UsersFiles', 'Videos', 'Windows')] + [string]$KnownFolder, + [Parameter(Mandatory = $true)] + [ref]$Path + ) + # Define SHGetKnownFolderPathif it hasn't been defined already + $Type = ([System.Management.Automation.PSTypeName]'KnownFolders.SHGetKnownFolderPathPS').Type + if (-not $Type) { + # http://www.pinvoke.net/default.aspx/shell32/SHGetKnownFolderPath.html + $Signature = @' +[DllImport("shell32.dll")] +public extern static int SHGetKnownFolderPath(ref Guid folderId, uint flags, IntPtr token,[MarshalAs(UnmanagedType.LPWStr)] out string pszPath); +'@ + $Type = Add-Type -MemberDefinition $Signature -Namespace 'KnownFolders' -Name 'SHGetKnownFolderPathPS' -PassThru + } + # I am not sure why I need to work around like this instead of passing $Path directly but the value doesn't propegate outside... + $_Path = "" + $code = $Type::SHGetKnownFolderPath([ref]$KnownFolders[$KnownFolder], 0, 0, [ref]$_Path) + $Path.value = $_Path + return $code +} \ No newline at end of file diff --git a/src/scripts/Do-YesNoInputLoop.ps1 b/src/scripts/Do-YesNoInputLoop.ps1 new file mode 100644 index 0000000..0375f85 --- /dev/null +++ b/src/scripts/Do-YesNoInputLoop.ps1 @@ -0,0 +1,55 @@ +<# + .NOTES + =========================================================================== + Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 + Created on: 9/29/2021 1:45 PM + Created by: dcmarquardt + Organization: inCrypto Software + Filename: Do-YesNoInputLoop.ps1 + =========================================================================== + .DESCRIPTION + A description of the file. +#> + + +<# + .SYNOPSIS + Loop until user inputs Y or N and return the value. + + .DESCRIPTION + A detailed description of the Get-YesNoAnswer function. + + .PARAMETER ChangeSetName + A description of the ChangeSetName parameter. + + .EXAMPLE + PS C:\> Get-YesNoAnswer -PROMPT 'Value1' + + .NOTES + Additional information about the function. +#> +function Do-YesNoInputLoop +{ + [OutputType([boolean])] + param + ( + [Parameter(Mandatory = $true)] + [string]$PROMPT + ) + + $PROMPT_SETTINGS = $PROMPT + " (Y)ES or (N)O" + while ($True) + { + $ANS = Read-Host $PROMPT_SETTINGS + if ($ANS -eq 'y' -or $ANS -eq 'yes') + { + return $true + break + } + If ($ANS -eq 'n' -or $ANS -eq 'no') + { + return $false + break + } + } +} diff --git a/src/scripts/Write-Disclaimer.ps1 b/src/scripts/Write-Disclaimer.ps1 new file mode 100644 index 0000000..f09e111 --- /dev/null +++ b/src/scripts/Write-Disclaimer.ps1 @@ -0,0 +1,108 @@ +<# + .NOTES + =========================================================================== + Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 + Created on: 9/30/2021 5:47 PM + Created by: dcmarquardt + Organization: inCrypto Software + Filename: Write-Disclaimer.ps1 + =========================================================================== + .DESCRIPTION + A description of the file. +#> + + +<# + .NOTES + =========================================================================== + Created on: 9/30/2021 4:26 PM + Created by: dcmarquardt + Organization: inCrypto Software + Filename: win10-debloatifier.ps1 + =========================================================================== + .DESCRIPTION + Removes all of the crapware and silences (most of) Microsoft's telemetry. +#> + +function Write-WarningToConsole +{ +<# + .SYNOPSIS + Writes out WARNING in ASCII + + .DESCRIPTION + A detailed description of the Write-WarningToConsole function. + + .EXAMPLE + PS C:\> Write-WarningToConsole + + .NOTES + Additional information about the function. +#> + [CmdletBinding()] + param () + + Write-Host "######## ######## ######## ######## ######## ######## ######## " -ForegroundColor Red + Write-Host "# ### ### ### # ## # ## # ## ## # ## # ## ## " -ForegroundColor Red + Write-Host "# ### ## ## # ## # # # # ### ### # # # # ## # " -ForegroundColor Red + Write-Host "# # # # ## # # ## # # # ### ### # # # ##### " -ForegroundColor Red + Write-Host "# # # # ## # # ### ### # # # # # " -ForegroundColor Red + Write-Host "# # # ## # # # ## # # # ### ### # # # # ## # " -ForegroundColor Red + Write-Host "# ### # ## # # ## # # ## # ## ## # ## # ## ## " -ForegroundColor Red + Write-Host "######## ######## ######## ######## ######## ######## ######## " -ForegroundColor Red + Write-Host " " -ForegroundColor Red + Write-Host " PLEASE READ CAREFULLY! " -ForegroundColor Red + Write-Host " This program makes changes to your computer. I tested it " -ForegroundColor Red + Write-Host " a whole bunch and it didn't break anything on my computers. " -ForegroundColor Red + Write-Host " " -ForegroundColor Red + Write-Host " If it breaks something on your computer, I take no " -ForegroundColor Red + Write-Host " responsibility whatsoever. This warning is to cover my ass " -ForegroundColor Red + Write-Host " in the event your computer starts on fire and starts clucking " -ForegroundColor Red + Write-Host " like a chicken. Good luck mighty hero! " -ForegroundColor Red + Write-Host "---------------------------------------------------------------" -ForegroundColor Red + Write-Host " Now that the ominous warnings are out of they way, shall we " -ForegroundColor Yellow + Write-Host " proceed? " -ForegroundColor Yellow +} + +function Get-YesNoInput +{ + <# + .SYNOPSIS + Prompts the user for a y/n answer and returns true for yes, false for no + + .DESCRIPTION + Asks the user whatever is passed in -PROMPT and returns true/false + + .EXAMPLE + PS C:\> Get-YesNoInput -PROMPT "Do stuff?" + + .NOTES + Additional information about the function. +#> + [CmdletBinding()] + [OutputType([boolean])] + param + ( + [Parameter(Mandatory = $true)] + [string]$PROMPT + ) + + while ($True) + { + $ANS = Read-Host $PROMPT + if ($ANS -eq 'y' -or $ANS -eq 'yes') + { + return $true + break + } + If ($ANS -eq 'n' -or $ANS -eq 'no') + { + return $false + break + } + } +} + +Write-WarningToConsole +Get-YesNoInput -PROMPT "Y or N" + diff --git a/src/scripts/raw/dimensions.ps1 b/src/scripts/raw/dimensions.ps1 new file mode 100644 index 0000000..56c0f8d --- /dev/null +++ b/src/scripts/raw/dimensions.ps1 @@ -0,0 +1,51 @@ + +Function Get-Image +{ + begin + { + [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null + } + process + { + $fi = [System.IO.FileInfo]$_ + if ($fi.Exists) + { + $img = [System.Drawing.Image]::FromFile($_) + $img.Clone() + $img.Dispose() + } + else + { + Write-Host "File not found: $_" -fore yellow + } + } + end { } +} + +$dirtoprocess = "D:\resize\" +$filestoprocess = $dirtoprocess + "*.jpg" +#$header = "File Name||Width||Height" +#Add-Content -Path D:\resize.txt -Value $header +#Add-Content -Path D:\delete.txt -Value $header +$totalcount = (Get-ChildItem $dirtoprocess | Measure-Object).Count +$processed = 0 +dir $filestoprocess -Recurse | % { + $processed++ + Write-Progress -Activity 'Processing' -Status ('Fetching Image ' + $processed + ' of ' + $totalcount) -PercentComplete ($processed / $totalcount * 100) + $image = $_ | Get-Image + if (700 -gt $image.Width -and 700 -gt $image.Height) + { + $outval = $_.name + "||" + $image.Width + "||" + $image.Height + # Add-Content -Path D:\delete.txt -Value $outval + Add-Content -Path D:\delete.txt -Value $_.name + } + + + if (1280 -lt $image.Width -or 1280 -lt $image.Height) + { + $outval = $_.name + "||" + $image.Width + "||" + $image.Height + #Add-Content -Path D:\resize.txt -Value $outval + Add-Content -Path D:\resize.txt -Value $_.name + } + +} \ No newline at end of file diff --git a/src/scripts/raw/print-folder-sizes.ps1 b/src/scripts/raw/print-folder-sizes.ps1 new file mode 100644 index 0000000..35a3005 --- /dev/null +++ b/src/scripts/raw/print-folder-sizes.ps1 @@ -0,0 +1,16 @@ +# For each item in the provided directory, print out a delimited list of names and sizes +$dir_to_process = "Z:\LIB-TV\Main\" +$dataColl = @() + +Get-ChildItem $dir_to_process -Directory | +Foreach-Object { + $name = $_.Name + $size = (Get-ChildItem -Path ($dir_to_process + $name) -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum + $foldersize = '{0:N2}' -f ($size / 1Gb) + $dataObject = New-Object PSObject + Add-Member -inputObject $dataObject -memberType NoteProperty -name "FolderName" -value $name + Add-Member -inputObject $dataObject -memberType NoteProperty -name "foldersizeGb" -value $foldersize + $dataColl += $dataObject +} + +$dataColl | Out-GridView -Title "Size Of Subdirectories" \ No newline at end of file diff --git a/src/scripts/raw/process-images.ps1 b/src/scripts/raw/process-images.ps1 new file mode 100644 index 0000000..5b00b34 --- /dev/null +++ b/src/scripts/raw/process-images.ps1 @@ -0,0 +1,56 @@ +Function Get-Image +{ + begin{ + [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") |Out-Null + } + process{ + $fi=[System.IO.FileInfo]$_ + if( $fi.Exists){ + $img = [System.Drawing.Image]::FromFile($_) + $img.Clone() + $img.Dispose() + }else{ + Write-Host "File not found: $_" -fore yellow + } + } + end{} +} + +$dirtoprocess = "D:\resize\" +$filestoprocess = $dirtoprocess + "*.jpg" +$totalcount = ( Get-ChildItem $dirtoprocess | Measure-Object ).Count +$processed = 0 + +dir $filestoprocess -Recurse | % { + $processed++ + Write-Progress -Activity 'Processing' -Status ('Fetching Image ' + $processed + ' of ' + $totalcount) -PercentComplete ($processed / $totalcount * 100) + $image = $_ | Get-Image + $width = $image.Width + $height = $image.Height + $image.Dispose() + if(786 -gt $width -and 786 -gt $height) + { + write-host ("Removing Item..." + $_.FullName) + Remove-Item $_ + } + if(1280 -lt $width -or 1280 -lt $height) + { + write-host ("Shrinking Item..." + $_.FullName) + $cmdline = "E:AppData\XYplorer\Tools\ImageMagick\mogrify.exe -resize 1280x1280 " + $_.FullName + invoke-expression -command $cmdline + } + + if ($processed % 1000 -eq 0) + { + $leavenow = Read-Host "Process 1000 more records?" + if ($leavenow -eq 'Y' -or $leavenow -eq 'y') + { + write-host "Doing more stuff now..." + } + else + { + write-host "Bye fucker..." + break + } + } +} \ No newline at end of file diff --git a/src/scripts/raw/resize.ps1 b/src/scripts/raw/resize.ps1 new file mode 100644 index 0000000..1923de0 --- /dev/null +++ b/src/scripts/raw/resize.ps1 @@ -0,0 +1,12 @@ +$dirtoprocess = "D:\resize\" +$filestoprocess = $dirtoprocess + "*.jpg" +$totalcount = ( Get-ChildItem $dirtoprocess | Measure-Object ).Count +$processed = 0 +dir $filestoprocess -Recurse | % { + $processed++ + Write-Progress -Activity 'Processing...' -Status ('Resizing Image ' + $processed + ' of ' + $totalcount) -PercentComplete ($processed / $totalcount * 100) + $cmdline = "E:AppData\XYplorer\Tools\ImageMagick\mogrify.exe -resize 1920x1080 " + $_.FullName + #write-host $cmdline + invoke-expression -command $cmdline + #%{E:AppData\XYplorer\Tools\ImageMagick\mogrify.exe -resize 1280x1280 $_.FullName} +} \ No newline at end of file diff --git a/src/scripts/raw/split-large-folder.ps1 b/src/scripts/raw/split-large-folder.ps1 new file mode 100644 index 0000000..8c8bc32 --- /dev/null +++ b/src/scripts/raw/split-large-folder.ps1 @@ -0,0 +1,43 @@ +# Number of groups to support +$filesPerGroup = 500 +$processdir = "E:\Collections\Images\NSFW\new\" +$totalcount = ( Get-ChildItem $processdir | Measure-Object ).Count +$processed = 0 +$currGroupFileCount = 0 +$currGroupNumber = 0 +$filestoprocess = $processdir + "*.jpg" + +dir $filestoprocess -Recurse | % { + # Write out the current progress + $processed++ + Write-Progress -Activity 'Processing' -Status ('Fetching Image ' + $processed + ' of ' + $totalcount) -PercentComplete ($processed / $totalcount * 100) + + # If we are starting a new group, increase the group number + if($currGroupFileCount -eq 0) + { + # Start a new group + $currGroupNumber++ + # Write-Host ('Starting new group folder ' + $currGroupNumber) + } + # Track how many files we've processed in this group so far + $currGroupFileCount++ + + # Calculate the target folder name and check to see if it exists... if not create it + $currGroupFolder = ( $processdir + $currGroupNumber ) + if (!(Test-Path -Path $currGroupFolder)) + { + # Write-Host ('Created Folder, did not exist ' + $currGroupFolder) + New-Item -Path $processdir -Name $currGroupNumber -ItemType "directory" + } + + # Move the file into the dir + $_ | Move-Item -Destination $currGroupFolder + # Write-Host ('Move file ' + $_.Name) + + # If we've reached the max count for this dir, reset the counter so we can create a new folder + if ($currGroupFileCount -eq $filesPerGroup) + { + $currGroupFileCount = 0 + } +} +