As per my comment, you are mixing syntax improperly.
%~dp0
...is not any PowerShell will understand. The PowerShell equivalent of that is...
$PSScriptRoot
Also, You are trying to run batch/cmd syntax in your -File
switch. PS has no idea what that is. That is not a file name.
You then have a Get-ChildIem alias on the same line and it's not terminated, so, again, that is not proper PowerShell code. It this,
PowerShell.exe -ExecutionPolicy Bypass -File %~dp0Check.ps1;"dir | tee D:\temp\output.txt"
...but again, this is not valid PS code, because of the mixed syntax.
The PowerShell equivalent of %~dp0
is...
$PSScriptRoot
PS has tons of special/reserved characters, and %
, is an alias for ForEach-Object, and that ```~``, has no meaning in PS.
Get-Alias -Name '%'
# Results
<#
CommandType Name Version Source
----------- ---- ------- ------
Alias % -> ForEach-Object
#>
Get-Alias -Name '~'
# Results
<#
Get-Alias : This command cannot find a matching alias because an alias with the name '~' does not exist.
#>
You can just do this in PS.
Copy-Item -Path $Source -Destination $Target -Recurse -Force |
Tee-Object -FilePath 'C:\temp\output.txt'
... or again, just use Robocopy.exe.
MSDocs: robocopy
Copies file data from one location to another.
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
https://www.delftstack.com/howto/powershell/powershell-robocopy/
tee-object
in your check.ps1