powershell ii command related question

this is a question related to my previous question: using ii to open folder in explorer

ii c:\p*  - works

ii \\servername\l* - does not work - does not give any errors as well
ii \\servername\logs - works

I would appreciate if you could help me with opening explorer using folder name pattern.


Thanks
DevSupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
What is the context of the previous question?.
0
AlanConsultantCommented:
Hi,

I just tested using \\Server\Share\Path\

ii \\ServerName\C$\Temp\*lan*

Open in new window


Opens up:

\\ServerName\C$\Temp\AlanA\

and

\\ServerName\C$\Temp\AlanB\


Are you running with sufficient permissions still?

Alan.
0
oBdACommented:
In "\\servername\l*", "l*" is not a folder, but a share.
Invoke-Item can only open a valid file system path, not a UNC with a partial share name.
It does not enumerate shares, which is what you're trying to do with "\\servername\l*".
You can save this as Invoke-Share.ps1 and use it instead:
<#
.SYNOPSIS
Opens a share on a remote system in Windows Explorer.
.DESCRIPTION
The function Invoke-Share opens a share on a remote system in Windows Explorer.
Wildcard characters are accepted as part of the share or using the -Filter argument.
.PARAMETER Path
The UNC to connect to; wildcard characters are accepted.
Note: any directory components after the share will be IGNORED.
.PARAMETER Filter
Specifies a filter. The value of this parameter qualifies the Path parameter.
.PARAMETER WhatIf
Only enumerates the shares the function would normally open.
.PARAMETER Confirm
Asks for confirmation before opening a share.
.INPUTS
System.String[]
.OUTPUTS
This function does not generate pipeline output.
.EXAMPLE
Invoke-Share -Path \\Server\*$
.EXAMPLE
Invoke-Share -Path \\Server -Filter *$
#>
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Low')]
Param(
	[Parameter(Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
	[Alias('ComputerName')]
	[string[]]$Path,
	[string]$Filter
)
	Begin {
		$CommandFilter = If ($Filter) {{$_ -like $Filter}} Else {{$true}}
	}
	Process {
		$Path | ForEach-Object {
			$ComputerName, $Share = If ($_.Contains('\')) {$_.Split('\', [StringSplitOptions]::RemoveEmptyEntries)[0..1]} Else {$_, $null}
			$PathFilter = If ($Share) {{$_ -like $Share}} Else {{$true}}
			$StdErr = $(
				& "${ENV:SystemRoot}\system32\net.exe" view /all "\\$($ComputerName)" |
				Where-Object {$_ -match '(?<Name>\A.*?)\s+Disk\b'} |
				ForEach-Object {$Matches['Name']} |
				Where-Object $PathFilter |
				Where-Object $CommandFilter |
				ForEach-Object {
					$UNC = "\\$($ComputerName)\$($_)"
					If ($PSCmdlet.ShouldProcess($UNC, 'Open Share')) {Invoke-Item -Path $UNC -Confirm:$false -WhatIf:$false}
				}
				
			) 2>&1
			If ($StdErr) {Write-Error "$($ComputerName): $(($StdErr -join ' ').Replace("`r`n", ' '))"}
		}
	}
	End {
	}

Open in new window

3

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DevSupportAuthor Commented:
@oBdA: Thank You so much oBdA! Works for me!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.