2

I'm trying to specify parameters in a powershell script, from a batch file.

The script itself looks likes this:

    Param(
    [Parameter(Mandatory=$true,HelpMessage="Application switch")]
    [string[]]$Apps,
    [ValidateRange(3,9999)]
    [int]$SwitchDelay = 30

$AppPids = @()
$Windows = Get-Process | ? { $_.MainWindowTitle -ne "" }
$Wsh = New-Object -COM Wscript.Shell

foreach ($App in $Apps) {
    foreach ($Window in $Windows) {
        if ($Window.MainWindowTitle -like $App) {
            Write-Verbose "Vindusfilter ""$App"" found hit on ""$($Window.MainWindowTitle)"" med PID ""$($Window.Id)"""
           $AppPids += $Window.Id
        }
    }
}

do {
    foreach ($ID in $AppPIDS) {
        # Hides text...
        $Wsh.AppActivate($ID) | Out-Null
        Start-Sleep -Seconds $SwitchDelay
        Write-Verbose "Changed window to PID ""$ID"""
    }
} while ($true)

And what I'm trying to do is to define in a batch file is something like:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\AppRotate.ps1" -Apps "*Chrome*", "Spotify*" -Switchdelay 5
pause

(Supposed to show error message here, need more reputation first...) Error: "... PositionalParameterNotFound.Approtate.ps1"

I'm basically new to scripting, so any ideas?

2
  • Where is your closing bracket for Param( Commented Nov 6, 2014 at 14:42
  • It got lost during copy/paste :) Commented Nov 7, 2014 at 8:54

1 Answer 1

2
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File   "C:\AppRotate.ps1" -Apps "*Chrome*","Spotify*" -Switchdelay 5

The problem was the space between the first, and second variable of parameter -Apps.

Should work now.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, can't belive I missed that. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.