Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using below code in windows powershell to search for a string and give filename as output if string is found.

$a=Get-ChildItem -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "err"}
Write-host " Files with error code ERROR : $a
but i want to search files in a shared location which is given below which is protected by username and password which can be supplied

shared location : \\d1dal723\prdload
username : abc\xxyyzz
password : asdfghj@123
Please help me to search and display file names in that shared path .

Thanks in Advance.
Posted

UNC paths seem to work just fine for me. What have you tried and what error messages do you get?

Anyway, Get-ChildItem is gonna need the path to begin with. Using the full local path could perhaps be an option. Like... "\\d1da1723\c$\This Directory\Stuff\prdload"

Or you could mount the share with "net use" before searching through the files.
"net use /?" for help on that.

PowerShell
$a=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath | select-string -pattern "err"}
Write-host "Files with error code ERROR : $a"
 
Share this answer
 
v2
Hi
After trying your code
SQL
a=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath | select-string -pattern "err"}
Write-host "Files with error code ERROR :

I got the below error:

e term 'a=Get-ChildItem' is not recognized as the name of a cmdlet, function, script f
ile, or operable program. Check the spelling of the name, or if a path was included, ver
ify that the path is correct and try again.
At line:1 char:16
+ a=Get-ChildItem <<<<  "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {g
c $_.pspath | select-string -pattern "err"}
    + CategoryInfo          : ObjectNotFound: (a=Get-ChildItem:String) [], CommandNotFo 
   undException
    + FullyQualifiedErrorId : CommandNotFoundException


:(
 
Share this answer
 
Comments
notjustme 16-Feb-14 0:47am    
It was actually your code, I just added the path you mentioned. However, the $ in $a got cut out when I copied your code.
Member 10597584 20-Feb-14 8:38am    
Hi,

Now i used the below code but got an error.Although i have mapped my network drives to Z and Y i am still getting error.PFB the code i used.

<blockquote class="FQ"><div class="FQA">Quote:</div>$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("Z:", "\\d1dal723\prdload", $false, "apl\smallak", "Smile@05")

$a=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "err"}
Write-host " Files with error code ERROR : $a"-foreground "magenta"-backgroundcolor "black"

$b=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "ora[0-9]"}
Write-host " Files with error code ORA : $b"-foreground "magenta"-backgroundcolor "black"

$c=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "odbc[0-9]"}
Write-host " Files with error code ODBC : $c"-foreground "magenta"-backgroundcolor "black"

$d=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "TNS"}
Write-host " Files with error code TNS : $d"-foreground "magenta"-backgroundcolor "black"

$e=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "inaccessible"}
Write-host " Files with error code INACCESSIBLE : $e"-foreground "magenta"-backgroundcolor "black"

$e=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "Holos not logged "}
Write-host " Files with error code Holos not logged : $e"-foreground "magenta"-backgroundcolor "black"

$e=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "\?"}
Write-host " Files with error code object no longer exists : $e"-foreground "magenta"-backgroundcolor "black"
</blockquote>
Member 10597584 20-Feb-14 8:39am    
Hi,

Now i used the below code but got an error.Although i have mapped my network drives to Z and Y i am still getting error.PFB the code i used.

$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("Z:", "\\d1dal723\prdload", $false, "apl\smallak", "Smile@05")

$a=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "err"}
Write-host " Files with error code ERROR : $a"-foreground "magenta"-backgroundcolor "black"

$b=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "ora[0-9]"}
Write-host " Files with error code ORA : $b"-foreground "magenta"-backgroundcolor "black"

$c=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "odbc[0-9]"}
Write-host " Files with error code ODBC : $c"-foreground "magenta"-backgroundcolor "black"

$d=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "TNS"}
Write-host " Files with error code TNS : $d"-foreground "magenta"-backgroundcolor "black"

$e=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "inaccessible"}
Write-host " Files with error code INACCESSIBLE : $e"-foreground "magenta"-backgroundcolor "black"

$e=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "Holos not logged "}
Write-host " Files with error code Holos not logged : $e"-foreground "magenta"-backgroundcolor "black"

$e=Get-ChildItem "\\d1dal723\prdload" -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "\?"}
Write-host " Files with error code object no longer exists : $e"-foreground "magenta"-backgroundcolor "black"


Please help
notjustme 24-Feb-14 21:51pm    
You're gonna have to adjust your path to your mapping then (like $a=Get-ChildItem Z: instead of what you have now). What is the error you're getting?

On a sidenote, if that's your real user/pass you migth wanna edit that out before pasting your code here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900