重新排列文件夹中的数据

重新排列文件夹中的数据

下面我有一段代码,用于将数据(Excel 格式)从一个文件夹移动到另一个文件夹。我希望这段代码每天运行一次(一天一次)。我需要帮助才能正确执行这段代码。我希望每 24 小时保留这些文件并将其放在另一个文件夹中,用同名的新文件替换旧文件。

# Code to get newest directory

$newestFolder = gci \Server123\ | ? { $_.PSIsContainer } | sort CreationTime -desc | select -f 1

<# get the latest created folder from a path #>
# Copy folder to a folder with different name

Copy-Item $newestFolder.FullName -Destination "\Server123\SP Capacity Planning" -Recurse
Rename filename by removing the last few characters (all files in folder)

Get-ChildItem '\Server123\SP Capacity Planning' -filter *.csv | rename-item -NewName {$.name.substring(0,$.BaseName.length-15) + $.Extension -replace ""," "}
Code to copy newest file to new directory

# file-> Average-Action2018-06-13.csv to Average-Action.csv

$targetdirectory = "\Server123\SP Capacity Planning - ShotName"

$sourcedirectory = "\Server123\SP Capacity Planning"

if (!(Test-Path -path $targetdirectory)) {New-Item $targetdirectory -Type Directory} Copy-Item -Path $sourcedirectory\Average-Action.csv -Destination $targetdirectory

# file-> Avg-per-Max-dur2018-06-13.csv to Avg-per-Max-d.csv

$targetdirectory1 = "\Server123\SP Capacity Planning - ShotName"

$sourcedirectory1 = "\Server123\SP Capacity Planning"

if (!(Test-Path -path $targetdirectory1)) {New-Item $targetdirectory1 -Type Directory} Copy-Item -Path $sourcedirectory1\Avg-per-Max-d.csv -Destination $targetdirectory1

# file-> MaxDuration2018-06-13.csv to MaxDuration20.csv

$targetdirectory2 = "\Server123\SP Capacity Planning - ShotName"

$sourcedirectory2 = "\Server123\SP Capacity Planning"

if (!(Test-Path -path $targetdirectory2)) {New-Item $targetdirectory2 -Type Directory} Copy-Item -Path $sourcedirectory1\MaxDuration20.csv -Destination $targetdirectory1
Import Data needed for Capacity Report

$columbs12 = Import-Csv \Server123\SP Capacity Planning - ShotName\Average-Action.csv | select -ExpandProperty UniqueRequests, UniqueUsers

$columbs3456 = Import-Csv \Server123\SP Capacity Planning - ShotName\Avg-per-Max-d.csv | select -ExpandProperty Percentile80, Percentile95, Percentile99, MaxDuration

$columbs789 = Import-Csv \Server123\SP Capacity Planning - ShotName\MaxDuration20.csv | select -ExpandProperty Percentile80, Percentile95, Percentile99, MaxDuration
Merge Files for Capacity Report

Merge-CSVFiles -CSVFiles $columbs12, $columbs3456, $columbs789 -OutputFile \Server123\SP Capacity Planning\CapacityReport.csv

错误消息:

Copy-Item : Cannot find path '\\Server123\sharepoint\HCL\HCL-SUPPORT-SHARED\REPORTING\CAPACITY-PLANNING\S P Capacity Planning\Average-Action.csv' because it does not exist. At line:26 char:1 + Copy-Item -Path $sourcedirectory\Average-Action.csv -Destination $tar ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (\\Server123...rage-Action.csv:String) [Copy-Item], ItemNo tFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand 
Copy-Item : Cannot find path '\\Server123\sharepoint\HCL\HCL-SUPPORT-SHARED\REPORTING\CAPACITY-PLANNING\S P Capacity Planning\MaxDuration20.csv' because it does not exist. At line:47 char:1 + Copy-Item -Path $sourcedirectory1\MaxDuration20.csv -Destination $tar ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
~~~~~~~~ 
+ CategoryInfo : ObjectNotFound: (\\Server123...xDuration20.csv:String) [Copy-Item], ItemNo tFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand Import-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "Capacity" to type "System.Char". Error: 
"String must be exactly one character long." At line:51 char:106 + ... CL\HCL-SUPPORT-SHARED\REPORTING\CAPACITY-PLANNING\SP Capacity Plannin ... + ~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Import-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ImportCsvCommand 
Import-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "Capacity" to type "System.Char". Error: "String must be exactly one character long." At line:53 char:108 + ... CL\HCL-SUPPORT-SHARED\REPORTING\CAPACITY-PLANNING\SP Capacity Plannin ... + ~~~~~~~~ 
+ CategoryInfo : InvalidArgument: (:) [Import-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ImportCsvCommand –
Import-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "Capacity" to type "System.Char". Error: "String must be exactly one character long." At line:55 char:107
+ ... CL\HCL-SUPPORT-SHARED\REPORTING\CAPACITY-PLANNING\SP Capacity Plannin ... + ~~~~~~~~ 
+ CategoryInfo : InvalidArgument: (:) [Import-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ImportCsvCommand 
Import-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "Capacity" to type "System.Char". Error: "String must be exactly one character long." At line:51 char:106 + ... CL\HCL-SUPPORT-SHARED\REPORTING\CAPACITY-PLANNING\SP Capacity Plannin ... + ~~~~~~~~ 
+ CategoryInfo : InvalidArgument: (:) [Import-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ImportCsvCommand Import-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "Capacity" to type "System.Char". Error: "String must be exactly one character long." At line:53 char:108 
+ CategoryInfo : InvalidArgument: (:) [Import-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ImportCsvCommand Import-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "Capacity" to type "System.Char". Error: "String must be exactly one character long." 
At line:55 char:107 + ... CL\HCL-SUPPORT-SHARED\REPORTING\CAPACITY-PLANNING\SP Capacity Plannin ... + ~~~~~~~~ + 
CategoryInfo : InvalidArgument: (:) [Import-Csv], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ImportCsvCommand 
Merge-CSVFiles : The term 'Merge-CSVFiles' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:59 char:1 + Merge-CSVFiles -CSVFiles $columbs12, $columbs3456, $columbs789 -Outpu ... + ~~~~~~~~~~~~~~ + 
CategoryInfo : ObjectNotFound: (Merge-CSVFiles:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

相关内容