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
Post a Comment