I am executing this following code snippet in power shell.
$FilePath="C:\Temp\SomeFolder"
$dt = (Get-date).Adddays("-2");
Get-Childitem $FilePath |where{$_.lastwritetime -lt $dt}|Remove-Item;echo $?;
The error I am getting is this -
Object reference not set to an instance of an object.
There can be no NullReference as far as I can ensure and the path inside the server is also valid. Also this code works for other paths present in D drives and E drives in other servers. Can anyone kindly help me to figure out the issue?