Script to setup Windows 10 1903
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.

173 lines
6.5 KiB

<#
.SYNOPSIS
The TAB completion for functions and their arguments
Version: v6.0.11
Date: 31.12.2021
Copyright (c) 20142022 farag
Copyright (c) 20192022 farag & Inestic
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 a comma
.LINK
https://github.com/farag2/Sophia-Script-for-Windows
#>
#Requires -RunAsAdministrator
#Requires -Version 7.2
function Sophia
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $false)]
[string[]]
$Functions
)
foreach ($Function in $Functions)
{
Invoke-Expression -Command $Function
}
# The "RefreshEnvironment" and "Errors" functions will be executed at the end
Invoke-Command -ScriptBlock {RefreshEnvironment; Errors}
}
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 11 v6.0.11 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2022"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force
Import-LocalizedData -BindingVariable Global:Localization -FileName Sophia -BaseDirectory $PSScriptRoot\Localizations
# The mandatory checkings. Please, do not comment out this function
# Обязательные проверки. Пожалуйста, не комментируйте данную функцию
Checkings
$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 UnpinTaskbarShortcuts
if ($Command -eq "UnpinTaskbarShortcuts")
{
# Get all command arguments, excluding defaults
foreach ($ParameterSet in $ParameterSets.Name)
{
# If an argument is Shortcuts
if ($ParameterSet -eq "Shortcuts")
{
$ValidValues = ((Get-Command -Name UnpinTaskbarShortcuts).Parametersets.Parameters | Where-Object -FilterScript {$null -eq $_.Attributes.AliasNames}).Attributes.ValidValues
foreach ($ValidValue in $ValidValues)
{
# The "UnpinTaskbarShortcuts -Shortcuts <function>" construction
"UnpinTaskbarShortcuts" + " " + "-" + $ParameterSet + " " + $ValidValue | Where-Object -FilterScript {$_ -like "*$wordToComplete*"} | ForEach-Object -Process {"`"$_`""}
}
# The "UnpinTaskbarShortcuts -Shortcuts <functions>" construction
"UnpinTaskbarShortcuts" + " " + "-" + $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
}
}
# If a module command is DNSoverHTTPS
if ($Command -eq "DNSoverHTTPS")
{
(Get-Command -Name $Command).Name | Where-Object -FilterScript {$_ -like "*$wordToComplete*"}
# Get the valid IPv4 addresses array
# ((Get-Command -Name DNSoverHTTPS).Parametersets.Parameters | Where-Object -FilterScript {$null -eq $_.Attributes.AliasNames}).Attributes.ValidValues | Select-Object -Unique
$ValidValues = @((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object {$_ -notmatch ":"}
foreach ($ValidValue in $ValidValues)
{
$ValidValuesDescending = @((Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DohWellKnownServers).PSChildName) | Where-Object {$_ -notmatch ":"}
foreach ($ValidValueDescending in $ValidValuesDescending)
{
# The "DNSoverHTTPS -Enable -PrimaryDNS x.x.x.x -SecondaryDNS x.x.x.x" construction
"DNSoverHTTPS -Enable -PrimaryDNS $ValidValue -SecondaryDNS $ValidValueDescending" | Where-Object -FilterScript {$_ -like "*$wordToComplete*"} | ForEach-Object -Process {"`"$_`""}
}
}
}
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 "" -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 "" -InformationAction Continue
Write-Verbose -Message "UninstallUWPApps, `"PinToStart -UnpinAll`"" -Verbose
Write-Verbose -Message "`"Set-Association -ProgramPath ```"%ProgramFiles%\Notepad++\notepad++.exe```" -Extension .txt -Icon ```"%ProgramFiles%\Notepad++\notepad++.exe,0```"`"" -Verbose