2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

バッチからPowershellのfunction呼び出し

Last updated at Posted at 2018-07-28

functionの引数をつけて呼び出す

call.bat
@echo off
cd %~dp0
set p1="1234567890"
set p2="abc"
echo %p1%
echo %p2%
powershell -command ". .\called.ps1; test-function -param1 %p1% -param2 %p2%"
called.ps1

function test-function($param1,$param2) {
    Write-Host "12345" $param1 $param2
}

実行結果

"1234567890"
"abc"
12345 1234567890 abc

##呼び出し元バッチのProcessIdを取得する。
powershellで利用する


function Get-ProcessId() {
    return Get-WmiObject win32_process -filter processid=$pid | ForEach-Object{$_.parentprocessid;}
}
2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?