@@ -237,6 +237,18 @@ $Properties = @{
237237 @ { name = ' Owner' ; default = $true ; }
238238 @ { name = ' Path' ; }
239239 )
240+ File = @ (
241+ @ { name = ' FullName' ; default = $true ; key = $true }
242+ @ { name = ' Attributes' ; }
243+ @ { name = ' CreationTime' ; }
244+ @ { name = ' Depth' ; }
245+ @ { name = ' LastAccessTime' ; }
246+ @ { name = ' LastWriteTime' ; }
247+ @ { name = ' Name' ; default = $true ; }
248+ @ { name = ' BaseName' ; default = $true ; }
249+ @ { name = ' Path' ; }
250+ @ { name = ' B64String' ; default = $true ; }
251+ )
240252}
241253
242254
@@ -249,6 +261,147 @@ foreach ($key in $Properties.Keys) {
249261 }
250262}
251263
264+ function Idm-FilesRead {
265+ param (
266+ # Operations
267+ [switch ] $GetMeta ,
268+ # Parameters
269+ [string ] $SystemParams ,
270+ [string ] $FunctionParams
271+ )
272+
273+ Log info " -GetMeta=$GetMeta -SystemParams='$SystemParams ' -FunctionParams='$FunctionParams '"
274+
275+ if ($GetMeta ) {
276+ #
277+ # Get meta data
278+ #
279+
280+ $system_params = ConvertSystemParams $SystemParams
281+
282+ $all_properties = $Global :Properties.File
283+
284+ @ (
285+ @ {
286+ name = ' properties'
287+ type = ' grid'
288+ label = ' Properties'
289+ table = @ {
290+ rows = @ ( $all_properties | ForEach-Object {
291+ @ {
292+ name = $_.name
293+ usage_hint = @ ( @ (
294+ foreach ($key in $_.Keys ) {
295+ if ($key -eq ' idm' ) {
296+ $key.Toupper ()
297+ }
298+ elseif ($key -ne ' name' ) {
299+ $key.Substring (0 , 1 ).Toupper() + $key.Substring (1 )
300+ }
301+ }
302+ ) | Sort-Object ) -join ' | '
303+ }
304+ })
305+ settings_grid = @ {
306+ selection = ' multiple'
307+ key_column = ' name'
308+ checkbox = $true
309+ filter = $true
310+ columns = @ (
311+ @ {
312+ name = ' name'
313+ display_name = ' Name'
314+ }
315+ @ {
316+ name = ' usage_hint'
317+ display_name = ' Usage hint'
318+ }
319+ )
320+ }
321+ }
322+ value = ($all_properties | Where-Object { $_.default }).name
323+ }
324+ )
325+
326+ }
327+ else {
328+ #
329+ # Execute function
330+ #
331+
332+ $system_params = ConvertSystemParams $SystemParams
333+ $function_params = ConvertFrom-Json2 $FunctionParams
334+
335+ if ($function_params.properties.length -eq 0 ) {
336+ # No properties selected: select defaults
337+
338+ $all_properties = $Global :Properties.File
339+
340+ $function_params.properties = ($all_properties | Where-Object { $_.default }).name
341+ }
342+
343+ # Assure key is the first column
344+ $key = ($Global :Properties.File | Where-Object { $_.key }).name
345+ $function_params.properties = @ ($key ) + @ ($function_params.properties | Where-Object { $_ -ne $key })
346+
347+ foreach ($path_spec in $system_params.paths_spec ) {
348+ Log debug " Path: $ ( $path_spec.path ) "
349+ $path_with_backslash = AppendBackslashToPath $path_spec.path
350+
351+ $gci_args = @ {
352+ Directory = $false
353+ Force = $true
354+ LiteralPath = $path_spec.path
355+ Recurse = $system_params.recursive
356+ Depth = 0
357+ ErrorAction = ' SilentlyContinue'
358+ }
359+
360+ if ($system_params.recursive ) {
361+ $gci_args.Depth = $system_params.recursion_depth
362+ }
363+
364+ if ($path_spec.depth -ge 0 ) {
365+ $gci_args.Depth = $path_spec.depth
366+ }
367+
368+ LogIO info ' Get-ChildItem' -In @gci_args - Exclude $system_params.excludes - Properties $function_params.properties
369+
370+ try {
371+ # This is to correct error messages, e.g.:
372+ # "Cannot find drive. A drive with the name 'x' does not exist" instead of
373+ # "A parameter cannot be found that matches parameter name 'Directory'".
374+ Get-ChildItem - Force - LiteralPath $path_spec.path > $null
375+
376+ # For directories, Get-ChildItem returns [System.IO.DirectoryInfo]
377+ Get-ChildItem @gci_args | ForEach-Object {
378+ foreach ($exclude in $system_params.excludes ) {
379+ if ($_.FullName -ilike $exclude ) { return }
380+ }
381+
382+ $_
383+ } | ForEach-Object {
384+ $ht = @ {
385+ Attributes = ($_.Attributes -split ' ,' | ForEach-Object { $h = $_.Trim (); if ($h.Length -gt 0 ) { $h.Substring (0 , 1 ).Toupper() } }) -join ' '
386+ Depth = $_.FullName.Substring ($path_with_backslash.length ).Split(' \' ).Count - 1
387+ Path = $_.FullName.Substring (0 , $_.FullName.length - $_.Name.Length )
388+ B64String = [System.Convert ]::ToBase64String([System.IO.File ]::ReadAllBytes($_.FullName ))
389+ }
390+
391+ $_ | Add-Member - PassThru - Force - NotePropertyMembers $ht
392+ } | Select-Object $function_params.properties | Sort-Object { $_.FullName }
393+ }
394+ catch {
395+ Log error " Failed: $_ "
396+ Write-Error $_
397+ }
398+ }
399+
400+ }
401+
402+ Log info " Done"
403+ }
404+
252405
253406function Idm-FolderCreate {
254407 param (
0 commit comments