0

I have hunted for an answer to my problem for two days. Yes I looked through previous asked questions on StackOverflow.

I am using a variable in a batch file.

set WorkingPath = "C:\Users\Workingpath\"
for /R %WorkingPath% %%? IN (*.txt) do (
  echo Current Variable %%~f?
  cmd /k Powershell.exe -executionpolicy remotesigned -File .\PowerShellFeature.ps1 -input %%~f?
)

I put an echo to prove that %%~f? does have a variable before sending it to PowerShell. However, passed to this cmdlet:

Param(
    [Parameter(Mandatory=$true)]
    [string]$input
)
Write-Host "Current input: " $input
$variable = Get-Item -Path $input
$date = $variable.LastWriteTime

No matter how I format the PowerShell parameters I get error "-input is null". I've tried using different variable types for the parameter.

If PowerShell had a recursive find I could just do it in PowerShell but recursive find is CMD function.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Madmatter
  • 1
  • 1
  • `$input` is an [automatic variable](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-3.0). Do not use it as a parameter name. If you must use something with "input" use `$InputObject` instead. – Ansgar Wiechers Feb 07 '18 at 19:12
  • https://stackoverflow.com/questions/8677628/recursive-file-search-using-powershell is also a good answer to my problem. – Madmatter Feb 07 '18 at 19:12
  • Why not just do the whole thing in powershell? – EBGreen Feb 07 '18 at 19:14

0 Answers0