YokoRUMsetPC.psm1
function Test-Admin { [CmdletBinding()] [OutputType([boolean])] param () return [boolean]([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) } function Format-DateTime { [CmdletBinding()] param () #region Parameters $DateFormat = 'dd/MM/yyyy' $DateLongFormat = 'dddd, MMMM d, yyyy' $TimeZoneAuto = 'On' $TimeZone = 'Central Europe Standard Time' $TimeFormat = 'HH:mm' $TimeLongFormat = 'HH:mm:ss' #endregion #region DateTimeFormat if (!(Test-Admin -WarningAction SilentlyContinue)) { Write-Warning -Message "To set time zone to automatically, need to open admin console." } else { Write-Output -InputObject "Set time zone automatically:`t$TimeZoneAuto" $TZAutoSettingRegPath = "HKLM:\SYSTEM\CurrentControlSet\Services\tzautoupdate" Set-ItemProperty -Path $TZAutoSettingRegPath -Name "Start" -Value 3 Set-TimeZone -Id $TimeZone } Write-Output -InputObject "Setting Time Zone to:`t`t$TimeZone" Write-Output -InputObject "Setting short time format to:`t$TimeFormat" Write-Output -InputObject "Setting short date format to:`t$DateFormat" Write-Output -InputObject "Setting long date format to:`t$dateLongFormat" Write-Output -InputObject "Setting long time format tp:`t$TimeLongFormat" try { $status = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS -ErrorAction SilentlyContinue if (!$status) { Write-Warning -Message "Date and time format already set." } function Set-DateFormat { [CmdletBinding(SupportsShouldProcess = $true)] param ($sid) if (Test-Path "HKU:\${sid}") { Write-Output -InputObject "Updating date format for user:`t$sid" Set-ItemProperty -Path "HKU:\${sid}\Control Panel\International\" -name sShortDate -value $DateFormat Set-ItemProperty -Path "HKU:\${sid}\Control Panel\International\" -name sLongDate -value $DateLongFormat Set-ItemProperty -Path "HKCU:\Control Panel\International" -name sShortTime -value $TimeFormat Set-ItemProperty -Path "HKCU:\Control Panel\International" -name sTimeFormat -value $TimeLongFormat } } $userDetails = Get-CimInstance -Class win32_useraccount | Where-Object{ $_.status -eq 'ok' } # Get-WmiObject foreach ($user in $userDetails) { $sid = $user.SID Set-DateFormat($sid) } } catch { Write-Error -Message "Error occured while setting Date format." -Exception "$_.Exception.Message" -Category WriteError } #endregion } function Install-dotNET3.5 { [CmdletBinding(SupportsShouldProcess = $true)] param ( [switch]$Force ) if (!(Test-Admin -ErrorAction SilentlyContinue)) { return Write-Error -Message "Need to open Powershell with Admin privileges." -Category PermissionDenied } if ($pscmdlet.ShouldProcess("Target", "Operation")) { $dotNetName = "Windows feature .NET 3.5" $dotNet = (Get-WindowsOptionalFeature -FeatureName "NetFx3" -Online -ErrorAction SilentlyContinue).State if ($Force) { Write-Output "Installing optional $dotNetName package." Enable-WindowsOptionalFeature -Online -FeatureName "NetFx3" -All } elseif (![boolean]$dotNet) { Write-Output "Installing optional $dotNetName package." Enable-WindowsOptionalFeature -Online -FeatureName "NetFx3" -All } else { Write-Output "Optional $dotNetName is already enabled." } if (![boolean]$dotNet) { Write-Error -Category NotEnabled -Message "$dotNetName failed to install, trying other installation method." -ErrorAction Continue $choco = Get-Command -Name "choco.exe" -ErrorAction SilentlyContinue if (![boolean]$choco) { [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 return & ([ScriptBlock]::Create((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))) } else { Start-Process -FilePath "choco.exe" -ArgumentList "install dotnet3.5 -f -y" -NoNewWindow } if (![boolean]$choco) { Start-Process -FilePath "DISM" -ArgumentList "/Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:D:\sources\sxs" -NoNewWindow } } } } function Get-HWIDcsv { [CmdletBinding()] param () if (Test-Admin) { Write-Output -InputObject "Generating hardware hash file." Install-Script -Name Get-WindowsAutoPilotInfo -Force $hashFolder = $env:SystemDrive + "\HWID" New-Item -Path $hashFolder -ItemType Directory -Force | Out-Null Set-Location -Path $hashFolder Get-WindowsAutopilotInfo -OutputFile "AutopilotHWID.csv" Start-Process explorer.exe $hashFolder } else { Write-Error -Message "Cannot generate hardware hash file, need admin console." -Category AuthenticationError } } function Set-YokoPC { [CmdletBinding(SupportsShouldProcess = $true)] param () Format-DateTime Install-dotNET3.5 } |