Created
October 13, 2017 14:24
-
-
Save chrisATautomatemystuff/81f9d6bfb9adae9f4600a2f143258579 to your computer and use it in GitHub Desktop.
My PowerShell Profile (Scrubbed Version)
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
### "#region AND #endregion HELP MAKE SCRIPTS COLLAPSIBLE WITHIN THE ISE" ### | |
### FIND AND CHANGE THE <WHATEVER> PLACEHOLDERS I PUT AS I SCRUBBED THE FILE ### | |
### PLACE THIS FILE IN THE FOLLOWING FOLDER (CREATE IT IF IT DOESN'T EXIST) : C:\USERS\<USERNAME>\DOCUMENTS\WINDOWSPOWERSHELL ### | |
#region Console Customization | |
#ELEVATED CONSOLE? | |
[System.Security.Principal.WindowsPrincipal]$global:currentUser = | |
New-Object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent()) | |
if($global:currentUser.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) { | |
$user = "(Administrator) - " + $global:currentUser.Identities.Name; | |
} | |
else { | |
$user = "(Non-Administrator) - " + $global:currentUser.Identities.Name | |
} | |
(Get-Host).UI.RawUI.WindowTitle = $user + " on " + [System.Net.Dns]::GetHostName() + " (v" + (Get-Host).Version + ")"; | |
#BASE WINDOWTITLE TO ADD TO | |
$originalUIRawUIWindowTitle = (Get-Host).UI.RawUI.WindowTitle | |
#IT'S SILLY, BUT I LIKE IT | |
function Prompt | |
{ | |
Write-Host ("[") -NoNewline -ForegroundColor White | |
Write-Host (Get-Date -Format "MM") -NoNewline -ForegroundColor Gray | |
Write-Host ("/") -NoNewline -ForegroundColor DarkGray | |
Write-Host (Get-Date -Format "dd") -NoNewline -ForegroundColor Gray | |
Write-Host ("/") -NoNewline -ForegroundColor DarkGray | |
Write-Host (Get-Date -Format "yyyy") -NoNewline -ForegroundColor Gray | |
Write-Host (" @ ") -NoNewline -ForegroundColor DarkGray | |
Write-Host (Get-Date -Format "hh") -NoNewline -ForegroundColor Gray | |
Write-Host (":") -NoNewline -ForegroundColor DarkGray | |
Write-Host (Get-Date -Format "mm") -NoNewline -ForegroundColor Gray | |
Write-Host (":") -NoNewline -ForegroundColor DarkGray | |
Write-Host (Get-Date -Format "ss") -NoNewline -ForegroundColor Gray | |
Write-Host ("]") -NoNewline -ForegroundColor White | |
Write-Host (" ") -NoNewline | |
Write-Host ([Environment]::UserDomainName) -NoNewline -ForegroundColor Green | |
Write-Host ("\") -NoNewline -ForegroundColor DarkGreen | |
Write-Host ([Environment]::UserName) -NoNewline -ForegroundColor Green | |
Write-Host (" ") -NoNewline | |
if($global:currentUser.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) { | |
Write-Host ("(Administrator)") -NoNewline -ForegroundColor Red | |
} | |
else { | |
Write-Host ("(Non-Administrator)") -NoNewline -ForegroundColor Magenta | |
} | |
Write-Host (" ") | |
Write-Host ("[") -NoNewline -ForegroundColor White | |
Write-Host ([System.Net.Dns]::GetHostName()) -NoNewline -ForegroundColor Gray | |
Write-Host ("]") -NoNewline -ForegroundColor White | |
Write-Host (" ") -NoNewline | |
Write-Host ("$(Get-Location)>") -NoNewline -ForegroundColor White | |
return " " | |
} | |
#STOP INTIMIDATING ME | |
$host.PrivateData.ErrorForegroundColor = "yellow" | |
#endregion | |
#region Variables | |
$cred_domain1 = "<domainname>\<username>" | |
$dc1_domain1 = "<fqdn dc1>" | |
$dc2_domain1 = "<fqdn dc2>" | |
#endregion | |
#region Modules | |
### IF YOU DON'T HAVE THESE MODULES, COMMENT THE LINES OUT - OR GO DOWNLOAD THE MODULE ### | |
#OOOH SHINY, BUT SOMETIMES I WANT DULL | |
if ([System.Windows.Input.Keyboard]::IsKeyDown('Ctrl') -eq $false) | |
{ | |
Start-Steroids | |
} | |
#I OWE THESE GUYS A BEER | |
Import-Module 'C:\Users\<USERNAME>\Documents\WindowsPowerShell\Modules\AppDeployToolkit\AppDeployToolkitMain.psm1' -Alias 'AppDeployToolkit' -DisableNameChecking -Force | |
#AIN'T NOBODY GOT TIME FOR A UI | |
Import-Module ActiveDirectory | |
Import-Module MsOnline | |
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking | |
Import-Module LyncOnlineConnector | |
#ONE DAY I'LL LEARN THESE COMMANDS | |
Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1' -Alias 'System.Center.Configuration.Manager' | |
#endregion | |
#region Functions | |
#region O365 | |
### SOME OF THIS IS COMMENTED OUT BECAUSE I RARELY WORK IN THAT SYSTEM ### | |
Function Connect-domain1 | |
{ | |
Param( | |
$cred_domain1 = (Get-Credential -Message "Domain 1 Credentials" -UserName "<service account address>") | |
) | |
Try{ | |
#CONNECT TO OFFICE365 | |
Connect-MsolService -Credential $cred_domain1 | |
#CONNECT TO SHAREPOINT ONLINE | |
#Connect-SPOService -Url https://<tenantname>-admin.sharepoint.com -Credential $cred_domain1 | |
#CONNECT TO SKYPE FOR BUSINESS ONLINE | |
#$sfboSession_domain1 = New-CsOnlineSession -Credential $cred_domain1 | |
#Import-PSSession $sfboSession_domain1 | |
#CONNECT TO EXCHANGE ONLINE | |
$exchangeSession_domain1 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/?proxymethod=rps" -Credential $cred_domain1 -Authentication Basic -AllowRedirection | |
Import-PSSession $exchangeSession_domain1 -DisableNameChecking | |
#MULTI-FACTOR AUTHENTICATION IS HARD, MAKE IT EASIER | |
#Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName|?{$_ -notmatch "_none_"}|select -First 1) | |
#CONNECT TO COMPLIANCE CENTER | |
#$ccSession_domain1 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.compliance.protection.outlook.com/powershell-liveid/" -Credential $cred_domain1 -Authentication Basic -AllowRedirection | |
#Import-PSSession $ccSession_domain1 -Prefix cc | |
Clear-Host | |
Write-Host 'You are now managing the <DOMAIN1> domain' | |
(Get-Host).UI.RawUI.WindowTitle = ($originalUIRawUIWindowTitle + " - You are now managing the <DOMAIN1> domain") | |
} | |
Catch{ | |
$_.Exception.Message | |
} | |
} | |
Function Disconnect-domain1 | |
{ | |
Param() | |
Get-PSSession | Remove-PSSession | |
Disconnect-SPOService | |
Write-Host 'You are no longer managing the <DOMAIN1> domain' | |
(Get-Host).UI.RawUI.WindowTitle = ($originalUIRawUIWindowTitle + " - You are no longer managing the <DOMAIN1> domain") | |
} | |
Function Add-MailboxAlias{ | |
Param( | |
[Parameter(Mandatory=$True,Position=1)] | |
$mailboxToAlias = (Read-Host -Prompt 'What mailbox would you like to add an alias to?'), | |
[Parameter(Mandatory=$True)] | |
$aliasToAdd = (Read-Host -Prompt 'What alias address(es) would you like to add?') | |
) | |
Set-Mailbox -Identity $mailboxToAlias -EmailAddresses @{add=$aliasToAdd} | |
} | |
Function Import-PowerCLI { | |
Add-PSSnapin vmware* | |
if (Get-Item 'C:\Program Files (x86)' -ErrorAction SilentlyContinue) { | |
. "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1" | |
} | |
else { | |
. "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1" | |
} | |
} | |
#endregion | |
function Add-CalendarResourceDelegate { | |
Param($roomName, $newDelegate) | |
$resourceDelegates = (Get-CalendarProcessing -Identity $roomName).ResourceDelegates | |
$resourceDelegates += $newDelegate | |
Set-CalendarProcessing -Identity $roomName -ResourceDelegates $resourceDelegates | |
} | |
function Remove-CalendarResourceDelegate { | |
Param($roomName, $delegateToRemove) | |
$resourceDelegates = (Get-CalendarProcessing -Identity $roomName).ResourceDelegates | |
$delegateToRemoveIdentity = (Get-Mailbox $delegateToRemove).Identity | |
$resourceDelegates.Remove($delegateToRemoveIdentity) | |
Set-CalendarProcessing -Identity $roomName -ResourceDelegates $resourceDelegates | |
} | |
#SLOW DOWN AND LET ME READ IF I PIPE YOU TO EASYVIEW | |
function EasyView { | |
process { $_; Start-Sleep -seconds 1} | |
} | |
function Get-NullValue | |
{ | |
foreach ($thing in $input){ | |
$thing.psobject.properties | Where-Object -FilterScript {$_.Value -eq $null} | Select-Object -Property BaseObject, Name | |
} | |
} | |
function Get-AsciiShrug { | |
$OutputEncoding = [System.Text.Encoding]::unicode | |
write-output "¯\_($(0x30C4|%{[char]$_}))_/¯" | clip | |
} | |
function Get-DisapprovalLook { | |
$OutputEncoding = [System.Text.Encoding]::unicode | |
write-output "$(0x0CA0|%{[char]$_})_$(0x0CA0|%{[char]$_})" | clip | |
} | |
Function Roll-Rick ([String[]]$ComputerName) | |
{ | |
$Rick = "We're no strangers to love", | |
"You know the rules and so do I", | |
"A full commitment's what I'm thinking of", | |
"You wouldn't get this from any other guy", | |
"I just want to tell you how I'm feeling", | |
"Gotta make you understand", | |
"Never gonna give you up, never gonna let you down", | |
"Never gonna run around and desert you", | |
"Never gonna make you cry, never gonna say goodbye", | |
"Never gonna tell a lie and hurt you", | |
"We've known each other for so long", | |
"Your heart's been aching but you're too shy to say it", | |
"Inside we both know what's been going on", | |
"We know the game and we're gonna play it", | |
"And if you ask me how I'm feeling", | |
"Don't tell me you're too blind to see", | |
"Never gonna give you up, never gonna let you down", | |
"Never gonna run around and desert you", | |
"Never gonna make you cry, never gonna say goodbye", | |
"Never gonna tell a lie and hurt you", | |
"Never gonna give you up, never gonna let you down", | |
"Never gonna run around and desert you", | |
"Never gonna make you cry, never gonna say goodbye", | |
"Never gonna tell a lie and hurt you", | |
"We've known each other for so long", | |
"Your heart's been aching but you're too shy to say it", | |
"Inside we both know what's been going on", | |
"We know the game and we're gonna play it", | |
"I just want to tell you how I'm feeling", | |
"Gotta make you understand", | |
"Never gonna give you up, never gonna let you down", | |
"Never gonna run around and desert you", | |
"Never gonna make you cry, never gonna say goodbye", | |
"Never gonna tell a lie and hurt you" | |
Invoke-Command -ComputerName $ComputerName -ArgumentList (,$Rick) -ScriptBlock { | |
Param ([String[]]$Rolling) | |
[Reflection.Assembly]::LoadWithPartialName('System.Speech') | Out-Null | |
$Speech = New-Object System.Speech.Synthesis.SpeechSynthesizer | |
ForEach ($Verse in $Rolling) | |
{ | |
$Command = {msg * "$Verse"} | |
$Command | Invoke-Expression | |
$Speech.Speak($Verse) | |
Sleep 1 | |
} | |
} | |
} | |
#endregion | |
#region PSDrives | |
New-PSDrive -Name sccm -PSProvider FileSystem -Root '\\<fqdn to sccm server>\sources$' | |
New-PSDrive -Name staging -PSProvider FileSystem -Root '\\<fqdn to sccm server>\sources$\Applications\~Staging' | |
#endregion | |
#cleanup my o365 sessions | |
Register-EngineEvent PowerShell.Exiting -SupportEvent -Action { | |
$Session = Get-PSSession | Where-Object {$_.ConfigurationName -like "Microsoft.Exchange"} | |
ForEach($obj in $Session){ | |
Remove-PSSession $obj | |
} | |
} | |
#TAKE ME HOME | |
Set-Location 'C:\' | |
#GET OUT OF MY FACE | |
Clear-Host | |
#HERE STRING '@" "@' (HERE STRING MUST END ON POSITION 1 OF IT'S OWN LINE OR IT WON'T WORK) WELCOME MESSAGE TO MYSELF | |
$intro = @" | |
,-._.-._.-._.-._.-. ,-------------------------------------. | |
`-. ,-' | | | |
| | | | | |
| | | | | |
| | | DON'T BREAK STUFF! | | |
| .. ,. | | | | |
,-|___| | |___|-. | | | |
| | L__;__J | | ,' | | |
`| / \ |' / _.-------------------------------------' | |
| ( ) | ;-' | |
| `'' | | |
| | | |
| | | |
;--..._____...--; ==================================. | |
,'--.._/ \_..--`. , |\ | |
/ `. ,' \ /| | \ | |
/ /`. | | _l_ \ / | | \ | |
/_/ \ \_J | |" |\_\ ________________/ | | \ | |
// `-.__.' | | \\ | | | [==] | |
|| | `---' || _____|_____________________________|| | |
|| | || | || | |
|| | || | _____________ || | |
|| | || | ( ) || | |
|| | || | `"""""""""""' || | |
;' | | | `; | || | |
`' \ | / `' | || | |
`--..____/ \____..--' | || | |
| | | | || | |
| | | | || | |
| | | | || | |
| | | | || | |
| | | | || | |
| | | __________| || | |
| | | | || | |
| | | |___________________________________|| | |
| | | | |
| | | | |
|_______|_______| | |
_..--' | | `--.._ | |
;________.___| |___.________; | |
"@ | |
$intro |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment