如何从 SMB 共享构建 Excel 工作表的路径和文件名

问题描述 投票:0回答:2

在建造现代床头柜之前需要了解什么 这个 DIY 现代床头柜项目是一个简单的构建,您可以在周末轻松完成。它非常适合用作床头柜,但您也可以将其用作茶几或小型玄关桌。 它用途广泛,非常适合初学者到中级构建!这款床头柜的整体尺寸为 17 ½ 英寸深 x 24 3/4 英寸高 x 27 英寸宽。

powershell
2个回答
0
投票

如果您只想要上个月最后一个星期五的文件,找到它的最简单方法不是构建路径,而只需搜索一个月的文件夹并过滤在星期五创建的文件,按创建时间排序,然后获取第一个(排序后,最后创建的文件夹将是第一项)。

$LastMonth = [datetime]::Now.AddMonths(-1).ToString('yyyy\\M')
$TargetFolder = Get-ChildItem (Join-Path '\\hcohesity05\cohesity_reports' $LastMonth) |Where{$_.CreationTime.DayOfWeek -eq 'Friday'}|Sort CreationTime|Select -first 1
$FilePath = (Resolve-Path (Join-Path $TargetFolder.FullName 'Cohesity_FETB_Report-*-14-26-48.xlsx')).Path
$oldbk = Import-Excel -Path $FilePath

0
投票

您可以使用

[DateTime]
类型来帮助您。

# To do this, we create a new datetime, 
# (using the current month and year, but the first day).
$endOfMonth = [datetime]::new(
    [DateTime]::Now.Year,
    [DateTime]::Now.Month,
    1
).AddMonths(1).AddDays(-1)  
# Then we add a month to it and subtract a day
# (thus giving us the last day of the month)

# Now we create a variable for the last Friday
$lastFriday = $endOfMonth
# and we keep moving backward thru the calendar until it's right.
while ($lastFriday.DayOfWeek -ne 'Friday') {
   $lastFriday = $lastFriday.AddDays(-1) 
}

# At this point, we can make the ReportPath, piece by piece
# ($BasePath would be the path until this point)

$ReportPrefix = "Cohesity_FETB_Report"
$ReportSuffix = "14-26-48.xlsx"

$ReportPath = Join-Path $BasePath $lastFriday.Year |
    Join-Path -ChildPath $lastFriday.Month |
    # A Custom format string will be needed for the month/day
    Join-Path -ChildPath $lastFriday.ToString("MM-dd") | 
    Join-Path -ChildPath "$reportPrefix-$($lastFriday.ToString('YYYY-MM-dd'))-$reportSuffix"

$reportPath

© www.soinside.com 2019 - 2024. All rights reserved.