【问题标题】:Powershell script saving on UTC timePowershell 脚本保存在 UTC 时间
【发布时间】:2019-06-14 10:46:27
【问题描述】:

我已经实现了 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
}

【问题讨论】:

    标签: powershell csv sharepoint time


    【解决方案1】:

    很简单,因为 PowerShell 有一个 .ToUniversalTime() 方法。在不更改其他所有内容的情况下更改以下内容将是最简单的。

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

    【讨论】:

    猜你喜欢
    • 2014-06-11
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-24
    • 1970-01-01
    相关资源
    最近更新 更多