filmov
tv
Power Automate (MS Flow):Extract attachment from SharePoint list using
Показать описание
# Change to desired location
# This is the folder with the XML
$inputFolder = 'C:\Users\xyz\Folder''
# This is the folder where the attachments will be saved
$attachFolder = 'C:\Users\xyz\New folder'
#Count the number of files
$counter = 0
# Get all the XML files from the Input Folder
Get-ChildItem $inputFolder -Filter *.xml | `
Foreach-Object{
[ xml ] $fileContents = Get-Content -Path $_.FullName
$fileName = $_.Name
if (($base64) -and ($base64 -ne "") -and ($base64.Length -ne $null))
{
try
{
# get the bytes
$bytes = [Convert]::FromBase64String($base64)
$memStream = New-Object System.IO.MemoryStream (,$bytes)
$binaryReader = New-Object System.IO.BinaryReader $memStream
$header = New-Object Byte[] 16
$header = $binaryReader.ReadBytes($header.Length)
# Attachment Size
$attachSize = [int]$binaryReader.ReadUInt32()
# Attachment Name
$attachNameLength = [int]$binaryReader.ReadUInt32()*2
$attachNameBytes = $binaryReader.ReadBytes($attachNameLength)
$attachName = [System.Text.Encoding]::Unicode.GetString($attachNameBytes, 0, $attachNameLength - 2)
# Attachment
$attachmentFile = $binaryReader.ReadBytes($attachSize);
$attachPath = $attachFolder + '\' + $fileName.Replace(".xml", "") + ' - ' + $attachName
# Write off to the output folder
[IO.File]::WriteAllBytes($attachPath, $attachmentFile)
$counter ++
}
catch [Exception]
{
Write-Host "Failure on" $fileName "with base64 value length" $base64.Length
}
}
}
Write-Host $counter
# This is the folder with the XML
$inputFolder = 'C:\Users\xyz\Folder''
# This is the folder where the attachments will be saved
$attachFolder = 'C:\Users\xyz\New folder'
#Count the number of files
$counter = 0
# Get all the XML files from the Input Folder
Get-ChildItem $inputFolder -Filter *.xml | `
Foreach-Object{
[ xml ] $fileContents = Get-Content -Path $_.FullName
$fileName = $_.Name
if (($base64) -and ($base64 -ne "") -and ($base64.Length -ne $null))
{
try
{
# get the bytes
$bytes = [Convert]::FromBase64String($base64)
$memStream = New-Object System.IO.MemoryStream (,$bytes)
$binaryReader = New-Object System.IO.BinaryReader $memStream
$header = New-Object Byte[] 16
$header = $binaryReader.ReadBytes($header.Length)
# Attachment Size
$attachSize = [int]$binaryReader.ReadUInt32()
# Attachment Name
$attachNameLength = [int]$binaryReader.ReadUInt32()*2
$attachNameBytes = $binaryReader.ReadBytes($attachNameLength)
$attachName = [System.Text.Encoding]::Unicode.GetString($attachNameBytes, 0, $attachNameLength - 2)
# Attachment
$attachmentFile = $binaryReader.ReadBytes($attachSize);
$attachPath = $attachFolder + '\' + $fileName.Replace(".xml", "") + ' - ' + $attachName
# Write off to the output folder
[IO.File]::WriteAllBytes($attachPath, $attachmentFile)
$counter ++
}
catch [Exception]
{
Write-Host "Failure on" $fileName "with base64 value length" $base64.Length
}
}
}
Write-Host $counter
Комментарии