Sunday, December 29, 2013

Make PowerShell startup blazing fast!!

If you use PowerShell...You HAVE to run this script! This will cut the time it takes PowerShell to start in half!

Function Improve-GAC { Set-Alias ngen (Join-Path ([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()) ngen.exe)
 [AppDomain]::CurrentDomain.GetAssemblies() |
    sort {Split-path $_.location -leaf} |
    %{
        $Name = (Split-Path $_.location -leaf)
        if ([System.Runtime.InteropServices.RuntimeEnvironment]::FromGlobalAccessCache($_))
        {
            Write-Host "Already GACed: $Name"
        }else
        {
            Write-Host -ForegroundColor Yellow "NGENing      : $Name"
            ngen $_.location | %{"`t$_"}
         }
      }
}Improve-GAC


referance: http://blogs.msdn.com/b/powershell/archive/2007/11/08/update-gac-ps1.aspx

Saturday, December 28, 2013

Backup Windows 8.1

Here is a short little PowerShell Function that I use to create a scheduled job that runs every night at midnight that backups my C:\ drive to my E:\ drive.

The code used to backup Windows 8.1:
wbAdmin start backup -backupTarget:E: -include:C: -quiet

Function Create-ScheduledJob {
<#
.Synopsis
   schedules nightly backups.
.FUNCTIONALITY
   PowerShell v3.0+
#>
[CmdletBinding()]
    Param( [Parameter( Mandatory = $True )]
           $JobName,
           [Parameter( Mandatory = $True )]
           $ScriptToRun,
           $VerbosePreference = "Continue" )

Begin{ $Trigger = (New-JobTrigger -Daily -At 12:01AM) }

Process{ Register-ScheduledJob -Name $JobName -Trigger $Trigger -ScriptBlock { "& wbAdmin start backup -backupTarget:E: -include:C: -quiet" } }

End { Write-Verbose "Your new ScheduledJob has been created successfully!" }

}Create-ScheduledJob


Monday, December 23, 2013

Skip Windows Metro UI at boot

Here is a short PowerShell function that will make Windows boot right to the Desktop; skipping the Metro UI!

Function Disable-MetroAtBoot {
<#
.Synopsis
   Disables Windows booting to the Metro Desktop.
.DESCRIPTION
   Disables Windows booting to the Metro Desktop by modifying the registry. Windows will boot to the Desktop after running this function.
.EXAMPLE
   Disable-MetroAtBoot
   After loging out and back into windows you will have 3 rows on your Windows Metro desktop.
.EXAMPLE
   Disable-MetroAtBoot -Verbose
   After loging out and back into windows you will have 1 row on your Windows Metro desktop.
.NOTES
   After running this script the next time you log into Windows, the first thing you will see is the desktop and not the Metro desktop.
.FUNCTIONALITY
   Windows 8, Windows 8.1
#>
[CmdletBinding()]
          Param ( $VerbosePreference = "Continue" )
    
Begin{ $RegLocation = "HKCU:\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartPage" }

Process{ New-ItemProperty $RegLocation -Name "OpenAtLogon" -Value 0 -PropertyType "DWord" }

End { Write-Verbose "Next time you log into Windows; Windows will boot right to the Desktop!" }

}Disable-MetroAtBoot -Verbose