# Execute PowerShell Script : path being dropped from script name

**URL:** https://www.finalbuilder.com/forums/t/execute-powershell-script-path-being-dropped-from-script-name/2240
**Category:** Discussion
**Created:** [January 17, 2014, 10:13am UTC](https://www.finalbuilder.com/forums/t/execute-powershell-script-path-being-dropped-from-script-name/2240 "2014-01-17T10:13:35Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![davestiff](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/d/f08c70/32.png) [@davestiff](https://www.finalbuilder.com/forums/u/davestiff)
#### Post date: [January 17, 2014, 10:13am UTC](https://www.finalbuilder.com/forums/t/execute-powershell-script-path-being-dropped-from-script-name/2240/1 "2014-01-17T10:13:35Z")

</div>

Hello,

I am trying to run C:\PowerShell\scripts\CheckForLockedInstallers.ps1 and the action is failing:

```
.\CheckForLockedInstaller.ps1 : The term '.\CheckForLockedInstaller.ps1' is
not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
```

I don't understand where the path is gone to. Does the action only execute scripts in the same folder as itself?

Thanks,  
Dave

---

<div class="post-metadata">

### Author: ![nevar](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/n/c4cdca/32.png) [@nevar](https://www.finalbuilder.com/forums/u/nevar)
#### Post date: [January 19, 2014, 11:28am UTC](https://www.finalbuilder.com/forums/t/execute-powershell-script-path-being-dropped-from-script-name/2240/2 "2014-01-19T11:28:29Z")

</div>

Hi Dave,   
  
 Which version of FinalBuilder are you running at this stage? Also what is the contents of the powershell script which your trying to run.

---

<div class="post-metadata">

### Author: ![davestiff](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/d/f08c70/32.png) [@davestiff](https://www.finalbuilder.com/forums/u/davestiff)
#### Post date: [January 20, 2014, 2:29am UTC](https://www.finalbuilder.com/forums/t/execute-powershell-script-path-being-dropped-from-script-name/2240/3 "2014-01-20T02:29:28Z")

</div>

Hi,

I am using FinalBuilder 7.0.0.2641

Essentially the PowerShell script runs OPENFILES.EXE and will report any locked files:

# Script to monitor SERVERNAME for open (locked) files  
param (  
&nbsp;&nbsp; &nbsp;[Parameter(Mandatory=$True,Position=1)]  
&nbsp;&nbsp;&nbsp; [string]$exeName  
)  
  
$serverName = "\\SERVERNAME.COM"  
$outputFile = "$env:TEMP\openfiles.txt"  
$smtpServer = "SMTPSERVER"  
$to = "person@domain.com"  
$cc = "person@domain.com"  
$from = $env:USERNAME + "@domain.com"  
$remoteRoot = "REMOTEFOLDER"  
$localRoot = "LOCALFOLDER"  
&nbsp;&nbsp; &nbsp;  
Clear-Host  
&nbsp;&nbsp; &nbsp;  
# query the server for open files (OPENFILES.EXE)  
$openFileList = openfiles /QUERY /S $serverName /FO CSV /V \> $outputFile  
$csv = Import-CSV $outputFile  
  
foreach($item in $csv) {  
  
&nbsp;&nbsp;&nbsp; $fileID = $item.ID  
&nbsp;&nbsp;&nbsp; $userID = $item."Accessed By"  
&nbsp;&nbsp;&nbsp; $locks = $item."#Locks"  
&nbsp;&nbsp;&nbsp; $openFile = $item."Open File (Path\executable)"  
&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp;&nbsp; Write-Host "$openFile : $locks - $userID"  
  
&nbsp;&nbsp;&nbsp; # get the path of the local installer on SERVERNAME  
&nbsp;&nbsp;&nbsp; $localFile = $exeName  
&nbsp;&nbsp;&nbsp; $localFile = $localInstaller.Replace($remoteRoot,$localRoot)  
&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp;&nbsp; if ($openFile -eq $localFile) {   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Host "Locked File Detected!"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # email details  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #$to = "$userID@domain.com"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $dateTime = Get-Date -Format g  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $subject = "Warning: locked file on $serverName - $dateTime"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $body = "USER: $userID  
"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $body += "FILE: $exeName  
"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $body += "ID: $fileID  
"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $body += "LOCKS: $locks  
"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $body += "WARNING: This file is currently locked and may cause the build to fail.  
"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $body += "The lock will be broken at the end of the build to prevent failure.  
"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $body += "You have 60-90 minutes before this happens. Please ensure the file is unlocked to prevent any data loss.  
"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $body += "  
  
"  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;$body += "Automated email sent from computer: $env:COMPUTERNAME"&nbsp; &nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# send the email  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Send-MailMessage -SmtpServer $smtpServer -To $to -Cc $cc -From $from -Subject $subject -Body $body -BodyAsHtml -Priority high  
&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp; &nbsp;  
}

Thanks!

Dave

---

<div class="post-metadata">

### Author: ![nevar](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/n/c4cdca/32.png) [@nevar](https://www.finalbuilder.com/forums/u/nevar)
#### Post date: [January 21, 2014, 3:23am UTC](https://www.finalbuilder.com/forums/t/execute-powershell-script-path-being-dropped-from-script-name/2240/4 "2014-01-21T03:23:12Z")

</div>

Hi Dave,   
  
 I have created a FinalBuilder project with your script and haven’t the issue your experiencing. Possibly its to do with the way in which the path is being defined. Is the script specified in a variable at all? Also are there any other actions which execute prior which are working on the same directory?

---

<div class="post-metadata">

### Author: ![davestiff](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/d/f08c70/32.png) [@davestiff](https://www.finalbuilder.com/forums/u/davestiff)
#### Post date: [January 21, 2014, 2:34am UTC](https://www.finalbuilder.com/forums/t/execute-powershell-script-path-being-dropped-from-script-name/2240/5 "2014-01-21T02:34:45Z")

</div>

Hi,  
  
I have tried both ways. Browsing for the file and using a hard-coded path and defining a variable for the path.  
  
I am using a test project with just one action.  
  
I will test it on another machine to see if it is something specific to my environment.  
  
Thanks!  
Dave

---

<div class="post-metadata">

### Author: ![davestiff](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/d/f08c70/32.png) [@davestiff](https://www.finalbuilder.com/forums/u/davestiff)
#### Post date: [January 21, 2014, 2:55am UTC](https://www.finalbuilder.com/forums/t/execute-powershell-script-path-being-dropped-from-script-name/2240/6 "2014-01-21T02:55:13Z")

</div>

Hi,  
  
I tried this on one of my build machines and it is working.  
  
I think it might be related to our “My Documents”, “Favorites”, etc. being stored on a network location. This means the PowerShell profile is on a network path as well. It might be causing an issue.  
  
Thanks,  
Dave

---

<div class="post-metadata">

### Author: ![nevar](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/n/c4cdca/32.png) [@nevar](https://www.finalbuilder.com/forums/u/nevar)
#### Post date: [January 21, 2014, 11:24am UTC](https://www.finalbuilder.com/forums/t/execute-powershell-script-path-being-dropped-from-script-name/2240/7 "2014-01-21T11:24:53Z")

</div>

Hi Dave,   
  
 I can see what the issue could be potentially. So if I understand you correctly the PowerShell profile could be using UNC paths. I am wondering if any other part of what is occurring here is also on a UNC path. E.g. the current directory of the FinalBuilder script, the directory the FinalBuilder script lives in, or directories which are mapped to UNC paths.   
  
 I will test this here locally today and see what I get. From memory FinalBuilder does some manipulation with regards to UNC paths to avoid some issues.

---

<div class="post-metadata">

### Author: ![nevar](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/n/c4cdca/32.png) [@nevar](https://www.finalbuilder.com/forums/u/nevar)
#### Post date: [January 22, 2014, 1:33am UTC](https://www.finalbuilder.com/forums/t/execute-powershell-script-path-being-dropped-from-script-name/2240/8 "2014-01-22T01:33:58Z")

</div>

Hi Dave,   
  
 After testing using a powershell profile I believe I am still missing some pieces to this puzzle. Would you be able to send your project, or a screen shot of the settings your using in the powershell action to support? I believe this will give me the last insights I require for a solution here.   
  
 Thanks.

---

<div class="post-metadata">

### Author: ![davestiff](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/d/f08c70/32.png) [@davestiff](https://www.finalbuilder.com/forums/u/davestiff)
#### Post date: [January 22, 2014, 2:50am UTC](https://www.finalbuilder.com/forums/t/execute-powershell-script-path-being-dropped-from-script-name/2240/9 "2014-01-22T02:50:27Z")

</div>

Hi Jason,  
  
thanks for looking into this!  
  
My script is as above. My PowerShell profile paths are:

```
Path&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ------  
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AllUsersAllHosts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; False  
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE\_profile.ps1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AllUsersCurrentHost&nbsp;&nbsp;&nbsp;&nbsp; False  
\SERVERNAME\HomeDirectory\dstiff\My Documents\WindowsPowerShell\profile.ps1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CurrentUserAllHosts&nbsp;&nbsp;&nbsp;&nbsp; False  
\SERVERNAME\HomeDirectory\dstiff\My Documents\WindowsPowerShell\Microsoft.PowerShellISE\_profile.ps1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CurrentUserCurrentHost&nbsp;&nbsp; True
```
  
  
I pass the filename (UNC path) of the potentially locked file to the script:  
  
\SERVERNAME\Path\To\Potentially\Locked\File\filename.exe  
  
Thanks!  
Dave

---

<div class="post-metadata">

### Author: ![nevar](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/n/c4cdca/32.png) [@nevar](https://www.finalbuilder.com/forums/u/nevar)
#### Post date: [January 22, 2014, 11:10am UTC](https://www.finalbuilder.com/forums/t/execute-powershell-script-path-being-dropped-from-script-name/2240/10 "2014-01-22T11:10:02Z")

</div>

Hi Dave,   
  
 I was also wondering if you could send your FinalBuilder project into support? Mainly to see what else the script is doing and what the options are on the script action itself.
