Re: issue resolved
Thanks for sharing your solution.
reg add hklm\software\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
reg add hklm\software\wow6432node\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
COMPLUS_version
, not v4.0.0.0
.
set COMPLUS_version=v4.0.0.0
powershell -File C:\Users\sysadmin.kai\Desktop\test.ps1
Version v4.0.30319 of the .NET Framework is not installed and it is required to
run version 3 of Windows PowerShell.
Microsoft .NET Framework 4 is already a part of this operating system. You do not need to install the .NET Framework 4 redistributable. <A HREF="http://go.microsoft.com/fwlink/?LinkId=164207">More information</A>.
Major Minor Build Revision
----- ----- ----- --------
4 0 30319 42000
[Environment]::Version
COMPLUS_version
has to be set before you start PowerShell. Not in the PowerShell script itself - that's too late. You can for example wrap your PowerShell execution to a batch file:
set COMPLUS_version=v4.6.01055.394271
powershell -File script.ps1
PSChildName Version Release
----------- ------- -------
v2.0.50727 2.0.50727.4927
v3.0 3.0.30729.4926
Windows Communication Foundation 3.0.4506.4926
Windows Presentation Foundation 3.0.6920.4902
v3.5 3.5.30729.4926
Client 4.6.01055 394271
Full 4.6.01055 394271
Client 4.0.0.0
set COMPLUS_version=v4.6.01055.394271
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::sftp
HostName = "deleted"
UserName = "deleted"
Password = "deleted"
SshHostKeyFingerprint = "deleted"
}
$session = New-Object WinSCP.Session
# Connect
$session.Open($sessionOptions)
# set filenames - if executed on a monday subtract three days
if((get-date).dayofweek -match 'Monday')
{$filedate = (Get-Date).adddays(-3)}
else
{$filedate = (Get-Date).adddays(-1)}
$file1 = 'TORON_RH' + $filedate.ToString('yyyyMMdd') + '.csv'
$file2 = 'TORON_RC' + $filedate.ToString('yyyyMMdd') + '.csv'
$file3 = 'TORON_RT' + $filedate.ToString('yyyyMMdd') + '.csv'
# Download files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult =
$session.GetFiles("/users/TORON/RPT/" + $file1, "\\ta_nas\Cidel\ReconData\NBCN\Toron\", $False, $transferOptions)
$transferResult.Check()
$transferResult =
$session.GetFiles("/users/TORON/RPT/" + $file2, "\\ta_nas\Cidel\ReconData\NBCN\Toron\", $False, $transferOptions)
$transferResult.Check()
$transferResult =
$session.GetFiles("/users/TORON/RPT/" + $file3, "\\ta_nas\Cidel\ReconData\NBCN\Toron\", $False, $transferOptions)
$transferResult.Check()
# Disconnect, clean up
$session.Dispose()
PowerShell script. The corresponding line is ' Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Could not load file or assembly 'file:///C:\Program Files (x86)\WinSCP\WinSCPnet.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. '. Process Exit Code -1. The step failed.\