【问题标题】:get-spweb how can i get today created itemsget-spweb 如何获取今天创建的项目
【发布时间】:2014-07-10 07:59:08
【问题描述】:

我正在使用下一个 Powershell 脚本从 Sharepoint 列表中获取项目并将其导出 我如何编辑此脚本以仅获取今天创建的数据或今天输入的数据 这是代码

$MyWeb = Get-SPWeb "http://ilike-eg.suz.itcgr.net/SM"
$MyList = $MyWeb.Lists["SCGC"] 
$exportlist = @()

$Mylist.Items |  ForEach-Object {
$obj =   New-Object PSObject -property @{ 
        "A"="   "+$_["AACCOUNT_ID"]
        "B"="   "+$_["BTRANSACTION_ID"]
        "C"="          "+$_["CDATE"] 
        "D"="      "+$_["DCUSTOMER_ID"]
        "E"="     "+$_["ECUSTOMER_NAME"]
        "F"=" "+$_["FAMOUNT"]
        "G"=" "+$_["GCLASS"] 
}

#Remove unnecessary sort
$exportlist += $obj   
$DateStamp = get-date -uformat "%Y-%m-%d@%H-%M-%S"
$NameOnly = "CDP" 

#Exporting with sorted properties
$exportlist |
Select-Object A,B,C,D,E,F,G |
Export-Csv -Delimiter "`t"-path "$NameOnly.txt"
}

#Removed duplicate get-content line
$a, ${d:CDP.txt} = Get-Content .\CDP.txt
$a, ${d:CDP.txt} = Get-Content .\CDP.txt

(Get-Content D:\CDP.txt) |
Foreach-Object {$_ -replace $([char]34) -replace "`t" -replace '/', '-'} |
Set-Content D:\CDP.txt

谢谢

【问题讨论】:

    标签: powershell sharepoint scripting


    【解决方案1】:

    您在 SPListItems 中的管道位置,插入查询以获取今天创建的项目

    改变这个:

    $Mylist.Items |
    

    到这里:

    $Mylist.Items | where {$_['Created'] -eq Get-Date -format d}
    

    【讨论】:

    • 我可以用一些充当(包含)的东西替换(-q)吗,因为项目正在创建并记录在 -u 日期格式 mm-dd-yyyy hh:mm:ss 和 Get-Date 是仅获得 mm-dd-yyyy 谢谢
    • 是的 powershell where command 有一个 -contains 操作,但您不想将它用于日期。因此,假设您想提供给定日期以从中提取值: $startDate = '05-28-2014 00:00:00' $endDate = '05-28-2014 23:59:59' $MyList.Items |其中 {($_['Created'] -ge $startDate) -and ($_['Created'] -le $endDate)} 其中 -ge 大于或等于和 -le 小于或等于
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    • 2011-06-29
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 2016-05-11
    • 1970-01-01
    相关资源
    最近更新 更多