我可以使用Get-SPWeb和getget list传递Parameter

时间:2014-05-18 15:47:45

标签: powershell sharepoint

我正在使用下一个代码从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

#Combined replace statements to avoid multiple read/writes
(Get-Content D:\CDP.txt) |
Foreach-Object {$_ -replace $([char]34) -replace "`t" -replace '/', ''} |
Set-Content D:\CDP.txt  

1 个答案:

答案 0 :(得分:0)

是的,请替换您的代码:

$Mylist.Items | ForEach-Object {

与以下代码类似(您需要声明date1 - startDate和date2 - endDate):

$Mylist.Items | where {$_['Created'] -gt $date1 -and $_['Created'] -lt $date2} | ForEach-Object {