0

I am currently trying to run a script I wrote. It works great, but I need it to also search and remove from the hidden folders as well. It does not seem to have any effect on hidden folders... Here is my script.

Get-ChildItem C:\ -Include saplogon.ini -Recurse | foreach ($_) {Remove-Item $_.fullname}

$src_dir = "\\xxxxxxxxxx\xxxxxxxxxxxx\saplogon\saplogon.ini"
$dst_dir = "C:\Windows"
$file = Get-ChildItem $src_dir
Copy-Item $file -Destination $dst_dir

[System.Environment]::SetEnvironmentVariable('SAP_LOGON_INI', 'C:\Windows\saplogon.ini', 'Machine')
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tyler S
  • 827
  • 1
  • 14
  • 23

1 Answers1

0

You are missing the the -Force parameter. The code below is using alias so it won't require horizontal scrolling. Know that gci is Get-ChildItem.

Note that you will only be able to get access if you have permission.

gci c:\ -Include saplogon.ini -Recurse -Force | foreach ($_) {remove-item $_.fullname}

At this point, you probably already took care of the non-hidden files. If you want to run the script again, but only for hidden files (and not non-hidden files), you can do that with the -Hidden flag.

Again, you will only be able to get access if you have the permission.

gci c:\ -Include saplogon.ini -Recurse -Hidden | foreach ($_) {remove-item $_.fullname}
nehcsivart
  • 734
  • 7
  • 12