facebook twitter hatena line email

「Windows/powershell」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(macでpowershell実行)
 
(同じ利用者による、間の9版が非表示)
行1: 行1:
==powershellインストール==
+
[[Windows/powershell/インストール]]
https://docs.microsoft.com/ja-jp/powershell/scripting/install/installing-powershell-core-on-macos?view=powershell-7.1
+
  
macであれば、powershell-x.x.x-osx-x64.pkg をDL
+
[[Windows/powershell/コーディング規約]]
  
==windowsでpowershell実行==
+
[[Windows/powershell/基本]]
$ ./tmp/hoge.ps1
+
  
/tmp/hoge.ps1
+
[[Windows/powershell/文字列]]
echo 'hoge'
+
  
==macでpowershell実行==
+
[[Windows/powershell/ファイル文字]]
$ /usr/local/bin/pwsh /tmp/hoge.ps1
+
  
/tmp/hoge.ps1
+
[[Windows/powershell/関数]]
echo 'hoge'
+
  
==windowsのpowershell.exeの場所==
+
[[Windows/powershell/クラス]]
C:\Windows\System32\WindowsPowerShell\v1.0
+
==windowsのpowershell_iseとは==
+
編集と、実行ができるツール
+
  
==powershellバージョン確認==
+
[[Windows/powershell/ini読込]]
===コマンドで実行===
+
$ /usr/local/bin/pwsh $PSVersionTable
+
PowerShell 7.1.3
+
  
===spに記述して実行===
+
[[Windows/powershell/eval]]
version.sp1
+
$PSVersionTable
+
  
実行
+
[[Windows/powershell/posh-git]]
$ /usr/local/bin/pwsh version.sp1
+
<pre>
+
Name                          Value
+
----                          -----
+
PSVersion                      7.1.3
+
PSEdition                      Core
+
GitCommitId                    7.1.3
+
OS                            Darwin 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64
+
Platform                      Unix
+
PSCompatibleVersions          {1.0, 2.0, 3.0, 4.0…}
+
PSRemotingProtocolVersion      2.3
+
SerializationVersion          1.1.0.1
+
WSManStackVersion              3.0
+
</pre>
+
 
+
==変数==
+
$path = "hoge.txt";
+
 
+
==変数で定義したpathを使用==
+
$path = "hoge.txt";
+
$data = Get-Content $path
+
 
+
==テキスト文置換==
+
aaaをcccへ置換
+
$data = Get-Content hoge.txt | % { $_ -replace "aaa", "ccc" }
+
$data | Out-File hoge.txt
+
 
+
参考:https://teratail.com/questions/290149
+
 
+
===エスケープ文字対応===
+
[]などは、\でエスケープする
+
$data = Get-Content hoge.txt | % { $_ -replace "aaa\[hoge\]", "ccc[piyo]" }
+
 
+
==実行ファイルのdirpath==
+
version3未満の場合
+
$ScriptDir = $MyInvocation.MyCommand.Path
+
echo $ScriptDir
+
 
+
version3以上の場合
+
$ScriptDir = $PSScriptRoot
+
echo $ScriptDir
+
 
+
参考:https://www.vwnet.jp/Windows/PowerShell/pwd.htm
+

2021年8月30日 (月) 20:49時点における最新版

Windows/powershell/インストール

Windows/powershell/コーディング規約

Windows/powershell/基本

Windows/powershell/文字列

Windows/powershell/ファイル文字

Windows/powershell/関数

Windows/powershell/クラス

Windows/powershell/ini読込

Windows/powershell/eval

Windows/powershell/posh-git