LinuxなどUNIX系のシェルでターミナル起動時に実行されるスクリプトを記述しておく .profile や .bash_profile などと同等の事をPowerShellで実現する 方法を以下に記します。
PowerShellのコンソールを起動し、$profile と入力しEnterキーを押してみてください。
出力されたパスがPowerShell起動時に読み込まれるスクリプトとなります。
以下に出力例を記します。
PS C:\Users\Sakura> $profile C:\Users\Sakura\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
$profileにより、配置するディレクトリおよびファイル名が分かったので作成してみます。
以下、上記の$profileの出力をもとにした手順です。
みなさんの環境にあった値で読み替えてください。
mkdir C:\Users\Sakura\Documents\WindowsPowerShell\
notepad $profile
# Office2013 Path
$Env:Path += ";C:\Program Files\Microsoft Office 15\root\office15"
# Google Chrome Path
$Env:Path += ";C:\Program Files\Google\Chrome\Application"
# Function
Function touch($file) {
If (Test-Path $file) {
(Get-Item $file).LastWriteTime = Get-Date
} Else {
Out-File -encoding Default $file
}
}
Function uptime() {
[DateTime]::Now - [Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime) |
Select-Object Days, Hours, Seconds, Milliseconds| Format-Table -AutoSize
}以上、PowerShell起動時にスクリプトを読み込み実行する方法でした。