TheVDIGuys / Windows_10_VDI_Optimize

Windows 10 optimization script for VDI configurations
MIT License
184 stars 49 forks source link

Get-ChildItem : Access to the path 'C:\Documents and Settings' is denied. #11

Closed DmitrySokolov closed 4 years ago

DmitrySokolov commented 4 years ago
Get-ChildItem : Access to the path 'C:\Documents and Settings' is denied.
At C:\Dev\Tools\Windows_10_VDI_Optimize\1909\Win10_1909_VDI_Optimize.ps1:226 char:18
+ ... sToRemove = Get-ChildItem -Path c:\ -Include *.tmp, *.etl, *.evtx -Re ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Documents and Settings:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

and lots of other,

Get-ChildItem : Access to the path 'C:\Program Files\Windows Defender Advanced Threat Protection\Classification\Configuration' is denied.
At C:\Dev\Tools\Windows_10_VDI_Optimize\1909\Win10_1909_VDI_Optimize.ps1:226 char:18
+ ... sToRemove = Get-ChildItem -Path c:\ -Include *.tmp, *.etl, *.evtx -Re ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Program File...n\Configuration:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

Get-ChildItem : Access to the path 'C:\ProgramData\Application Data' is denied.
At C:\Dev\Tools\Windows_10_VDI_Optimize\1909\Win10_1909_VDI_Optimize.ps1:226 char:18
+ ... sToRemove = Get-ChildItem -Path c:\ -Include *.tmp, *.etl, *.evtx -Re ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\Application Data:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

Get-ChildItem : Access to the path 'C:\ProgramData\Desktop' is denied.
At C:\Dev\Tools\Windows_10_VDI_Optimize\1909\Win10_1909_VDI_Optimize.ps1:226 char:18
+ ... sToRemove = Get-ChildItem -Path c:\ -Include *.tmp, *.etl, *.evtx -Re ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\Desktop:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

Get-ChildItem : Access to the path 'C:\ProgramData\Documents' is denied.
At C:\Dev\Tools\Windows_10_VDI_Optimize\1909\Win10_1909_VDI_Optimize.ps1:226 char:18
+ ... sToRemove = Get-ChildItem -Path c:\ -Include *.tmp, *.etl, *.evtx -Re ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\Documents:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Windows\SystemData' is denied.
At C:\Dev\Tools\Windows_10_VDI_Optimize\1909\Win10_1909_VDI_Optimize.ps1:226 char:18
+ ... sToRemove = Get-ChildItem -Path c:\ -Include *.tmp, *.etl, *.evtx -Re ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...dows\SystemData:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection\Cache' is denied.
At C:\Dev\Tools\Windows_10_VDI_Optimize\1909\Win10_1909_VDI_Optimize.ps1:226 char:18
+ ... sToRemove = Get-ChildItem -Path c:\ -Include *.tmp, *.etl, *.evtx -Re ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...rotection\Cache:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection\Cyber' is denied.
At C:\Dev\Tools\Windows_10_VDI_Optimize\1909\Win10_1909_VDI_Optimize.ps1:226 char:18
+ ... sToRemove = Get-ChildItem -Path c:\ -Include *.tmp, *.etl, *.evtx -Re ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...rotection\Cyber:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

user is local administrator, powershell run as admin

DmitrySokolov commented 4 years ago

powershell 5.1

sandude-ms commented 4 years ago

Hello DmitrySokolov,

Those errors are by design. The script is designed to delete all of those files types (.tmp, .evtx, .etl) anywhere on C:. The script will of course get errors if the files are in use, and just go on. You can see the same result on a Windows device. Open a .CMD prompt as administrator, CD to C:\, then run "del *.tmp /s". If the file is in use, you will get an access denied. Otherwise the file is deleted. Same with .ETL and .EVTX. Those files are used mainly by the DPS service for troubleshooting in case something goes wrong. In our case we are usually creating a gold image and the creation date is "day 1", so we don't need to know all the diagnostic information from before on this image.

Does that all make sense? If the errors are troubling we can look at suppressing those.

Thanks,

Robert M. Smith

DmitrySokolov commented 4 years ago

Hi,

If all these errors are expected, it would be good to suppress them all. This is a little confusing to see all of these errors - whether the script completed correctly or not.

Thanks!