Product:
Microsoft PowerShell
Planning Analytics 2.0.9.17
Microsoft Windows 2019 server
Issue:
I have backup zip files in a folder that i want to move to a different drive, to save space on the first drive.
Solution:
Create a d:\script folder and in notepad++ create a copyoldfile.ps1 file with this content:
# powershell script to copy old files # older than a month from today's date # set common start values $abortFlag = 0 # Get a input parameter https://ss64.com/ps/syntax-args.html # get from folder as parameter to call to script [String]$FromFolder = $Args[0] [String]$ToFolder = $Args[1] # debug lines Write-Host [$FromFolder] Write-Host [$ToFolder] # check if args are empty and then break the code if ( $FromFolder -eq '' ) { Write-Host "Fromfolder is missing" -ForegroundColor Red $abortFlag = 1 } if ( $ToFolder -eq '' ) { Write-Host "Tofolder is missing" -ForegroundColor Red $abortFlag = 1 } if ($abortFlag -eq 1) { Write-Host "The abort flag has been tripped. Exit script." -ForegroundColor Red break } # for each file in folder check date and move file older than 30 days Get-Childitem -File -Path $FromFolder -Filter *.zip | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} | Move-Item -Destination $ToFolder # #
DatasourceASCIIQuoteCharacter= Char(39); SC_QUOTE_COMMAND = Char(34); sExec = 'Powershell -ExecutionPolicy ByPass -file ' | SC_QUOTE_COMMAND | 'd:\script\copyoldfile.ps1' | SC_QUOTE_COMMAND | ' ' ; sSourceDir = SC_QUOTE_COMMAND | 'D:\TM1 Data\Back Up' | SC_QUOTE_COMMAND | ' ' ; sTargetDir = SC_QUOTE_COMMAND | 'd:\arkiv' | SC_QUOTE_COMMAND | ' ' ; sCommand = sExec | ' ' | sSourceDir | ' ' | sTargetDir ; ## remove to debug the string sent to cmd ## ASCIIOUTPUT ( 'd:\temp\result.txt' , sCommand); EXECUTECOMMAND(sCommand,0);
The powershell only accepts ” around its file paths, we have to change the QuoteCharacter to be ‘. Change the folders in the TI process to match your backup folders. Do your developing and testing in your TM1 development servers first.
https://www.ibm.com/docs/en/planning-analytics/2.0.0?topic=tv-turbointegrator-local-variables
More Information:
https://linuxhint.com/loop-through-files-in-a-directory-using-powershell/
https://theitbros.com/powershell-script-for-loop-through-files-and-folders/
https://adamtheautomator.com/powershell-if-statement/
https://ss64.com/ps/syntax-args.html
https://blog.ironmansoftware.com/daily-powershell/assign-powershell-variables/
https://linuxhint.com/get-current-date-powershell/
https://www.red-gate.com/simple-talk/sysadmin/powershell/how-to-use-parameters-in-powershell/