Last active
December 17, 2020 20:37
-
-
Save kensleDev/3a07cbaa0be7b46135c65dfecc94ef67 to your computer and use it in GitHub Desktop.
Widnows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -RunAsAdministrator | |
Set-ExecutionPolicy Bypass -Scope Process -Force | |
$reposPath = "$env:userprofile/repos" | |
$envPath = "$reposPath/env/windows_local" | |
$powershellPath = "$env:userprofile/Documents/WindowsPowershell" | |
$log = "" | |
Function InstallChocolatey { | |
if (!(Test-Path -Path "$env:ProgramData\Chocolatey")) { | |
Invoke-Expression((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) | |
refreshenv | |
Write-Output "Chocolatey installed." | |
} else { | |
Write-Output "Chocolatey already installed." | |
} | |
} | |
Function InstallSoftware { | |
choco install git --params='/NoShellIntegration' -y | |
$env:path+='C:\Program Files\Git\cmd' | |
Output-Title "Git installed" | |
choco install poshgit -y | |
refreshenv | |
Output-Title "Posh Git installed" | |
choco install openssh -y | |
refreshenv | |
Output-Title "Open Ssh installed" | |
choco install virtualbox -y | |
refreshenv | |
Output-Title "Virtualbox installed" | |
choco install vagrant | |
refreshenv | |
Output-Title "Vagrant installed" | |
} | |
Function PullRepo { | |
if (!(Test-Path -Path "$reposPath")) { | |
mkdir repos | |
} | |
if (!(Test-Path -Path "$envPath")) { | |
cd $reposPath | |
git clone https://github.com/kensleDev/env.git | |
Output-Title "Repo doesn't exists, pulled from github" | |
} else { | |
cd $envPath | |
git pull | |
Output-Title "Repo already exists, pulled latest content" | |
} | |
} | |
Function CopyDotfiles { | |
cd $envPath | |
Copy-Item -Force "./dotfiles/Microsoft.PowerShell_profile.ps1" $powershellPath | |
Output-Title "Copied Dotfiles" | |
} | |
function Output-Title { | |
param([string] $text) | |
$output = @" | |
------------------------------------------------- | |
-> $text | |
------------------------------------------------- | |
"@ | |
$log += "-> $text \n" | |
echo $output | |
} | |
Function DisplayLog { | |
echo "" | |
echo "" | |
echo "" | |
echo "===============================================" | |
echo "" | |
echo $log | |
echo "" | |
echo "===============================================" | |
} | |
InstallChocolatey | |
InstallSoftware | |
PullRepo | |
CopyDotfiles | |
# DisplayLog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GetLog( | |
[string]$log, | |
[string]$type, | |
[int16]$limit, | |
[datetime]$after, | |
[datetime]$before, | |
[string]$messageFilter | |
) { | |
$title = $log + ' | ' + $type + ' | latest:' + $limit + ' | from: ' + $after + ' to:' + $after + ' | filter: ' + $messageFilter | |
Get-EventLog -LogName $log -EntryType $type -Newest $limit -After $after -Before $before | Where-Object { $_.message –match $messageFilter } | Out-GridView -PassThru -Title $title | |
} | |
GetLog "Application" "Error" 10 "4/07/19 10:17" "5/07/19 10:17" $filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ensure that Get-ChildItemColor is loaded | |
Import-Module Get-ChildItemColor | |
# Set l and ls alias to use the new Get-ChildItemColor cmdlets | |
Set-Alias l Get-ChildItemColor -Option AllScope | |
Set-Alias ls Get-ChildItemColorFormatWide -Option AllScope | |
# Helper function to change directory to my development workspace | |
# Change c:\ws to your usual workspace and everytime you type | |
# in cws from PowerShell it will take you directly there. | |
function cws { Set-Location c:\ws } | |
# Helper function to set location to the User Profile directory | |
function cuserprofile { Set-Location ~ } | |
Set-Alias ~ cuserprofile -Option AllScope | |
# Helper function to show Unicode character | |
function U | |
{ | |
param | |
( | |
[int] $Code | |
) | |
if ((0 -le $Code) -and ($Code -le 0xFFFF)) | |
{ | |
return [char] $Code | |
} | |
if ((0x10000 -le $Code) -and ($Code -le 0x10FFFF)) | |
{ | |
return [char]::ConvertFromUtf32($Code) | |
} | |
throw "Invalid character code $Code" | |
} | |
# Ensure posh-git is loaded | |
Import-Module -Name posh-git | |
# Start SshAgent if not already | |
# Need this if you are using github as your remote git repository | |
if (! (ps | ? { $_.Name -eq 'ssh-agent'})) { | |
Start-SshAgent | |
} | |
# Ensure oh-my-posh is loaded | |
Import-Module -Name oh-my-posh | |
# Default the prompt to agnoster oh-my-posh theme | |
Set-Theme agnoster |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment