tom42tools.psm1
function DeployMe() { <# .SYNOPSIS Downloads .ps1 and runs it as admin .DESCRIPTION Used for system reinstalls, it downloads .ps1 and runs it as admin, it will also record restore folder Downloads .ps1 and runs it as admin .PARAMETER URL URL to a .ps1 files .PARAMETER Restorefolder Where the old install backup files were movied to .EXAMPLE PS C:\> DeployMe 'https://www.website.com/file.ps1' Downloads .ps1 and runs it as admin .EXAMPLE PS C:\> DeployMe -URL 'https://www.website.com/file.ps1' Downloads .ps1 and runs it as admin .EXAMPLE PS C:\> DeployMe 'https://www.website.com/file.ps1' 'e:\restore' Downloads .ps1 and runs it as admin, saves 'e:\restore' to file named "~\restore.dir" .EXAMPLE PS C:\> DeployMe -URL 'https://www.website.com/file.ps1' -Restorefolder 'e:\restore' Downloads .ps1 and runs it as admin, saves 'e:\restore' to file named "~\restore.dir" #> [CmdletBinding()] param( [Parameter()] [string] $URL, [Parameter()] [string] $Restorefolder = 'NA' ) if (isURIWeb $URL) { Write-Output $restorefolder | out-file -FilePath "~\restore.dir" (New-Object System.Net.WebClient).DownloadFile($URL,"$env:TEMP\part1.ps1");Start-Process -FilePath "powershell.exe" -ArgumentList "-executionpolicy bypass -File $env:TEMP\part1.ps1" -Verb RunAs } else { Write-Host 'NOT VALID URL' Pause } } function Set-RunOnce { <# .SYNOPSIS Sets file as a runonce next time the system is rebooted .DESCRIPTION Sets file as a runonce next time the system is rebooted, this is used to setup next part of reinstall .PARAMETER Command File to run next boot .EXAMPLE PS C:\> Set-RunOnce 'https://www.website.com/file.ps1' Downloads .ps1 and runs it as admin #> [cmdletbinding()] param ( [string]$Command = '%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file c:\WORK\part3.ps1' ) if (-not ((Get-Item -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce).'Run' )) { New-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce' -Name 'Run' -Value $Command -PropertyType ExpandString } else { Set-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce' -Name 'Run' -Value $Command -PropertyType ExpandString } } function isURIWeb($address) { $uri = $address -as [System.URI] $uri.AbsoluteURI -ne $null -and $uri.Scheme -match '[http|https]' } function Get-IP { Set-Clipboard -Value ((Invoke-WebRequest -uri "http://ifconfig.me/ip").Content) (Invoke-WebRequest -uri "http://ifconfig.me/ip").Content } Function Set-WallPaper { <# .SYNOPSIS Applies a specified wallpaper to the current user's desktop .PARAMETER Image Provide the exact path to the image .PARAMETER Style Provide wallpaper style (Example: Fill, Fit, Stretch, Tile, Center, or Span) .EXAMPLE Set-WallPaper -Image "C:\Wallpaper\Default.jpg" Set-WallPaper -Image "C:\Wallpaper\Background.jpg" -Style Fit https://www.joseespitia.com/2017/09/15/set-wallpaper-powershell-function/ #> param ( [parameter(Mandatory=$True)] # Provide path to image [string]$Image, # Provide wallpaper style that you would like applied [parameter(Mandatory=$False)] [ValidateSet('Fill', 'Fit', 'Stretch', 'Tile', 'Center', 'Span')] [string]$Style ) $WallpaperStyle = Switch ($Style) { "Fill" {"10"} "Fit" {"6"} "Stretch" {"2"} "Tile" {"0"} "Center" {"0"} "Span" {"22"} } If($Style -eq "Tile") { New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 1 -Force } Else { New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 0 -Force } Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; public class Params { [DllImport("User32.dll",CharSet=CharSet.Unicode)] public static extern int SystemParametersInfo (Int32 uAction, Int32 uParam, String lpvParam, Int32 fuWinIni); } "@ $SPI_SETDESKWALLPAPER = 0x0014 $UpdateIniFile = 0x01 $SendChangeEvent = 0x02 $fWinIni = $UpdateIniFile -bor $SendChangeEvent $ret = [Params]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $Image, $fWinIni) } |