powershell - Powershell脚本保存在UTC时间
问题描述
我已经实现了用于将数据从共享点提取到 CSV 文件的 powershell 脚本。目前我的文件正在按照我的时区保存。但我想用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 有一个.ToUniversalTime()
方法。在不更改其他所有内容的情况下更改以下内容将是最简单的。
$ExportName = (Get-Date).ToUniversalTime().ToString("yyyyMMdd")
$ExportName1 = (Get-Date).ToUniversalTime().ToString("yyyyMMdd")
推荐阅读
- git - 在 Github 中创建分支文件夹
- java - 在 Quarkus 原生构建时从 SSM 加载值
- clojurescript - 在试剂组分之间传递数据
- r - 比较组间的年费率
- python - numpy.core._exceptions.MemoryError:无法为形状为 (138494, 10000) 且数据类型为 float64 的数组分配 10.3 GiB
- r - 使用 htmltab 从 html 获取表格
- python - 在 python 中输入提示因输入 import Any 而感到困惑
- node.js - 有什么方法可以更快地插入?(Mongo DB 集合更新)
- ios - 集合视图单元格在某些视图中显示错误的背景颜色
- typescript - VueJs 3 TDD 一个依赖于外部库组件的组件