Browse Source

fixed and improved WinPrtScrFolder

pull/469/head
Dmitry Nefedov 2 years ago
parent
commit
bef1406f75
  1. 34
      src/Sophia_Script_for_Windows_10/Module/Sophia.psm1
  2. 6
      src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1
  3. 6
      src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1
  4. 34
      src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1
  5. 34
      src/Sophia_Script_for_Windows_11/Module/Sophia.psm1
  6. 34
      src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1

34
src/Sophia_Script_for_Windows_10/Module/Sophia.psm1

@ -7702,6 +7702,16 @@ function WinPrtScrFolder
$Default $Default
) )
# Check if user is logged into OneDrive account (Microsoft account)
$UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore
if ($UserEmail)
{
Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim())
Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
switch ($PSCmdlet.ParameterSetName) switch ($PSCmdlet.ParameterSetName)
{ {
"Desktop" "Desktop"
@ -7713,20 +7723,28 @@ function WinPrtScrFolder
if ($PresetName) if ($PresetName)
{ {
# Get the name of a preset (e.g Sophia.ps1) regardless it was named
$PresetName = Split-Path -Path $PresetName.File -Leaf
# Check whether a preset contains the "OneDrive -Uninstall" string uncommented out # Check whether a preset contains the "OneDrive -Uninstall" string uncommented out
$OneDriveUninstallFunctionUncommented = (Get-Content -Path $PSScriptRoot\..\$PresetName -Encoding UTF8 -Force | Select-String -SimpleMatch "OneDrive -Uninstall").Line.StartsWith("#") -eq $false if (Get-Content -Path $PresetName.File -Encoding UTF8 -Force | Select-String -SimpleMatch "OneDrive -Uninstall")
{
# The string exists and is commented
$IsOneDriveToUninstall = (Get-Content -Path $PresetName.File -Encoding UTF8 -Force | Select-String -SimpleMatch "OneDrive -Uninstall").Line.StartsWith("#") -eq $false
}
else
{
# The string doesn't exist
$IsOneDriveToUninstall = $false
}
$OneDriveInstalled = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore $OneDriveInstalled = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore
if ($OneDriveUninstallFunctionUncommented -or (-not $OneDriveInstalled)) if ($IsOneDriveToUninstall -or (-not $OneDriveInstalled))
{ {
$DesktopFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop $DesktopFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -PropertyType ExpandString -Value $DesktopFolder -Force New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -PropertyType ExpandString -Value $DesktopFolder -Force
} }
else else
{ {
Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim())
Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) -ErrorAction SilentlyContinue Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
} }
} }
else else
@ -7739,8 +7757,8 @@ function WinPrtScrFolder
} }
else else
{ {
Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim())
Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) -ErrorAction SilentlyContinue Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
} }
} }
} }

6
src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1

