You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
5.3 KiB
160 lines
5.3 KiB
<#
|
|
.SYNOPSIS
|
|
The TAB completion for functions and their arguments
|
|
|
|
Version: v5.10.6
|
|
Date: 01.06.2021
|
|
|
|
Copyright (c) 2014–2021 farag
|
|
Copyright (c) 2019–2021 farag & oZ-Zo
|
|
|
|
Thanks to all https://forum.ru-board.com members involved
|
|
|
|
.DESCRIPTION
|
|
Dot source the script first: . .\Function.ps1 (with a dot at the beginning)
|
|
Start typing any characters contained in the function's name or its arguments, and press the TAB button
|
|
|
|
.EXAMPLE
|
|
Sophia -Functions <tab>
|
|
Sophia -Functions temp<tab>
|
|
Sophia -Functions "DiagTrackService -Disable", "DiagnosticDataLevel -Minimal", UninstallUWPApps
|
|
|
|
.NOTES
|
|
Set execution policy to be able to run scripts only in the current PowerShell session:
|
|
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
|
|
|
|
.NOTES
|
|
Separate functions with comma
|
|
|
|
.NOTES
|
|
https://forum.ru-board.com/topic.cgi?forum=62&topic=30617#15
|
|
https://habr.com/post/521202/
|
|
https://forums.mydigitallife.net/threads/powershell-windows-10-sophia-script.81675/
|
|
https://www.reddit.com/r/PowerShell/comments/go2n5v/powershell_script_setup_windows_10/
|
|
|
|
.LINK
|
|
https://t.me/sophianews
|
|
https://t.me/sophia_chat
|
|
|
|
.LINK
|
|
https://github.com/farag2
|
|
https://github.com/Inestic
|
|
|
|
.LINK
|
|
https://github.com/farag2/Windows-10-Sophia-Script
|
|
#>
|
|
function Sophia
|
|
{
|
|
[CmdletBinding()]
|
|
param
|
|
(
|
|
[Parameter(Mandatory = $false)]
|
|
[string[]]
|
|
$Functions
|
|
)
|
|
|
|
# Regardless of the functions entered as an argument, the "Checkings" function will be executed first, and the "RefreshEnvironment" and "Errors" functions will be executed at the end
|
|
Invoke-Command -ScriptBlock {Checkings}
|
|
|
|
foreach ($Function in $Functions)
|
|
{
|
|
Invoke-Expression -Command $Function
|
|
}
|
|
|
|
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
|
|
}
|
|
|
|
Clear-Host
|
|
|
|
$Host.UI.RawUI.WindowTitle = "Windows 10 Sophia Script v5.10.6 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows 10 | $([char]0x00A9) farag & oz-zo, 2014–2021"
|
|
|
|
Remove-Module -Name Sophia -Force -ErrorAction Ignore
|
|
Import-Module -Name $PSScriptRoot\Sophia.psd1 -PassThru -Force
|
|
|
|
Import-LocalizedData -BindingVariable Global:Localization -FileName Sophia -BaseDirectory $PSScriptRoot\Localizations
|
|
|
|
$Parameters = @{
|
|
CommandName = "Sophia"
|
|
ParameterName = "Functions"
|
|
ScriptBlock = {
|
|
param
|
|
(
|
|
$commandName,
|
|
$parameterName,
|
|
$wordToComplete,
|
|
$commandAst,
|
|
$fakeBoundParameters
|
|
)
|
|
|
|
# Get functions list with arguments to complete
|
|
$Commands = (Get-Module -Name Sophia).ExportedCommands.Keys
|
|
foreach ($Command in $Commands)
|
|
{
|
|
$ParameterSets = (Get-Command -Name $Command).Parametersets.Parameters | Where-Object -FilterScript {$null -eq $_.Attributes.AliasNames}
|
|
|
|
# If a module command is PinToStart
|
|
if ($Command -eq "PinToStart")
|
|
{
|
|
# Get all command arguments, excluding defaults
|
|
foreach ($ParameterSet in $ParameterSets.Name)
|
|
{
|
|
# If an argument is Tiles
|
|
if ($ParameterSet -eq "Tiles")
|
|
{
|
|
$ValidValues = ((Get-Command -Name PinToStart).Parametersets.Parameters | Where-Object -FilterScript {$null -eq $_.Attributes.AliasNames}).Attributes.ValidValues
|
|
foreach ($ValidValue in $ValidValues)
|
|
{
|
|
# The "PinToStart -Tiles <function>" construction
|
|
"PinToStart" + " " + "-" + $ParameterSet + " " + $ValidValue | Where-Object -FilterScript {$_ -like "*$wordToComplete*"} | ForEach-Object -Process {"`"$_`""}
|
|
}
|
|
|
|
# "PinToStart -Tiles <functions>" construction
|
|
"PinToStart" + " " + "-" + $ParameterSet + " " + ($ValidValues -join ", ") | Where-Object -FilterScript {$_ -like "*$wordToComplete*"} | ForEach-Object -Process {"`"$_`""}
|
|
}
|
|
|
|
continue
|
|
}
|
|
}
|
|
|
|
# If a module command is UninstallUWPApps
|
|
if ($Command -eq "UninstallUWPApps")
|
|
{
|
|
(Get-Command -Name $Command).Name | Where-Object -FilterScript {$_ -like "*$wordToComplete*"}
|
|
|
|
# Get all command arguments, excluding defaults
|
|
foreach ($ParameterSet in $ParameterSets.Name)
|
|
{
|
|
# If an argument is ForAllUsers
|
|
if ($ParameterSet -eq "ForAllUsers")
|
|
{
|
|
# The "UninstallUWPApps -ForAllUsers" construction
|
|
"UninstallUWPApps" + " " + "-" + $ParameterSet | Where-Object -FilterScript {$_ -like "*$wordToComplete*"} | ForEach-Object -Process {"`"$_`""}
|
|
}
|
|
|
|
continue
|
|
}
|
|
}
|
|
|
|
foreach ($ParameterSet in $ParameterSets.Name)
|
|
{
|
|
# The "Function -Argument" construction
|
|
$Command + " " + "-" + $ParameterSet | Where-Object -FilterScript {$_ -like "*$wordToComplete*"} | ForEach-Object -Process {"`"$_`""}
|
|
|
|
continue
|
|
}
|
|
|
|
# Get functions list without arguments to complete
|
|
Get-Command -Name $Command | Where-Object -FilterScript {$null -eq $_.Parametersets.Parameters} | Where-Object -FilterScript {$_.Name -like "*$wordToComplete*"}
|
|
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
Register-ArgumentCompleter @Parameters
|
|
|
|
Write-Information -MessageData "`n" -InformationAction Continue
|
|
Write-Verbose -Message "Sophia -Functions <tab>" -Verbose
|
|
Write-Verbose -Message "Sophia -Functions temp<tab>" -Verbose
|
|
Write-Verbose -Message "Sophia -Functions `"DiagTrackService -Disable`", `"DiagnosticDataLevel -Minimal`", UninstallUWPApps" -Verbose
|
|
Write-Information -MessageData "`n" -InformationAction Continue
|
|
Write-Verbose -Message "UninstallUWPApps, `"PinToStart -UnpinAll`"" -Verbose
|
|
|