-
Notifications
You must be signed in to change notification settings - Fork 7
/
Import-Sophia.ps1
147 lines (124 loc) · 3.3 KB
/
Import-Sophia.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<#
.SYNOPSIS
Scraps the latest version of Sophia edition weither you have W10/11/LTSC/PS7,
changes all function scopes to global and invokes it, as if it were importing it as a module
You can find farag's dobonhonkerosly big Sophia Script at https://github.com/farag2/Sophia-Script-for-Windows
And if you'd like using it as a GUI, try out SophiApp: https://github.com/Sophia-Community/SophiApp
Using the -Write parameter returns the script instead of piping it to Invoke-Expression
.EXAMPLE
Import-Sophia
# Or for short:
ipso
#>
function Import-Sophia {
[alias('ipso')]
[CmdletBinding()]
param(
[switch]
$Write,
[string]
[ValidateSet(
'de-DE',
'en-US',
'es-ES',
'fr-FR',
'hu-HU',
'it-IT',
'pt-BR',
'ru-RU',
'tr-TR',
'uk-UA',
'zh-CN'
)]
$OverrideLang
)
function Get-SophiaVersion {
switch ((Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber){
"17763" {
"Windows_10_LTSC_2019"
break
}
{($_ -ge 19044) -and ($_ -le 19048)}{
if ($PSVersionTable.PSVersion.Major -eq 5){
# Check if Windows 10 is an LTSC 2021
if ((Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName) -eq "Windows 10 Enterprise LTSC 2021"){
"Windows_10_LTSC_2021"
}
else{
"Windows_10"
}
}
else{
"Windows_10_PowerShell_7"
}
}
{$_ -ge 22000}
{
if ($PSVersionTable.PSVersion.Major -eq 5){
"Windows_11"
}
else{
"Windows_11_PowerShell_7"
}
}
}
}
$SophiaVer = "Sophia_Script_for_" + (Get-SophiaVersion)
$SupportedLanguages = @(
'de-DE',
'en-US',
'es-ES',
'fr-FR',
'hu-HU',
'it-IT',
'pt-BR',
'ru-RU',
'tr-TR',
'uk-UA',
'zh-CN'
)
if($OverrideLang){
if ($OverrideLang -NotIn $SupportedLanguages){
Write-Warning "Language $OverrideLang may not be supported."
}
$Lang = $OverrideLang
}
elseif((Get-UICulture).Name -in $SupportedLanguages){
$Lang = (Get-UICulture).Name
}
elseif((Get-UICulture).Name -eq "en-GB"){
$Lang = 'en-US'
}
else{
$Lang = 'en-US'
}
$Lang = (Get-UICulture).Name
if ($OverrideLang){$Lang = $OverrideLang}
if ($Lang -NotIn $SupportedLanguages){
$Lang = 'en-US'
}
Try{
$URL = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/src/$SophiaVer/Localizations/$Lang/Sophia.psd1"
$Hashtable = Invoke-RestMethod $URL -ErrorAction Stop
} Catch {
Write-Warning "Failed to get Localizations with lang $Lang`nand URL: $URL"
$_
return
}
While ($Hashtable[0] -ne 'C'){
$Hashtable = $Hashtable.Substring(1) # BOM ((
}
$global:Localizations = $global:Localization = Invoke-Expression $HashTable
Write-Verbose "Getting $($SophiaVer -replace '_', ' ')"
$RawURL = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/src/$SophiaVer/Module/Sophia.psm1"
Write-Verbose $RawURL
$SophiaFunctions = (Invoke-RestMethod $RawURL -ErrorAction Stop)
While ($SophiaFunctions[0] -ne '<'){
$SophiaFunctions = $SophiaFunctions.Substring(1) # BOM ((
}
if ($Write){
return $SophiaFunctions
}else{
New-Module -Name "Sophia Script (TL)" -ScriptBlock ([ScriptBlock]::Create($SophiaFunctions)) | Import-Module -Global
}
}