@ -3651,9 +3651,6 @@ function TempFolder
# Restart the Printer Spooler service (Spooler) # Restart the Printer Spooler service (Spooler)
Restart-Service -Name Spooler -Force Restart-Service -Name Spooler -Force
# Stop OneDrive processes
Stop-Process -Name OneDrive, FileCoAuth -Force -ErrorAction Ignore
if (-not (Test-Path -Path $env:SystemDrive\Temp)) if (-not (Test-Path -Path $env:SystemDrive\Temp))
{ {
New-Item -Path $env:SystemDrive\Temp -ItemType Directory -Force New-Item -Path $env:SystemDrive\Temp -ItemType Directory -Force
@ -3763,9 +3760,6 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false
# Restart the Printer Spooler service (Spooler) # Restart the Printer Spooler service (Spooler)
Restart-Service -Name Spooler -Force Restart-Service -Name Spooler -Force
# Stop OneDrive processes
Stop-Process -Name OneDrive, FileCoAuth -Force -ErrorAction Ignore
# Remove a symbolic link to the %SystemDrive%\Temp folder # Remove a symbolic link to the %SystemDrive%\Temp folder
if (Get-Item -Path $env:LOCALAPPDATA\Temp -Force -ErrorAction Ignore | Where-Object -FilterScript {$_.LinkType -eq "SymbolicLink"}) if (Get-Item -Path $env:LOCALAPPDATA\Temp -Force -ErrorAction Ignore | Where-Object -FilterScript {$_.LinkType -eq "SymbolicLink"})
{ {

6
src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1

@ -4022,9 +4022,6 @@ function TempFolder
# Restart the Printer Spooler service (Spooler) # Restart the Printer Spooler service (Spooler)
Restart-Service -Name Spooler -Force Restart-Service -Name Spooler -Force
# Stop OneDrive processes
Stop-Process -Name OneDrive, FileCoAuth -Force -ErrorAction Ignore
if (-not (Test-Path -Path $env:SystemDrive\Temp)) if (-not (Test-Path -Path $env:SystemDrive\Temp))
{ {
New-Item -Path $env:SystemDrive\Temp -ItemType Directory -Force New-Item -Path $env:SystemDrive\Temp -ItemType Directory -Force
@ -4134,9 +4131,6 @@ Unregister-ScheduledTask -TaskName SymbolicLink -Confirm:`$false
# Restart the Printer Spooler service (Spooler) # Restart the Printer Spooler service (Spooler)
Restart-Service -Name Spooler -Force Restart-Service -Name Spooler -Force
# Stop OneDrive processes
Stop-Process -Name OneDrive, FileCoAuth -Force -ErrorAction Ignore
# Remove a symbolic link to the %SystemDrive%\Temp folder # Remove a symbolic link to the %SystemDrive%\Temp folder
if (Get-Item -Path $env:LOCALAPPDATA\Temp -Force -ErrorAction Ignore | Where-Object -FilterScript {$_.LinkType -eq "SymbolicLink"}) if (Get-Item -Path $env:LOCALAPPDATA\Temp -Force -ErrorAction Ignore | Where-Object -FilterScript {$_.LinkType -eq "SymbolicLink"})
{ {

34
src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1

@ -7705,6 +7705,16 @@ function WinPrtScrFolder
$Default $Default
) )
# Check if user is logged into OneDrive account (Microsoft account)
$UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore
if ($UserEmail)
{
Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim())
Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
switch ($PSCmdlet.ParameterSetName) switch ($PSCmdlet.ParameterSetName)
{ {
"Desktop" "Desktop"
@ -7716,20 +7726,28 @@ function WinPrtScrFolder
if ($PresetName) if ($PresetName)
{ {
# Get the name of a preset (e.g Sophia.ps1) regardless it was named
$PresetName = Split-Path -Path $PresetName.File -Leaf
# Check whether a preset contains the "OneDrive -Uninstall" string uncommented out # Check whether a preset contains the "OneDrive -Uninstall" string uncommented out
$OneDriveUninstallFunctionUncommented = (Get-Content -Path $PSScriptRoot\..\$PresetName -Encoding UTF8 -Force | Select-String -SimpleMatch "OneDrive -Uninstall").Line.StartsWith("#") -eq $false if (Get-Content -Path $PresetName.File -Encoding UTF8 -Force | Select-String -SimpleMatch "OneDrive -Uninstall")
{
# The string exists and is commented
$IsOneDriveToUninstall = (Get-Content -Path $PresetName.File -Encoding UTF8 -Force | Select-String -SimpleMatch "OneDrive -Uninstall").Line.StartsWith("#") -eq $false
}
else
{
# The string doesn't exist
$IsOneDriveToUninstall = $false
}
$OneDriveInstalled = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore $OneDriveInstalled = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore
if ($OneDriveUninstallFunctionUncommented -or (-not $OneDriveInstalled)) if ($IsOneDriveToUninstall -or (-not $OneDriveInstalled))
{ {
$DesktopFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop $DesktopFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -PropertyType ExpandString -Value $DesktopFolder -Force New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -PropertyType ExpandString -Value $DesktopFolder -Force
} }
else else
{ {
Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim())
Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) -ErrorAction SilentlyContinue Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
} }
} }
else else
@ -7742,8 +7760,8 @@ function WinPrtScrFolder
} }
else else
{ {
Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim())
Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) -ErrorAction SilentlyContinue Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
} }
} }
} }

34
src/Sophia_Script_for_Windows_11/Module/Sophia.psm1

@ -7238,6 +7238,16 @@ function WinPrtScrFolder
$Default $Default
) )
# Check if user is logged into OneDrive account (Microsoft account)
$UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore
if ($UserEmail)
{
Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim())
Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
switch ($PSCmdlet.ParameterSetName) switch ($PSCmdlet.ParameterSetName)
{ {
"Desktop" "Desktop"
@ -7249,20 +7259,28 @@ function WinPrtScrFolder
if ($PresetName) if ($PresetName)
{ {
# Get the name of a preset (e.g Sophia.ps1) regardless it was named
$PresetName = Split-Path -Path $PresetName.File -Leaf
# Check whether a preset contains the "OneDrive -Uninstall" string uncommented out # Check whether a preset contains the "OneDrive -Uninstall" string uncommented out
$OneDriveUninstallFunctionUncommented = (Get-Content -Path $PSScriptRoot\..\$PresetName -Encoding UTF8 -Force | Select-String -SimpleMatch "OneDrive -Uninstall").Line.StartsWith("#") -eq $false if (Get-Content -Path $PresetName.File -Encoding UTF8 -Force | Select-String -SimpleMatch "OneDrive -Uninstall")
{
# The string exists and is commented
$IsOneDriveToUninstall = (Get-Content -Path $PresetName.File -Encoding UTF8 -Force | Select-String -SimpleMatch "OneDrive -Uninstall").Line.StartsWith("#") -eq $false
}
else
{
# The string doesn't exist
$IsOneDriveToUninstall = $false
}
$OneDriveInstalled = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore $OneDriveInstalled = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore
if ($OneDriveUninstallFunctionUncommented -or (-not $OneDriveInstalled)) if ($IsOneDriveToUninstall -or (-not $OneDriveInstalled))
{ {
$DesktopFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop $DesktopFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -PropertyType ExpandString -Value $DesktopFolder -Force New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -PropertyType ExpandString -Value $DesktopFolder -Force
} }
else else
{ {
Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim())
Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) -ErrorAction SilentlyContinue Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
} }
} }
else else
@ -7275,8 +7293,8 @@ function WinPrtScrFolder
} }
else else
{ {
Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim())
Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) -ErrorAction SilentlyContinue Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
} }
} }
} }

34
src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1

@ -7241,6 +7241,16 @@ function WinPrtScrFolder
$Default $Default
) )
# Check if user is logged into OneDrive account (Microsoft account)
$UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore
if ($UserEmail)
{
Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim())
Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
return
}
switch ($PSCmdlet.ParameterSetName) switch ($PSCmdlet.ParameterSetName)
{ {
"Desktop" "Desktop"
@ -7252,20 +7262,28 @@ function WinPrtScrFolder
if ($PresetName) if ($PresetName)
{ {
# Get the name of a preset (e.g Sophia.ps1) regardless it was named
$PresetName = Split-Path -Path $PresetName.File -Leaf
# Check whether a preset contains the "OneDrive -Uninstall" string uncommented out # Check whether a preset contains the "OneDrive -Uninstall" string uncommented out
$OneDriveUninstallFunctionUncommented = (Get-Content -Path $PSScriptRoot\..\$PresetName -Encoding UTF8 -Force | Select-String -SimpleMatch "OneDrive -Uninstall").Line.StartsWith("#") -eq $false if (Get-Content -Path $PresetName.File -Encoding UTF8 -Force | Select-String -SimpleMatch "OneDrive -Uninstall")
{
# The string exists and is commented
$IsOneDriveToUninstall = (Get-Content -Path $PresetName.File -Encoding UTF8 -Force | Select-String -SimpleMatch "OneDrive -Uninstall").Line.StartsWith("#") -eq $false
}
else
{
# The string doesn't exist
$IsOneDriveToUninstall = $false
}
$OneDriveInstalled = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore $OneDriveInstalled = Get-Package -Name "Microsoft OneDrive" -ProviderName Programs -Force -ErrorAction Ignore
if ($OneDriveUninstallFunctionUncommented -or (-not $OneDriveInstalled)) if ($IsOneDriveToUninstall -or (-not $OneDriveInstalled))
{ {
$DesktopFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop $DesktopFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name Desktop
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -PropertyType ExpandString -Value $DesktopFolder -Force New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}" -PropertyType ExpandString -Value $DesktopFolder -Force
} }
else else
{ {
Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim())
Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) -ErrorAction SilentlyContinue Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
} }
} }
else else
@ -7278,8 +7296,8 @@ function WinPrtScrFolder
} }
else else
{ {
Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) Write-Warning -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim())
Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line) -ErrorAction SilentlyContinue Write-Error -Message ($Localization.OneDriveWarning -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue
} }
} }
} }

Loading…
Cancel
Save