Sunday, September 4, 2016

Windows Spotlight Wallpapers

If you are anything like me then you were super impressed by the new wallpapers Windows has been pushing out to Windows 10 machines. Well here is a PowerShell function that you can run to find them all, rename them and then sort them into two folders based on the width of the images, some will go into a phone wallpaper folder while the larger images will be saved in the default folder on your desktop.



Function Get-WindowsSpotlightWallpapers{
<#
.Synopsis
   Grabs Windows Spotlight Wallpapers
.DESCRIPTION
   Grabs Microsoft Spotlight Wallpapers and moves them to your desktop, filters out the wallpapers by width and moves the skinny images to a folder for phone wallpapers.
.EXAMPLE
   PS :\> Get-WindowsSpotlightWallpapers
#>
    [CmdletBinding()]
    Param (
            # Path to spotlight files
            [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true,Position=0)]
            $Path = "C:\Users\$env:USERNAME\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets"
          )
            # Moves to the directory the wallpapers are stored in.
            Set-Location -Path $Path
                # copies wallpapers to  folder on you desktop so we don't currupt the originals at all.
                Copy-Item -Path $Path -Recurse -Destination "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\" -Verbose
                    # renames files with .jpeg extention.
                    Get-ChildItem -Path "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\" | Rename-Item -NewName { [io.path]::ChangeExtension($_.name, "jpeg") } -Verbose
                        # deletes files smaller than 25000
                        Get-ChildItem -Path "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\" | Where-Object {$_.Length -lt "25000"} | Remove-Item -Verbose
                           # creates a folder for the phone wallpapers
                            New-Item -Path "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers" -ItemType Directory -Verbose | Out-Null
                            # filter files by image width then moves small files to phone wallpaper directory.
                            Function Get-Image{
                                     [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
                                      $fi=[System.IO.FileInfo]$_          
                                      if( $fi.Exists){
                                                       $img = [System.Drawing.Image]::FromFile($_)
                                                       $img.Clone()
                                                       $img.Dispose()      
                                      } else { Write-Host "File not found: $_" -fore yellow }  
                            }
                            $PhoneWallpapers = Get-ChildItem "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\*.jpeg" -Recurse | % {
                                $image = $_ | Get-Image
                                    New-Object PSObject -Property  @{
                                                                        File = $_.name
                                                                        Fullname = $_.Fullname
                                                                        Height = $image.Height
                                                                        Width = $image.Width
                                    };
                            }
                        # starts 5 second sleep timer
                        Start-Sleep -Seconds 5
                # Goes through wallpapers and moved the smaller width files to the phone wallpaper directory.
                foreach($p in $PhoneWallpapers){
                    if(($p).Width -lt "1081"){
                        Move-Item -Path ($p).fullname -Destination "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers\" -Verbose -Force
                        }
                    if(($p).Width -eq "272"){
                        Move-Item -Path ($p).fullname -Destination "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers\" -Verbose -Force
                        }
               # starts 5 second sleep timer
               Start-Sleep -Seconds 5
                    if(($p).Width -lt "1081"){
                        Move-Item -Path ($p).fullname -Destination "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers\" -ErrorAction SilentlyContinue -Verbose -Force
                        }
                    if(($p).Width -eq "272"){
                        Move-Item -Path ($p).fullname -Destination "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers\" -ErrorAction SilentlyContinue -Verbose -Force
                        }
                }
Set-location "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\"
Invoke-Item "C:\Users\$env:USERNAME\Desktop\Windows Spotlight Wallpapers\"
} # end of function.
Get-WindowsSpotLightWallpapers



After running the script I would recommend setting the newly created folder on your desktop as the folder windows uses to grab you wallpapers from.

Simply hit the windows key and start tyoing 'wallpaper' and you should see something that says choose background....

Enjoy!

Monday, September 28, 2015

Maximus is coming . . .

This has been an ongoing project\side project for myself over the last month or two. It's more or less a PowerShell Module loaded with functions to allow you to do great things at great speeds. In all I think it contains about 30 functions, I'm sure this will continue to fluctuate.... which leads me to why I'm actually writing this, I hope to possible\hopefully treat this page as the HelpURI for Maximus.

but anyhow..... here is one, one I just wrote today actually. This is what I would call an oldie but a goodie.

Function Invoke-Speech {
<#
.SYNOPSIS  
   This functions allows you to make a computer speak.
 
.DESCRIPTION
   This function allows you to make Windows talk with the voice of either Microsoft David or Microsoft Zira.

.EXAMPLE
   PS C:\> Invoke-Speech -Gender Female -Message "You Sir, look like you are ready for a coffee break."

.NOTES  
    
    Version             : 5.0+ Verified
    
    Author/Copyright    : © Matthew Kerfoot - All Rights Reserved
    
    Email/Blog/Twitter  : mkkerfoot@gmail.com  www.TheOvernightAdmin.com  @mkkerfoot
    
    Disclaimer          : THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK
                          OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
                          While these scripts are tested and working in my environment, it is recommended 
                          that you test these scripts in a test environment before using in your production environment
                          Matthew Kerfoot further disclaims all implied warranties including, without limitation, any 
                          implied warranties of merchantability or of fitness for a particular purpose. The entire risk 
                          arising out of the use or performance of this script and documentation remains with you. 
                          In no event shall Matthew Kerfoot, its authors, or anyone else involved in the creation, production, 
                          or delivery of this script/tool be liable for any damages whatsoever (including, without limitation, 
                          damages for loss of business profits, business comerruption, loss of business information, or other 
                          pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, 
                          even if Matthew Kerfoot has been advised of the possibility of such damages

    Assumptions         : ExecutionPolicy of AllSigned (recommended), RemoteSigned or Unrestricted (not recommended)
#>
[CmdletBinding(SupportsShouldProcess)]
                Param(
                        [Parameter(Mandatory=$True, ValueFromPipelineByPropertyName=$true, HelpMessage = "David or Zira?", Position=0)]
                        $Gender,
                        [Parameter(Mandatory=$True, ValueFromPipelineByPropertyName=$true, HelpMessage = "What would you like to say?", Position=1)]
                        $Message
                     )
$Voice = New-Object -ComObject sapi.spvoice
Switch($Gender)
    {
        Male    { $Voice.Voice = $Voice.GetVoices().Item("0") ; $Voice.Speak($Message) }
        Female  { $Voice.Voice = $Voice.GetVoices().Item("1") ; $Voice.Speak($Message) }
        Default { $Voice.Speak($Message) } <# Microsofts default is Male. #>
    }
}
Invoke-Speech -Gender Female -Message "You Sir, look like you are ready for a coffee break."

Sunday, August 2, 2015

How to enable Windows 10 dark theme

Well Windows 10 was released to the general public last week on 7/29/2015. Since then I found out about a cool tweak you can make with just a slight adjustment, This will likely be added to the PC Setting context menu in the future as a toggle button but for now you still have to manually add it by creating a single registry key. Wait really that's it, Yes it is!

I threw in a quick little revert back function called Set-LightTheme just in case you don't like the dark theme(I think you are weird).



Please download functions from the Microsoft Script Repository!








Click here to download the script from the Microsoft Script Repository!