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,