Issue using Get-Child-Item


have function scan (grep) files in folder extension.  for reason, get-child-item returns empty / 0 files on folder though can @ folder , see files of specified extension (*.config).  suspect either doing wrong or permissions somehow getting in way.  how use get-childitem in context?

function scan-files { param( [parameter(mandatory=$true)] [string]$folder, [parameter(mandatory=$true)] [string]$filepattern, [parameter(mandatory=$false)] [bool]$recurse = $false ) write-host "folder = $folder" write-host "filepattern = $filepattern" $files = get-childitem -include $filepattern -path $folder

#always empty reason if ($files) { write-host "file count = $($files.length)" }

.

.

.

#invoke our function

$folder = "c:\program files\microsoft sql server\msrs12.mssqlserver\reporting services\reportserver\"
$filepattern = "*.config"         

#scan-files -folder $folder -filepattern $filepattern -recurse:$true
scan-files -folder $folder -filepattern $filepattern



change this:

$folder = "c:\program files\microsoft sql server\msrs12.mssqlserver\reporting services\reportserver\"

to this:

$folder='c:\program files\microsoft sql server\msrs12.mssqlserver\reporting services\reportserver\*'

you have run elevated see folder set.


\_(ツ)_/







Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS