Powershell脚本节省了UTC时间

时间:2019-01-21 03:51:47

标签: powershell csv sharepoint time

我已经实现了Powershell脚本,用于将数据从共享点提取到CSV文件。目前,我的文件正在按我的时区保存。但是我想用UTC时间保存文件。意味着在脚本下我想将时间格式转换为UTC时间。任何人都可以更正我的脚本。我正在使用的脚本行下面。

 Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$web = get-spweb http://testsharepoint/sharepoint/
$caseLib = $web.lists | where {$_.title -eq "Library"}

$query=new-object Microsoft.SharePoint.SPQuery 

$query.ViewFields = "<FieldRef Name='LinkFilename'/><FieldRef Name='DocumentSetDescription'/>"

$query.RowLimit=5000

$ListName1 = "Test_"
$ExportFolder1 = “C:\export\”
$ExportName1 = Get-Date -f “yyyyMMdd”
$ExportPath1 = $ExportFolder1 + $ListName1 + $ExportName1 + “.csv”

$ListName = "Data_"
$ExportFolder = “\\servername\Data\”
$ExportName = Get-Date -f “yyyyMMdd”
$ExportPath = $ExportFolder + $ListName + $ExportName + “.csv”

do
{
$caseLibItems=$caseLib.GetItems($query)
$query.ListItemCollectionPosition=$caseLibItems.ListItemCollectionPosition
$listItemsTotal = $caseLibItems.Count
$x = 0
for($x=0;$x -lt $listItemsTotal; $x++)
{
$Description = $caseLibItems[$x]["DocumentSetDescription"]
$str = ""
if('$Description; -ne $null)
$str = $caseLibItems[$x]["LinkFilename"].ToString() + '}' + $Description 
  }
else
 {
$str = $caseLibItems[$x]["LinkFilename"].ToString()
}
Write-Output $str| Out-File $ExportPath1 -Append
}

1 个答案:

答案 0 :(得分:2)

由于PowerShell具有.ToUniversalTime()方法,因此非常容易。不更改其他所有内容,最简单的更改就是以下内容。

$ExportName = (Get-Date).ToUniversalTime().ToString("yyyyMMdd")
$ExportName1 = (Get-Date).ToUniversalTime().ToString("yyyyMMdd")