Azure自动化PowerShell从SharePoint读取CSV文件

3qpi33ja  于 9个月前  发布在  Shell
关注(0)|答案(1)|浏览(140)

添加我能够使用Azure自动化从SharePoint读取文件的时刻。对我来说,问题是当我执行导入时,我丢失了CSV上的所有属性值。因此,以下文件具有属性date,time,id,name当我查询$GetCSV时,我获得所有记录当我查询$GetCSV. id时,它不显示任何数据。

#Obtain AccessToken for Microsoft Graph via the managed identity
$headers = Get-AuthToken
$graphurl = "https://graph.microsoft.com/beta"

#Sharepoint parameters
$SharePoint = "%Company%.sharepoint.com"
$SharePointSite = "%Site%"
$ItemPathFile = "file.csv"
$ItemPath = "Apps/Entra%20Automation/$ItemPathFile"

#Get the site from Graph API
$SharePointsitequery = "$graphurl/sites/$($SharePoint):/sites/$($SharePointSite)"
$SiteRequestCall = try{Invoke-RestMethod -Method GET -headers $headers -Uri $SharePointsitequery}catch{Write-output "Error SharePoint SiteId $($_.Exception.Response.StatusCode) $($_.Exception.Response.StatusDescription)"}
$SiteId = $SiteRequestCall.id.split(",")[1]

#Get the file to the documents library
$Querygetfile = "$graphurl/sites/$siteId/drive/items/root:/$($ItemPath):/content"
$GetCSV = try{Invoke-RestMethod -Method GET -Headers $headers -Uri $Querygetfile }catch{Write-output "Error SharePoint Get $($_.Exception.Response.StatusCode) $($_.Exception.Response.StatusDescription)"}

字符串

vxf3dgd4

vxf3dgd41#

当我查询$GetCSV时,我得到了所有记录,当我查询$GetCSV.id时,它没有显示任何数据。
您可以使用下面修改的脚本,通过Azure自动化从**CSV**文件中获取特定记录。
在我的共享点中,我的示例CSV文件看起来像这样:
x1c 0d1x的数据

脚本:

$headers = Get-AuthToken
$graphurl = "https://graph.microsoft.com/beta"

#Sharepoint parameters
$SharePoint = "%Company%.sharepoint.com"
$SharePointSite = "%Site%"
$ItemPathFile = "file.csv"
$ItemPath = "Apps/Entra%20Automation/$ItemPathFile"

#Get the site from Graph API
$SharePointsitequery = "$graphurl/sites/$($SharePoint):/sites/$($SharePointSite)"
$SiteRequestCall = try{Invoke-RestMethod -Method GET -headers $headers -Uri $SharePointsitequery}catch{Write-output "Error SharePoint SiteId $($_.Exception.Response.StatusCode) $($_.Exception.Response.StatusDescription)"}
$SiteId = $SiteRequestCall.id.split(",")[1]

#Get the file to the documents library
$Querygetfile = "$graphurl/sites/$siteId/drive/items/root:/$($ItemPath):/content"
$GetCSV = try{Invoke-RestMethod -Method GET -Headers $headers -Uri $Querygetfile }catch{Write-output "Error SharePoint Get $($_.Exception.Response.StatusCode) $($_.Exception.Response.StatusDescription)"}

$CSV = $GetCSV | ConvertFrom-Csv -Delimiter ","

# Access the properties of the CSV file
$Numeric = $CSV.Numeric
$Numeric2 = $CSV.'Numeric-2'
$NumericSuffix = $CSV.'Numeric-Suffix'

$Numeric

字符串
上面的代码在我的Azure自动化环境中执行并读取第一列。

输出:


相关问题