Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell script in one folder calls a script from a second folder results in FileNotFoundException

$
0
0

I have a powershell script located here:

D:\path1\script1.ps1

Within D:\path1\script1.ps1 I need to call D:\path2\script2.ps1. script2.ps1 will in turn load some C# assemblies that are already placed in the D:\path2 folder.

script1.ps1 looks like this:

$otherpath = "D:\path2"

Set-Location -Path $otherpath

Push-Location -Path $otherpath

.\script2.ps1

script2.ps1 looks like this:

[System.Reflection.Assembly]::LoadFrom("MyAssembly.dll") | out-null

So script2.ps1 assumes that MyAssembly.dll live in D:\path2 right next to script2.ps1. However, when I call script1.ps1 from within D:\path1, I get this:

Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly
'file:///D:\path1\MyAssembly.dll' or one of its dependencies. The system cannot find the file
specified."
At D:\path2\script2.ps1:5 char:1
+ [System.Reflection.Assembly]::LoadFrom("MyAssembly.dll") | out-null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

How do I set the path correctly such that when D:\path2\script2.ps1 is called from script1.ps1, the environment has D:\path2 set properly as the working directory?


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>