Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Reading temporary data from workstations

$
0
0

Good morning,

First I'm not a programmer, I write some code but looping gets me one loop is easy two loops gets me.  I will first explain what I'm trying to do and then show you my code.

I'm trying to write a script to clean temporary files on workstations, they do not want this to run this as a logon or logoff script thus complicating matters as I cannot use variables to clean up the user profiles on these remote workstations.  This will be run every Sunday.

$a = Get-Content "C:\CSD\Scripts\PLSCAAD_PC_List_Test.csv"

 


#foreach ($i in $a)
 
# {Remove-Item "\\$i\c$\temp\*" -force -recurse}

#foreach ($i in $a)
 
# {Remove-Item "\\$i\c$\windows\temp\*" -force -recurse}


foreach ($i in $a)

{Get-ChildItem "\\$i\c$\users" | Where-Object {$_.PSIsContainer} | Foreach-Object {$_.Name}}

The problem I'm having is storing that last Get-Childitem into a variable.  If I put a $USERPROFILE= in front of that I get an error.  I need to store that list of directories of users into a variable and then write a for each statement against it.  My goal is to clear different temp directories from the users profile.  The rest of the directories are not a problem.

I know that code isn't the cleanest...  I would prefer not to have so many loops in there, but I'm not that good at this sort of thing.  I've managed to be more of a hardware/server admin guy.  I write simple scripts that for example to pull BIOS versions or serials from our servers but we have got other software now that does some of this stuff, although I do write scripts still for drive space.  It's really these loops, I don't know why I have such a block with them but the light bulb has not gone off yet.

Thanks in advance,

Tim

.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>