[英]Check a PowerShell script line against a txt file containing computer names
[英]Run PowerShell script against each site from txt file
在线寻求针对 sharepoint 运行 powershell 脚本的帮助。 基本上我目前拥有的是:
#Parameters
$SiteURL = "https://mysite.sharepoint.com/sites/site1"
$ListName= "Documents"
$ReportOutput = "C:\Temp\export.csv"
$Pagesize = 500
#Connect to SharePoint Online site
Connect-PnPOnline $SiteURL -UseWebLogin
#Delete the Output report file if exists
If (Test-Path $ReportOutput) { Remove-Item $ReportOutput}
#Array to store results
$Results = @()
#Get all Items from the document library with given fields
$ListItems = Get-PnPListItem -List $ListName -Fields "FileLeafRef", "SMTotalFileStreamSize", "FileDirRef","Author","Created","File_x0020_Type"
#Iterate through each item
Foreach ($Item in $ListItems)
{
#Filter Files only
If (($Item.FileSystemObjectType) -eq "File")
{
$Results += New-Object PSObject -Property ([ordered]@{
FileName = $Item["FileLeafRef"]
FileType = $Item["File_x0020_Type"]
RootFolder = $Item["FileDirRef"]
RelativeURL = $Item["FileRef"]
FileSize = ($Item["SMTotalFileStreamSize"])
CreatedBy = $Item["Author"].Email
CreatedOn = $Item["Created"]
Modified = $Item["Modified"]
ModifiedByEmail = $Item["Editor"].Email
})
}
}
#Export the results
$Results
$Results | Export-Csv -Path $ReportOutput -NoTypeInformation
但是,我有一个文本文件中的站点列表,我想针对这些站点运行它。
> https://mysite.sharepoint.com/sites/site1
> https://mysite.sharepoint.com/sites/site2
> https://mysite.sharepoint.com/sites/site3
将站点 url 添加到 CSV 中:
使用 Import-CSV 命令从 CSV 导入和使用站点 url:
$contents = Import-Csv ".\Test.csv"
$ListName= "Documents"
$ReportOutput = "C:\Temp\export.csv"
$Pagesize = 500
foreach($row in $contents)
{
#Parameters
#$SiteURL = "https://mysite.sharepoint.com/sites/site1"
$SiteURL = $row.SiteUrl
#Connect to SharePoint Online site
Connect-PnPOnline $SiteURL -UseWebLogin
#Delete the Output report file if exists
If (Test-Path $ReportOutput) { Remove-Item $ReportOutput}
#Array to store results
$Results = @()
#Get all Items from the document library with given fields
$ListItems = Get-PnPListItem -List $ListName -Fields "FileLeafRef", "SMTotalFileStreamSize", "FileDirRef","Author","Created","File_x0020_Type"
#Iterate through each item
Foreach ($Item in $ListItems)
{
#Filter Files only
If (($Item.FileSystemObjectType) -eq "File")
{
$Results += New-Object PSObject -Property ([ordered]@{
FileName = $Item["FileLeafRef"]
FileType = $Item["File_x0020_Type"]
RootFolder = $Item["FileDirRef"]
RelativeURL = $Item["FileRef"]
FileSize = ($Item["SMTotalFileStreamSize"])
CreatedBy = $Item["Author"].Email
CreatedOn = $Item["Created"]
Modified = $Item["Modified"]
ModifiedByEmail = $Item["Editor"].Email
})
}
}
#Export the results
$Results
$Results | Export-Csv -Path $ReportOutput -NoTypeInformation
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.