powershell script equivalent to bashrc
Share
Download ▾
powershell script equivalent to bashrc
PowerShell profile initialization
if (-not (Test-Path PROFILE)) {
New-Item -Path PROFILE -ItemType "file" -Value "" | Out-Null
}
Function to start the PowerShell session
function Start-PowerShellSession {
# Your custom logic to start the session
}
Function to add a new alias
function Add-PowerShellAlias {
param (
[string]Name,[string]Value
)
Set-Alias -Name Name−ValValue
}
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
u
e
Function to add a new function
function Add-PowerShellFunction {
param (
[string]Name,[scriptblock]ScriptBlock
)
Set-Alias -Name Name−ValueScriptBlock
}
Function to add a new module
function Import-PowerShellModule {
param (
[string]ModuleName)Import−ModuleModuleName
}
Function to add a new environment variable
function Set-PowerShellEnvironmentVariable {
param (
[string]Name,[string]Value
)
[Environment]::SetEnvironmentVariable(Name,Value, [System.EnvironmentVariableTarget]::User)
}
Function to add a new path to the system PATH variable
function Add-PowerShellPath {
param (
[string]Path)env:Path += ";Path"[Environment]::SetEnvironmentVariable(′Path′,env:Path, [System.EnvironmentVariableTarget]::User)
}
Function to add a new command to the PowerShell prompt
function Add-PowerShellPromptCommand {
param (
[scriptblock]Command
)
function global:prompt {
& Command
"> "
}
}
Example usage of the functions
Start-PowerShellSession
Add-PowerShellAlias -Name "ll" -Value "Get-ChildItem"
Add-PowerShellFunction -Name "gci" -ScriptBlock {Get-ChildItem}
Import-PowerShellModule -ModuleName "Pester"
Set-PowerShellEnvironmentVariable -Name "PSModulePath" -Value "env:PSModulePath;C:\CustomModules"
Add-PowerShellPath -Path "C:\CustomTools"
Add-PowerShellPromptCommand -Command {Write-Host "PSModulePath: ($env:PSModulePath)" -NoNewline}