Hi
Es geht um Reports... Programmiert wurde es mit PowerShell ISE
Hier der Fehler:
Rename-Item : Es wurde kein Positionsparameter gefunden, der das Argument "+" akzeptiert.
In Zeile:34 Zeichen:1
+ rename-item "c:\Reporting\Report_Telephone_" + $todaydate[0] +'-' + $todaydate[1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Rename-Item], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.RenameItemCommand
hier mein Code:
#today's date (year-month-day)
$todaydate = Get-Date -Format yyyy-MM-dd
#arrays (today => systemtime)
$todaydate = $todaydate.Split('-')
$todaydate[0] #year
$todaydate[1] #month
$todaydate[2] #day
#arrays yesterday (systemtime - one day)
$yesterdaysdate = Get-Date((Get-Date).AddDays(-1)) -Format yyyy-MM-dd
$yesterdaysdate = $yesterdaysdate.Split('-')
$yesterdaysdate[0] #year
$yesterdaysdate[1] #month
$yesterdaysdate[2] #day
#arrays yesterday (systemtime - one day)
$lastmonth = Get-Date((Get-Date).AddMonths(-1)) -Format yyyy-MM-dd
$lastmonth = $lastmonth.Split('-')
$lastmonth[0] #year
$lastmonth[1] #month
$lastmonth[2] #day
#Example 1: Filename "Report_Telephone_yyyy-mm" => in this case "Report_Telephone_2016-12"
#it renames the file -> minus one month, so the name must be "Report_Telephone_2016-11"
$filename='Report_Telephone_'+ $lastmonth[0]+'-'+ $lastmonth[1] + '.xlsx'
$filemonth = [int][regex]::Match($filename, '\w+_\d+_(\d+)').Groups[1].Value
$filemonth = "{0:D2}" -f ($filemonth - 1)
write-host $filename
rename-item "c:\Reporting\Report_Telephone_" + $todaydate[0] +'-' + $todaydate[1] + ".xlsx" -NewName $filename
$sourcepath='C:\Reporting\'+ $filename
write-host $sourcepath
$destinationpath='C:\Reporting\'+ $lastmonth[0]+'\'+ $lastmonth[1]
write-host $destinationpath
if(test-path $destinationpath)
{
}
else
{
mkdir $destinationpath
}
move-item -path $sourcepath -destination $destinationpath
Hat einer ne Idee, wie ich das lösen könnte? Thx im vorraus :3