hi , i m developing a tool to make a search on a network drive the results are diplayed on a out-gridview window but directory is not mentionned only the filename is displayed . i suppose the get childItem command doesn’t
$fileName –>name of the file requested
$Files = (Get-ChildItem -Recurse -Force $filePath -ErrorAction SilentlyContinue | Where-Object { ($.PSIsContainer -eq $false) -and ( $.FullName -like “$fileName”) } #test if $files contains result
if ($Files.count -eq 0) {
write-host " no result containing expression:" $fileName
} else { #here we select what information we want to be displayed in out-gridview and then Passthru
$Files | Select-Object Name,Directory | Out-GridView -Title “choisissez le fichier à ouvrir” -PassThru | ii
}
Nothing happens even if i select a file in the out-gridview window . i suppose there is a mismatch object type between
$Files | Select-Object Name,Directory and Out-GridView -Passthru ??
help please !!
the results a good until the window of out-gridview but the invoke item doesn’t open the file selected …
Include FullName in your Select-Object property list, if you want to include the directory.
However, Invoke-Item can’t “invoke” a file with just the file name. Including FullName may help, but if it doesn’t, then you’re going to need to NOT use Select-Object, but instead let the entire file object appear in the GridView, so that the entire file object can be passed through.
Actually it works when i let the entire object pass through –>$Files | Out-GridView -Title “choose the file to open” -PassThru | ii
But in the Out-GridView window we can’t see the location of the directory even with FullName in the Select-Object property list
Anyway I ll let it this way if there is no choice …
your solution is 50/100 effective as it works for all the files in a certain directory and doesn’t work at all for certain directory… and powershell doesn’t generate any error message …
it seems that out-GridView doesn’t like long path ex:Z:\level1\Telecommunication\Service client\Téléphonie mobile\Applications\file.doc
and for this path : Z:\level1\Application Métier\SIGNORDO (signature ordonnances) - AP0177\otherfile.doc
it works like a charm ???
your solution doesn’t generate any error powershell accepts it but the choosen file doesn’t open ,it’s like invoke item doesn’t receive enough information …
Strange things, it works for me if I pipe the results of:
(dir -File)[0]
into it. Since Invoke-Item performs the default action on the specified item, I assume that you have the application to launch the file installed on the PC that you run this. I don’t think it’s something about the PowerShell version either, but just to be sure, which version of PowerShell are you using ($PSVersionTable will tell you)?
hi dirk,
the problem doesn’t come from wich software ii uses to open the requested file,
when i choose a location for a pdf file it works but il i choose the same file in a anoter directory on the same network drive nothings happens ???
i ve found out a solution to bypass my problem here is the code : #here we select or specifie the file name
[string]$myfile = ‘Linux-clients.pdf’ #the result is a collection of objects containing the expression ‘$myfile’ and many other things
$search = (Get-ChildItem -Recurse -File -Force -Path E:\ -ErrorAction SilentlyContinue | Where-Object { $_.FullName -like “$myfile” } )
$search | Select-Object PSpath,FullName | Out-GridView -Passthru | ii
#This is the only way you can send the path and fullname to invoke-item via a select-object command !
thank you dude for orienting me in the right direction !!