#*************************************************************************************************************
# Script Name : Microsoft.PowerShellISE_profile.ps1
# Purpose : Set Profile in ISE
# Date : June 4, 2025
# Updated : 9:24 AM 6/4/2025
# Changes : Updated logic and shortened
# Author : Patrick Burwell, www.Burwell.tech
#*************************************************************************************************************
# Set TLS 1.2 for secure connections
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
#DATE Variables
$date = get-date -uformat "%m%d%y-%H" #<---This is NOT MS Date sort convention-hour-'061522-14'
$day = Get-Date -Format yyyyMMdd #<---This is MS Date sort-'20220615'
$thisday = Get-Date -Format MM/dd/yyyy #<---This is NOT MS Date sort-used for Olderthan and Newthan on copy-item - today (so it always copies)-'06/15/2022'
$tomorrow = (get-date).AddDays(+1).ToString("MM/dd/yyyy")#<---This is not MS Date sort-used for Olderthan and Newthan on copy-item - tomorrow - '06/16/2022'
$yesterday = (get-date).AddDays(-1).ToString("yyyyMMdd")#<---This is MS Date sort-yesterday-'20220614'
$daybefore = (get-date).AddDays(11).ToString("MM/dd/yyyy")#<---This is not MS Date sort-used for Olderthan and Newthan on copy-item - tomorrow - '06/16/2022'
$today = (Get-Date -Format yyyyMMdd)+"-"+(get-date -uformat %H) #<--- this is MS date sort-hr - '20220615-14'
# Set ProfileVersion
$ProfileVersion = Get-Date -Format 'MM/dd/yyyy'
$AdminServer = "ns-admfs02"
$PowerShellPath = "D:\PowerShell"
$UserPowerShellPath = "C:\Users\$env:username\Documents\WindowsPowerShell"
# Function to set PSModulePath
function Set-PSModulePath {
param (
[string]$path
)
if ($env:PSModulePath -notlike "$path*") {
$env:PSModulePath = "$path;$env:PSModulePath"
}
}
# Check if running on the admin server
if ($AdminServer -ne $Env:computername) {
if (Test-Path d:\) {
New-Item -ItemType Directory -Path $PowerShellPath -Force | Out-Null
Set-Location $PowerShellPath
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name "PSModulePath" -Value "$PowerShellPath;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules;C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell;C:\Program Files\Microsoft Azure AD Sync\Bin"
Set-PSModulePath "$PowerShellPath\modules"
} else {
New-Item -ItemType Directory -Path $UserPowerShellPath -Force | Out-Null
Set-Location $UserPowerShellPath
Set-PSModulePath "$UserPowerShellPath\modules"
}
} else {
Set-Location $PowerShellPath
Set-PSModulePath "$PowerShellPath\modules"
}
# Create necessary directories
@("input", "output", "log", "SchedTasks", "testing", "modules", "Reports") | ForEach-Object {
New-Item -ItemType Directory -Path "$UserPowerShellPath\$_" -Force -ErrorAction SilentlyContinue | Out-Null
}
# Set Execution Policy
Set-ExecutionPolicy Bypass -Force -Scope CurrentUser -ErrorAction SilentlyContinue
Write-Host "ExecutionPolicy is now" (Get-ExecutionPolicy -Scope CurrentUser) "for the CurrentUser"
# Set aliases
Set-Alias -Name grep -Value sls
Set-Alias -Name Get-Subnets -Value "$PowerShellPath\List-SubnetswithPromptedSitefromADSS.ps1"
Set-Alias -Name np+ -Value "$env:ProgramFiles\notepad++\notepad++.exe"
# Set CMD settings
Set-ItemProperty -Path "HKCU:\Console" -Name InsertMode -Value 1
Set-ItemProperty -Path "HKCU:\Console" -Name HistoryNoDup -Value 1
Set-ItemProperty -Path "HKCU:\Console" -Name HistoryBufferSize -Value 999
Set-ItemProperty -Path "HKCU:\Console" -Name NumberOfHistoryBuffers -Value 999
$Host.UI.RawUI.WindowTitle = "$Env:computername"
Write-Host "Running from $profile"
# Function Prompt
function Prompt {
"$(Get-Location) >"
}
# Display welcome message
Write-Host "Today is $(Get-Date -Format 'MM/dd/yyyy')"
Write-Host "Welcome to $env:computername"
Write-Host "You are logged in as $env:username"
Write-Host "This is PowerShell Version $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion)"
#Set $PSModulePath to $ENV:PSModulePath
$PSModulePath = $ENV:PSModulePath
Write-Host "This is your present PSModulePath: $PSModulePath"
<#
gci Env:
gci Variable:
Get-Variable | Where-Object { $_.Name -like '*ModulePath*' }
#>
PS ISE PROFILE
by
Tags:

Leave a Reply