Skip to content

Instantly share code, notes, and snippets.

@perXautomatik
Created August 14, 2023 08:00
Show Gist options
  • Save perXautomatik/b1041d712a156a914d89ceafecadaf02 to your computer and use it in GitHub Desktop.
Save perXautomatik/b1041d712a156a914d89ceafecadaf02 to your computer and use it in GitHub Desktop.
a simple PowerShell script
��function Ensure-Everything {
# Define a function to search with void tools everything for the folder name and "child:config" and get the first result
<#
.SYNOPSIS
Searches with void tools everything for the folder name and "child:config" and returns the first result as an object with properties Name, Path, and FullPath.
.PARAMETER FolderName
The folder name to search with.
.EXAMPLE
Search-Everything -FolderName "PF\NoteTakingProjectFolder"
Output: @{Name=config; Path=B:\PF\NoteTakingProjectFolder\.git\modules\NoteTakingProjectFolder; FullPath=B:\PF\NoteTakingProjectFolder\.git\modules\NoteTakingProjectFolder\config}
#>
param(
# The folder name to search with
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$folderPath,
# The filter to apply to the search
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$filter
)
# Install and import the pseverything module if not already loaded
if (-not (Get-Module -Name pseverything)) {
Install-Module pseverything -Scope CurrentUser -Force
Import-Module pseverything
}
$folderPath = $folderPath.trim("\\")
$filter = """" + ($folderPath | Split-Path -Leaf) + """" + " " + $filter
# Use Everything to find all folders in the folder path that match the filter
$results = Search-Everything -Filter $filter -global
# If there are any results, then return the first one as an object with properties Name, Path, and FullPath
if ($results) {
$firstResult = $results
return [PSCustomObject]@{
Path = $firstResult
}
}
else {
# Throw an error if no results are found
throw "No results found for folder path '$folderPath' and filter '$filter'"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment