Skip to main content
deleted 7 characters in body
Source Link
raredesign
  • 89
  • 3
  • 14

Rather than create a static HashTable that is composed of the data from my list, I am looking to make it dynamic, but ran into some difficulty in constructing it.

For example:

Given that $items is set to Get-PnPListItem

foreach($item in $items){
    $HashTable += New-Object PSObject -Property @{
        'Title' = $item.FieldValues.Title;
        'Date' = $item.FieldValues.Date;
        'Column 3' = $item.FieldValues.Column_x0020_3;
        'Column 4' = $item.FieldValues.Column_x0020_4;
        'Assigned To' = $item.FieldValues.Assigned_x0020_To.LookupValue;
    }
}

That example above works, but again, is explicit. My thought was to construct the HashTable from the All Items view.

$view = Get-PnPView -List $listName -Identity "All Items";
$columns = $view.ViewFields;

Since a foreach() cannot be run inside of the HashTable, I have tried piping Add and Add-Member from a foreach of $column in $columns, but without resolve.

Within the loop, I would also need to check each GetType() to determine if I need to append a .Date, .LookupValue, etc.

While I can get by with what I have and use explicit scripts, it should be self-evident how valuable a dynamically constructed script would be for all.

Any ideas?

Rather than create a static HashTable that is composed of the data from my list, I am looking to make it dynamic, but ran into some difficulty in constructing it.

For example:

Given that $items is set to Get-PnPListItem

foreach($item in $items){
    $HashTable += New-Object PSObject -Property @{
        'Title' = $item.FieldValues.Title;
        'Date' = $item.FieldValues.Date;
        'Column 3' = $item.FieldValues.Column_x0020_3;
        'Column 4' = $item.FieldValues.Column_x0020_4;
        'Assigned To' = $item.FieldValues.Assigned_x0020_To.LookupValue;
    }
}

That example above works, but again, is explicit. My thought was to construct the HashTable from the All Items view.

$view = Get-PnPView -List $listName -Identity "All Items";
$columns = $view.ViewFields;

Since a foreach() cannot be run inside of the HashTable, I have tried piping Add and Add-Member from a foreach of $column in $columns, but without resolve.

Within the loop, I would also need to check each GetType() to determine if I need to append a .Date, .LookupValue, etc.

While I can get by with what I have and use explicit scripts, it should be self-evident how valuable a dynamically constructed script would be for all.

Any ideas?

Rather than create a static HashTable that is composed of the data from my list, I am looking to make it dynamic, but ran into some difficulty in constructing it.

For example:

Given that $items is set to Get-PnPListItem

foreach($item in $items){
    $HashTable += New-Object PSObject -Property @{
        'Title' = $item.FieldValues.Title;
        'Date' = $item.FieldValues.Date;
        'Column 3' = $item.FieldValues.Column_x0020_3;
        'Column 4' = $item.FieldValues.Column_x0020_4;
        'Assigned To' = $item.FieldValues.Assigned_x0020_To.LookupValue;
    }
}

That example above works, but again, is explicit. My thought was to construct the HashTable from the All Items view.

$view = Get-PnPView -List $listName -Identity "All Items";
$columns = $view.ViewFields;

Since a foreach() cannot be run inside of the HashTable, I have tried piping Add and Add-Member from a foreach of $column in $columns, but without resolve.

Within the loop, I would also need to check each GetType() to determine if I need to append a .LookupValue, etc.

While I can get by with what I have and use explicit scripts, it should be self-evident how valuable a dynamically constructed script would be for all.

Any ideas?

Source Link
raredesign
  • 89
  • 3
  • 14

Dynamic HashTable from a list in PnP PowerShell

Rather than create a static HashTable that is composed of the data from my list, I am looking to make it dynamic, but ran into some difficulty in constructing it.

For example:

Given that $items is set to Get-PnPListItem

foreach($item in $items){
    $HashTable += New-Object PSObject -Property @{
        'Title' = $item.FieldValues.Title;
        'Date' = $item.FieldValues.Date;
        'Column 3' = $item.FieldValues.Column_x0020_3;
        'Column 4' = $item.FieldValues.Column_x0020_4;
        'Assigned To' = $item.FieldValues.Assigned_x0020_To.LookupValue;
    }
}

That example above works, but again, is explicit. My thought was to construct the HashTable from the All Items view.

$view = Get-PnPView -List $listName -Identity "All Items";
$columns = $view.ViewFields;

Since a foreach() cannot be run inside of the HashTable, I have tried piping Add and Add-Member from a foreach of $column in $columns, but without resolve.

Within the loop, I would also need to check each GetType() to determine if I need to append a .Date, .LookupValue, etc.

While I can get by with what I have and use explicit scripts, it should be self-evident how valuable a dynamically constructed script would be for all.

Any ideas?