dominikradko
dominikradko

Reputation: 1

Can't save new-alias even if i made ps1 file

i've used command:

Get-Variable profile | Format-List

i did it for check where is my powershell profile folder. After i did it it showed me this path:

C:\Users\Dom\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1

I opened this path and file named Microsoft.PowerShellISE_profile.ps1 where i've saved my alias with command: New-Alias rc Restart-Computer but this alias doesn't work.. Powershell act like this file never existed.. Any suggestions?

Upvotes: 0

Views: 184

Answers (1)

user6811411
user6811411

Reputation:

This script will look for $Search through the 4 profiles for the current host and print the finds with 4 lines of context:

## Search-PSProfiles.ps1
$ProfileNames = $PROFILE | Get-Member -MemberType noteproperty | select -Expandproperty Name
$Search = 'Restart'
ForEach ($Prof in $ProfileNames){
  $ThisProfile = $Profile."$Prof"
  if (Test-Path $ThisProfile){
  "{0,25} search for $Search in $ThisProfile " -f "`$Profile.$Prof" 
    Get-Content $ThisProfile|Select-String -AllMatches $Search -Context 0,4
  } else {
  "{0,25} doesn't exist ({1})" -f "`$Profile.$Prof",$ThisProfile
  }
}

Sample output started from a PoSh console:

$Profile.AllUsersAllHosts doesn't exist (C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1)
$Profile.AllUsersCurrentHost doesn't exist (C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1)
$Profile.CurrentUserAllHosts search for restart in C:\Users\UserName\Documents\WindowsPowerShell\profile.ps1

> New-Alias rc Restart-Computer
$Profile.CurrentUserCurrentHost search for restart in C:\Users\UserName\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

Upvotes: 1

Related Questions