I am rather new to Powershell and have a question regarding the error I'm receiving. After browsing through stack overflow I have found that users have made errors in spelling and the like and so I haven't found a suitable answer to my problem.
I have one script that runs a backup of some data and compresses it and stores it as:
yyyyMMddsometext.7z
I have another script to get the latest backup (if it was created) and copy it to another location
I am receiving an error
copy-item cannot bind argument to parameter 'path' because it is null
Does this mean that the file is non-existent or is it an error in any of the below?
$c = $textBox.Text
$a = (Get-Date).AddDays(-1).ToString($c)
$b = Get-ChildItem "C:\BackupsRP1" -Filter *.7z | Where-Object BaseName -like "*$a*"
Copy-Item $b -Destination "C:\Users\user\Desktop"
Above the code is a simple GUI for the user to input the date in the format yyyyMMdd and it will locate the file one less day than the user inputs and copy it to the location.
Thank you, J
$b
doesn't hold any value. This is probaly because your filter doesnt't find a matching file, either because the file doesn't exist or the filter is wrong. Write$a
to the console and make sure the filename is correct. – Paxz$c
? – marsze