Execute PowerShell Script : path being dropped from script name

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

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.

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 (
    [Parameter(Mandatory=$True,Position=1)]
    [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"
    
Clear-Host
    
# 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) {

    $fileID = $item.ID
    $userID = $item."Accessed By"
    $locks = $item."#Locks"
    $openFile = $item."Open File (Path\executable)"
    
    Write-Host "$openFile : $locks - $userID"

    # get the path of the local installer on SERVERNAME
    $localFile = $exeName
    $localFile = $localInstaller.Replace($remoteRoot,$localRoot)
    
    if ($openFile -eq $localFile) {
        Write-Host "Locked File Detected!"
        # email details
        #$to = "$userID@domain.com"
        $dateTime = Get-Date -Format g
        $subject = "Warning: locked file on $serverName - $dateTime"
        $body = "USER: $userID
"
        $body += "FILE: $exeName
"
        $body += "ID: $fileID
"
        $body += "LOCKS: $locks
"
        $body += "WARNING: This file is currently locked and may cause the build to fail.
"
        $body += "The lock will be broken at the end of the build to prevent failure.
"
        $body += "You have 60-90 minutes before this happens. Please ensure the file is unlocked to prevent any data loss.
"
        $body += "

"
        $body += "Automated email sent from computer: $env:COMPUTERNAME"   
        
        # send the email
        Send-MailMessage -SmtpServer $smtpServer -To $to -Cc $cc -From $from -Subject $subject -Body $body -BodyAsHtml -Priority high
    }
    
}

Thanks!

Dave

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?

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

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

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.

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.

Hi Jason,

thanks for looking into this!

My script is as above. My PowerShell profile paths are:

Path                                                                                                          Name                   Exists
----                                                                                                          ----                   ------
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1                                                        AllUsersAllHosts        False
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1                                AllUsersCurrentHost     False
\SERVERNAME\HomeDirectory\dstiff\My Documents\WindowsPowerShell\profile.ps1                                  CurrentUserAllHosts     False
\SERVERNAME\HomeDirectory\dstiff\My Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1          CurrentUserCurrentHost   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

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.