kennysarmy Posted August 9, 2019 Posted August 9, 2019 Has anyone come across a script which can be run at startup which would report the contents of C:\users and save the results centrally? I've changed the location of my redirected desktops this summer and want to ensure the script I've run at startup has actually worked and cleaned out all the local profiles, it appears on some machines it's not worked
kennysarmy Posted August 9, 2019 Author Posted August 9, 2019 This powershell script might work! Get-ChildItem -Path C:\users | Out-File \\dc01\netlogon\uc\$env:computername.txt But got to work out how to run the script at startup!
HPlum78 Posted August 9, 2019 Posted August 9, 2019 Can you not just set it up as a schedule task and select the trigger At log on?
kennysarmy Posted August 9, 2019 Author Posted August 9, 2019 I've got the script running... but it can't write the results back Error Message = Access to the path '\\fp4\d$\Server_Apps\Utilities\pcaudit\uc\TEMP00-2019-08.txt' is denied. Fully Qualified Error ID = FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand I've added "Domain Computers to the folder "\\fp4\d$\Server_Apps\Utilities\pcaudit\uc" with full control...
Duke5A Posted August 9, 2019 Posted August 9, 2019 I've got the script running... but it can't write the results back Error Message = Access to the path '\\fp4\d$\Server_Apps\Utilities\pcaudit\uc\TEMP00-2019-08.txt' is denied. Fully Qualified Error ID = FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand I've added "Domain Computers to the folder "\\fp4\d$\Server_Apps\Utilities\pcaudit\uc" with full control... How do you have it running now? Login scripts run under user credential and startup scripts run under local computer credentials. Might be easier to run a batch script with something like this: net use z: \\dc01\netlogon\uc /user:username /password:password dir C:\users > z:\%computername%.txt net use z: /delete ...or as recommended earlier using a scheduled task at startup as you can pass alternate credentials to that as well.
kennysarmy Posted August 9, 2019 Author Posted August 9, 2019 How do you have it running now? Login scripts run under user credential and startup scripts run under local computer credentials. Might be easier to run a batch script with something like this: net use z: \\dc01\netlogon\uc /user:username /password:password dir C:\users > z:\%computername%.txt net use z: /delete ...or as recommended earlier using a scheduled task at startup as you can pass alternate credentials to that as well. I need ideally it to run without having to logon so I've got it running as a startup script. I've set the NTFS permissions on the folder I need the file to be created in to include "Domain Computers" : Full Control.
kennysarmy Posted August 9, 2019 Author Posted August 9, 2019 If I create the file locally it works, so in C:\Windows So is it possible using a powershell startup script to have access to domain resources?
kennysarmy Posted August 9, 2019 Author Posted August 9, 2019 Sorted. I saved the file locally and then used this line: Copy-Item -Path D:\folder\test.txt -Destination \\server1\remoteshare\ and made sure the share had write permissions for Authenticated Users and Domain Computers on both the share and the folder. Might look at changing the script now so it counts the number of folders in C:\users as well!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now