获取上次生成目录的Powershell脚本

获取上次生成目录的Powershell脚本,powershell,Powershell,我想创建powershell脚本/命令以获取最新的生成目录名。说这是我的文件夹列表 2018年1月1日建造 2018年第1期第1期第2期 建设2018年1月1日1月1日3 等等 我想得到最新的版本号 我能在接下来的时间里拿到它。但是,如果任何旧版本被删除,我将不会得到确切的最后一个版本。还有更好的办法吗 $currentTime=$(Get-Date -Format o) $getDate=$currentTime.split("T") $getDate = $getDate[0].replac

我想创建powershell脚本/命令以获取最新的生成目录名。说这是我的文件夹列表 2018年1月1日建造 2018年第1期第1期第2期 建设2018年1月1日1月1日3 等等 我想得到最新的版本号

我能在接下来的时间里拿到它。但是,如果任何旧版本被删除,我将不会得到确切的最后一个版本。还有更好的办法吗

$currentTime=$(Get-Date -Format o)
$getDate=$currentTime.split("T")
$getDate = $getDate[0].replace('-','_')
$previousBuildCount= (Get-ChildItem build_2018_08_16.* -Path C:\builds\).Name.count
$buildVersion='build' + '_' +  $getDate + '.' + ($previousBuildCount + 1)

您可以尝试使用简单的正则表达式解析器:

#demo data
1 | out-file build_01_01_2018.1
2 | out-file build_01_01_2018.2
4 | out-file build_01_01_2018.4

#solution
Get-ChildItem build_01_01_2018.* | % {
  [int][Regex]::Match($_.Name, '(?<=build_01_01_2018\.).*').Value
} | Measure -Maximum | select -ExpandProperty Maximum