1
votes

I am trying to change all the file creation date stamp to new time. I am using below code to do that. I am running this from a VM with an admin ID which as access to all the "FILE share servers".

Am my missing nay permissions to make changes to the files?

Note: File share servers are stored in different servers and I am using my own VM which is in same domain to access those file shares.I can access them through Network path from "RUN". Not sure while access denied error is thrown.

 Function Set-FileTimeStamps {  Param (
     [Parameter(mandatory=$true)]
     [string[]]$path,
     [datetime]$date = (Get-Date) )
     Get-ChildItem -Path $path |
     ForEach-Object {
      $_.CreationTime = $date
      $_.LastAccessTime = $date
      $_.LastWriteTime = $date } } Set-FileTimeStamps -path \\nwst01\test$\rgadagot "07/10/19 10:10"

error:

Exception setting "CreationTime": "Access to the path '\nwst01\test$\user \Data' is denied." Exception setting At line:10 char:6 + $_.CreationTime = $date + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException + FullyQualifiedErrorId : ExceptionWhenSetting

Exception setting"LastAccessTime": "Access to the path '\nwst01\test$\user \Data' is denied." At line:11 char:6 + $_.LastAccessTime = $date + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException + FullyQualifiedErrorId : ExceptionWhenSetting

Exception setting "LastWriteTime": "Access to the path '\nwst01\test$\user \Data' is denied." At line:12 char:6 + $_.LastWriteTime = $date } + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException + FullyQualifiedErrorId : ExceptionWhenSetting

1
Please, PLEASE do not add code as a (link to an) image. Instead, copy/paste the code in the question as text.Theo
Not only that but the output you provide cannot have come from the code. Paste the code in your question, and the output from that code. Did you know you had a space in the path name?Scepticalist
Just now added the code and the errorraj
Hello Everyone, I am able to find below script but it won't be able to change default folders called "My Pictures", My videos" as they are in read-only mode. Can we still force it? or can we ignore in this script? And also can we do it using CSV bulk? $ts = get-date get-childitem c:\temp\test -recurse | ForEach-Object{$_.LastWriteTime = $ts}raj
Note the tag [shell] for POSIX shell has nothing to do with the tag [powershell].David C. Rankin

1 Answers

0
votes

Welcome to stackoverflow.

Try to create a new file at that location (through the same script). If that fails, but you are able to create such a file otherwise, it may be a double-hop issue: Kerberos authentication prevents you from impersonating a 2nd time (even if you are logged in as a domain administrator). There is a workaround with CredSSP but maybe better look into the suggestion here: https://searchwindowsserver.techtarget.com/tutorial/How-to-avoid-the-double-hop-problem-with-PowerShell.