Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Management.Automation.ParameterBindingException: A parameter cannot be found that matches parameter name 'Provider'. #665

Open
penalvch-zz opened this issue Dec 25, 2021 · 0 comments

Comments

@penalvch-zz
Copy link

penalvch-zz commented Dec 25, 2021

Steps to reproduce

Running $test.ps1 as part of a scheduled task via an administrative user intermittently shows the below error. It's seems to be root caused to dot sourcing inside a foreach-object -parallel as a job, as I cannot reproduce via dot sourcing a script without using foreach-object -parallel.

The partial WORKAROUND is don't dot source inside a foreach-object -parallel -asjob, but then you cannot as easily utilize runspace background jobs.

Computer has latest drivers, BIOS, firmware, and updates applied, with AV turned off.

$test.ps1

foreach-object -parallel {. c:\scripts\check.ps1} -asjob

check.ps1

try{
    $null=import-module -name PackageManagement,powershellget
    if((get-installedmodule -name simplysql -ea 0).count -eq 0){
        $null=(install-module -acceptlicense -name SimplySql -scope currentuser)
    }
}catch{
    $ei_h=$_
    $ge_h=get-error
    $exception_h=$ei_h.Exception
    $line_h=$ei_h.InvocationInfo.ScriptLineNumber
    $stringerr_h=-join('Error. Investigate.',"`n",'$line_h=',$line_h,"`n",'$exception_h=',"`n",$exception_h,"`n",'get-error=',"`n",$ge_h)
    $mtoday_h=get-date -uformat '%Y%m%d%H%M'
    $problem_h="$env:userprofile\$mtoday_h-problem.txt"
    $streamp_h=[System.IO.StreamWriter]$problem_h
    $streamp_h.write($stringerr_h)
    $streamp_h.close()
    exit 1
}

test.xml

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2021-12-22T16:06:10.889206</Date>
    <Author>TEST\admin</Author>
    <URI>\test\test</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2021-12-23T04:01:00-05:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-21-4026033148-167229773-3407019803-1001</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>false</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>pwsh.exe</Command>
      <Arguments>-nologo -windowstyle hidden -ExecutionPolicy Bypass -command ". c:\scripts\test.ps1; exit $LASTEXITCODE"</Arguments>
      <WorkingDirectory>c:\scripts</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

Expected behavior

$null=import-module -name PackageManagement,powershellget
>> if((get-installedmodule -name simplysql -ea 0).count -eq 0){
>>     $null=(install-module -acceptlicense -name SimplySql -scope currentuser)
>> }
PS C:\Windows\System32>

Actual behavior

System.Management.Automation.ParameterBindingException: A parameter cannot be found that matches parameter name 'Provider'.
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at Get-InstalledModule<Process>(Closure , FunctionContext )
   at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
   at System.Management.Automation.PSScriptCmdlet.DoProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()

Environment data

get-error
A parameter cannot be found that matches parameter name 'Provider'.
$psversiontable

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Get-Module -ListAvailable PowerShellGet,PackageManagement

    Directory:
C:\Users\system2\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name
---------- -------    ---------- ----
Script     2.2.5                 PowerShellGet

    Directory: C:\program
files\powershell\7\Modules

ModuleType Version    PreRelease Name
---------- -------    ---------- ----
Script     1.4.7                 PackageManag…
Script     2.2.5                 PowerShellGet

    Directory: C:\Program
Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name
---------- -------    ---------- ----
Binary     1.0.0.1               PackageManag…
Script     1.0.0.1               PowerShellGet

PS C:\Windows\System32>
Get-PackageProvider -ListAvailable

Name                     Version          Dyna
                                          micO
                                          ptio
                                          ns
----                     -------          ----
NuGet                    3.0.0.1          Des…
PowerShellGet            2.2.5.0          Pac…
PowerShellGet            1.0.0.1

PS C:\Windows\System32>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant