Hi,
There is no need to create a share, psfile translates "/vol/vol1/qtree1/database.mdb" as "C:\vol\vol1\qtree1\database.mdb". Here is an example in powershell:
# http://technet.microsoft.com/en-us/sysinternals/bb897552.aspx
# Note that this script relies on "psfile.exe" existing in the windows system directory
#'------------------------------------------------------------------------------
#'Initialization Section. Define Global Variables.
#'------------------------------------------------------------------------------
[String]$uncPath = "\\testns01\test1$\databases\admin\database.mdb"
[String]$scriptPath = Split-Path($MyInvocation.MyCommand.Path)
[String]$scriptSpec = $MyInvocation.MyCommand.Definition
[String]$scriptName = (Get-Item $scriptSpec).Name
[String]$systemPath = [Environment]::SystemDirectory
[String]$exeSpec = "$systemPath\cmd.exe"
[String]$exeName = "psfile.exe"
[Array]$elements = $uncPath -Split [regex]::Escape("\")
[String]$controller = $elements[2]
[String]$shareName = $elements[3]
[String]$fileName = $elements[$elements.Length -1]
#'------------------------------------------------------------------------------
#'construct the folder path between the share name and file name.
#'------------------------------------------------------------------------------
Write-Host "The Script ""$scriptName"" Started Processing."
Write-Host "Processing file ""$uncPath"""
[String]$folderPath = "/"
For($i=4; $i -lt ($elements.Count -1); $i++){
[String]$folderPath = $folderPath + $elements[$i] + "/"
}
#'------------------------------------------------------------------------------
#'Ensure psfile.exe exists in the scripts system directory.
#'------------------------------------------------------------------------------
If(-Not(Test-Path -Path "$systemPath\$exeName")){
Write-Host "The file ""$systemPath\$exeName"" does not exist"
Break;
}
#'------------------------------------------------------------------------------
#'Enumerate the mount point of the share and file
#'------------------------------------------------------------------------------
Import-Module DataOnTap
Connect-NaController -Name $controller | Out-Null
[String]$mountPoint = Get-NaCifsShare | Where-Object {$_.ShareName -eq $shareName} | Select-Object -ExpandProperty MountPoint
[String]$mountPath = "$mountPoint$folderPath$fileName"
$file = Get-NaLockStatus | Where-Object {$_.Mode -eq "Oplock-Excl" -And $_.Path -eq $mountPath}
[String]$filePath = $file.Path
[String]$owner = $file.Owner
Write-Host "Enumerated the mount point for CIFS share ""$shareName"" as ""$mountPoint"""
Write-Host "Enumerated CIFS Locked file as ""$filePath"" locked by ""$owner"""
#'------------------------------------------------------------------------------
#'Replace the foward slash with back slash characters to build the local file path.
#'------------------------------------------------------------------------------
[String]$fileSpec = "C:" + ($filePath -Replace ([regex]::Escape("/"),"\"))
[String]$command = "$exeName \\$controller ""$fileSpec"" -c"
Start-Process $exeSpec -ArgumentList " /c $command"
Write-Host "Executed Command: $command"
Write-Host "The Script ""$scriptName"" Completed Successfully."
Here is an example of the script output:
PS C:\Scripts\PowerShell\Projects\CloseLockedFile> .\CloseLockedFile.ps1
The Script "test.ps1" Started Processing.
Processing file "\\testns01\test1$\databases\admin\database.mdb"
Enumerated the mount point for CIFS share "test1$" as "/vol/vol1/qtree1"
Enumerated CIFS Locked file as "/vol/vol1/qtree1/Databases/Admin/database.mdb" locked by "administrator"
Executed Command: psfile.exe \\testns01 "C:\vol\vol1\qtree1\Databases\Admin\database.mdb" -c
The Script "CloseLockedFile.ps1" Completed Successfully.
PS C:\Scripts\PowerShell\Projects\CloseLockedFile>
Hope that helps
Cheers Matt
If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.