Pass parameter to powershell command from bat script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
suadhm
Posts: 13
Joined: 05 Feb 2019 05:22

Pass parameter to powershell command from bat script

#1 Post by suadhm » 25 Aug 2023 01:51

Hi,

Is there any way that I can pass parameter in batch script to powershell command executed by that script.
Script is like this:

Code: Select all

echo.
set /p PROC=Enter Proces Name: 
echo.
$TrackProcessName = "*%PROC%*"
$EstablishedConnections = Get-NetTCPConnection -State Established |Select-Object -Property LocalAddress, LocalPort,@{name='RemoteHostName';expression={(Resolve-DnsName $_.RemoteAddress).NameHost}},RemoteAddress, RemotePort, State,@{name='ProcessName';expression={(Get-Process -Id $_.OwningProcess). Path}}, OffloadState,CreationTime
Foreach ($Connection in $EstablishedConnections)
{
If ($Connection.ProcessName -like $TrackProcessName)
{
$Connection|ft
}
}


So I need to pass parameter %PROC% to $TrackProcessName = "*%PROC%*". This way it does not work.

Any suggestion?

Regards,

Post Reply