DanielJ
DanielJ

Reputation: 109

Trying to add files to a sharepoint library via Add-PnPFile but whenever a blank value is sent to a datetime column, no other values are sent

I've got a script that adds a file then reads an excel sheet and then populate a sharepoint document library with that data. The command looks something like

Add-PnPFile -Path $Path -Folder $LibraryName -Values @{"Name" = $Values[0]; "Classification" = $Values[1]; "DocumentID" = $Values[2]; "EffectiveDate" = $Values[3]; "DatePublished" = $Values[4]; "EndDate" = $Values[5]; "RNumber" = $Values[6]}

Everything works fine until one of the date columns needs to be a blank and it's value in the array is blank. Whenever that happens i notice that even though the document gets populated, all the columns are blank. What values can be passed instead of an empty string for the datetimes for this to work?

Edit: do want to add that whenever i replace the blank with a dummy date, it works just fine

Upvotes: 1

Views: 26

Answers (1)

DanielJ
DanielJ

Reputation: 109

Ended up creating a hashtable and only passing in the Key/Value if they had data

# Initialize an empty hashtable
        $HashTable = @{}

        # Split into key-value pairs safely
        $Values -split ";" | ForEach-Object {
        if ($_ -match "=") {  # Ensure the pair contains '='
            $Key, $Value = $_ -split "=", 2  # Split into two parts only
            $Key = $Key.Trim()
            $Value = $Value.Trim()

            # Ensure both key and value are valid before adding to hashtable
            if ($Key -ne "" -and $null -ne $Value) {
                $HashTable[$Key] = $Value
                }
            }
        }

        # Debug output
        $HashTable | Format-Table -AutoSize
    
            Add-PnPFile -Path $Path -Folder $LibraryName -Values $HashTable


Upvotes: 1

Related Questions