Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

deleting sms junk folders that require admin permission

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 06-26-2008   #1 (permalink)
IT STAFF
Guest


 

deleting sms junk folders that require admin permission

When sms fails to install package on a machine, it will create some *junk
folders* eg d:\01b23a6a69662dce1aef

I know how to delete it manually by the following :

a) Go to folder's security tab properties and select Administrators, allow
full control.
b) delete it manually.

Problem is there are numerous *junk folders* and the *COMMON * folder under
it is "update" folder. Therefore i need to loop every folders and if detect
"update" subfolder, it should delete the root folder which is eg
d:\01b23a6a69662dce1aef OR d:\17aaa9a1d699800e0de905789dae4b16

At the same time, i need to ensure that i take the root junk folders and
assign full permission over it and delete it.

I also need to do it REMOTELY, ie delete these folders at remote pc that sms
created.

Any help ?






My System SpecsSystem Spec
Old 06-26-2008   #2 (permalink)
Marco Shaw [MVP]
Guest


 

Re: deleting sms junk folders that require admin permission

IT STAFF wrote:
Quote:

> When sms fails to install package on a machine, it will create some *junk
> folders* eg d:\01b23a6a69662dce1aef
>
> I know how to delete it manually by the following :
>
> a) Go to folder's security tab properties and select Administrators, allow
> full control.
> b) delete it manually.
>
> Problem is there are numerous *junk folders* and the *COMMON * folder under
> it is "update" folder. Therefore i need to loop every folders and if detect
> "update" subfolder, it should delete the root folder which is eg
> d:\01b23a6a69662dce1aef OR d:\17aaa9a1d699800e0de905789dae4b16
>
> At the same time, i need to ensure that i take the root junk folders and
> assign full permission over it and delete it.
>
> I also need to do it REMOTELY, ie delete these folders at remote pc that sms
> created.
>
> Any help ?
So the directory structure is d:\something\update or can update be
deeper like d:\something\something\deeper?

Does the script need to look through all the local drives?

Just to keep Brandon happy, I think you can do this with LogParser... ;-)

Seriously, a combination of WinRM and PowerShell may help. Do you have
both installed on the remote systems?

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 06-26-2008   #3 (permalink)
IT STAFF
Guest


 

Re: deleting sms junk folders that require admin permission


The directory structure is d:\something\update

LogParser ?

I've ctp v2 of powershell ...do i need to install winrm in EVERY remote
machine OR just install winrm in the machine that runs the script ?


Quote:

> So the directory structure is d:\something\update or can update be deeper
> like d:\something\something\deeper?
>
> Does the script need to look through all the local drives?
>
> Just to keep Brandon happy, I think you can do this with LogParser... ;-)
>
> Seriously, a combination of WinRM and PowerShell may help. Do you have
> both installed on the remote systems?
>
> Marco
>
> --
> Microsoft MVP - Windows PowerShell
> http://www.microsoft.com/mvp
>
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
>
> Blog:
> http://marcoshaw.blogspot.com

My System SpecsSystem Spec
Old 06-27-2008   #4 (permalink)
Kuma
Guest


 

Re: deleting sms junk folders that require admin permission

On Jun 27, 1:02*pm, "IT STAFF" <jkk...@xxxxxx> wrote:
Quote:

> The directory structure is d:\something\update
>
> LogParser ?
>
> I've ctp v2 of powershell ...do i need to install winrm in EVERY remote
> machine OR just install winrm in the machine that runs the script ?
>
>
>
Quote:

> > So the directory structure is d:\something\update or can update be deeper
> > like d:\something\something\deeper?
>
Quote:

> > Does the script need to look through all the local drives?
>
Quote:

> > Just to keep Brandon happy, I think you can do this with LogParser... ;-)
>
Quote:

> > Seriously, a combination of WinRM and PowerShell may help. *Do you have
> > both installed on the remote systems?
>
Quote:

> > Marco
>
Quote:

> > --
> > Microsoft MVP - Windows PowerShell
> >http://www.microsoft.com/mvp
>
Quote:

> > PowerGadgets MVP
> >http://www.powergadgets.com/mvp
>
Quote:

> > Blog:
> >http://marcoshaw.blogspot.com- Hide quoted text -
>
> - Show quoted text -
Sorry if this is a bit hard to read, kinda in a hurry
Doable with wmi and .Net
You will need to have admin rights on the remote machine
# Get a ACL from an object you have full permission on
$permission = Get-ACL -Path "DIR_TO_COPY_PERMMISSIONS_FROM"
#Assign a computername to a variable
$comp = "COMPUTERYOUNEEDTOCLEAN"
#Get the list of directories from the computer
$directory = Get-WMIObject -ComputerName $comp -Query {SELECT DeviceID
FROM Win32_LogicalDisk WHERE DriveType='3'} | Select DeviceID |
Foreach-Object {$_.DeviceID.Replace(":", "$")} | Foreach-
Object{[System.IO.Directory]::GetDirectories("\\$comp\$_")} | Where-
Object {!$_.Contains("System Volume Information")} | Foreach-Object{$_,
[System.IO.Directory]::GetDirectories("$_", "UPDATE",
[System.IO.SearchOption]::AllDirectories)} | Foreach-
Object{[System.IO.Directory]::GetParent($_)}
#For each directory, take ownership
$directory | Foreach-Object
{$_.GetAccessControl().setowner($permission.GetOwner([System.Security.Principal.NTAccount]))}
#copy permissions
foreach($dir in $directory) {Set-Acl $dir -AclObject $permission}
#Delete the directory Remove the -whatif after you test it
$directory | Foreach-Object {del $_.FullName -Whatif}

Hope that helps a little bit, I'll try to come back and explain
further if you can't follow it.
My System SpecsSystem Spec
Old 06-27-2008   #5 (permalink)
Marco Shaw [MVP]
Guest


 

Re: deleting sms junk folders that require admin permission

Quote:

> Hope that helps a little bit, I'll try to come back and explain
> further if you can't follow it.
I'm not really challenging this approach, but would be interested in the
performance aspect.

I'll have to try it.

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 06-27-2008   #6 (permalink)
Marco Shaw [MVP]
Guest


 

Re: deleting sms junk folders that require admin permission

Quote:

> I've ctp v2 of powershell ...do i need to install winrm in EVERY remote
> machine OR just install winrm in the machine that runs the script ?
You would have to have WinRM installed on the remote machines. So that
may not be an option...

Marco
My System SpecsSystem Spec
Old 07-03-2008   #7 (permalink)
IT STAFF
Guest


 

Re: deleting sms junk folders that require admin permission


$directory = Get-WMIObject -ComputerName $comp -Query {SELECT DeviceID FROM
Win32_LogicalDisk WHERE DriveType='3'} | Select DeviceID | Foreach
{$_.DeviceID.Replace(":", "$")} | Foreach
{[System.IO.Directory]::GetDirectories("\\$comp\$_")} | Where
{!$_.Contains("System Volume Information")} |Foreach
{$_,[System.IO.Directory]::GetDirectories("$_",
"UPDATE",[System.IO.SearchOption]::topdirectoryonly)}


$directory | Foreach {[System.IO.Directory]::GetParent($_)}


Error : "Path cannot be the empty string or all whitespace.

===================================






"Sorry if this is a bit hard to read, kinda in a hurry
Doable with wmi and .Net
You will need to have admin rights on the remote machine
# Get a ACL from an object you have full permission on
$permission = Get-ACL -Path "DIR_TO_COPY_PERMMISSIONS_FROM"
#Assign a computername to a variable
$comp = "COMPUTERYOUNEEDTOCLEAN"
#Get the list of directories from the computer
$directory = Get-WMIObject -ComputerName $comp -Query {SELECT DeviceID
FROM Win32_LogicalDisk WHERE DriveType='3'} | Select DeviceID |
Foreach-Object {$_.DeviceID.Replace(":", "$")} | Foreach-
Object{[System.IO.Directory]::GetDirectories("\\$comp\$_")} | Where-
Object {!$_.Contains("System Volume Information")} | Foreach-Object{$_,
[System.IO.Directory]::GetDirectories("$_", "UPDATE",
[System.IO.SearchOption]::AllDirectories)} | Foreach-
Object{[System.IO.Directory]::GetParent($_)}
#For each directory, take ownership
$directory | Foreach-Object
{$_.GetAccessControl().setowner($permission.GetOwner([System.Security.Principal.NTAccount]))}
#copy permissions
foreach($dir in $directory) {Set-Acl $dir -AclObject $permission}
#Delete the directory Remove the -whatif after you test it
$directory | Foreach-Object {del $_.FullName -Whatif}

Hope that helps a little bit, I'll try to come back and explain
further if you can't follow it.


My System SpecsSystem Spec
Old 07-07-2008   #8 (permalink)
Kuma
Guest


 

Re: deleting sms junk folders that require admin permission

Let me try to explain this a bit better.

# Get a ACL from an object you have full permission on
$permission = Get-ACL -Path "DIR_TO_COPY_PERMMISSIONS_FROM"

#Assign a computername to a variable this should be the computer you
need to target as a string ie "FX354-QR421"
$comp = "COMPUTERYOUNEEDTOCLEAN"

#Get the list of directories from the computer
#First get a list of all fixed hdd in the computer using wmi
$directory = Get-WMIObject -ComputerName $comp -Query
{SELECT DeviceID FROM Win32_LogicalDisk WHERE DriveType='3'} |
#Grab only the device ID "C:" "D:" etc
Select DeviceID |
#Foreach Drive Replace the : with a $
Foreach-Object {$_.DeviceID.Replace(":", "$")} |
#Foreach drive use .Net class to search only top Directories so we
can
#filter out the System Volume Information since only the OS hass
access to this folder
Foreach-Object{[System.IO.Directory]::GetDirectories("\\$comp\$_")} |
Where-Object {!$_.Contains("System Volume Information")} |
# Foreach top level directory search recursively for a folder named
"UPDATE"
Foreach-Object{$_, [System.IO.Directory]::GetDirectories("$_",
"UPDATE",
[System.IO.SearchOption]::AllDirectories)} |
# Foreach "UPDATE" Directory get the parent directory and store it in
the $directory variable
Foreach-Object{[System.IO.Directory]::GetParent($_)}
#For each directory, take ownership
$directory | Foreach-Object
{$_.GetAccessControl().setowner($permission.GetOwner([System.Security.Princ*
ipal.NTAccount]))}
#copy permissions
foreach($dir in $directory) {Set-Acl $dir -AclObject $permission}
#Delete the directory Remove the -whatif after you test it
$directory | Foreach-Object {del $_.FullName -Whatif}

The only idea i have at the moment is that you have an UPDATE folder
directly under the root drive. From you post above that shouldn't be
the case though.

I would say try to set the $permission variable and $computername
variable
then start inputting that big pipeline one step at a time. Check
$directory before you add
another pipe.

ie set vars then run $directory = Get-WMIObject -ComputerName $comp -
Query {SELECT DeviceID
FROM Win32_LogicalDisk WHERE DriveType='3'}
view $directory
then add the next part of the pipe
view $directory
etc...
It's working allright when i build a C:\a9y4bag897ay890ag\UPDATE
directory on a remote box then remove
my permissions from it. Its able to delete it with no problem. Let me
know if it works out for you.
My System SpecsSystem Spec
Old 07-07-2008   #9 (permalink)
IT STAFF
Guest


 

Re: deleting sms junk folders that require admin permission

Let me try and get back to u on this.

I am looking at directories that only have "update" at the 2nd level. Thus i
wish to cut down on the search. Also i prefer to look at d:\ drive rather
than all hard-drive eg c:\

Any "update" folder at deeper level, i will not be deleting.



"Kuma" <kumasan76@xxxxxx> wrote in message
news:bd992d0e-fd02-4974-99b4-6f84da633a42@xxxxxx
Let me try to explain this a bit better.

# Get a ACL from an object you have full permission on
$permission = Get-ACL -Path "DIR_TO_COPY_PERMMISSIONS_FROM"

#Assign a computername to a variable this should be the computer you
need to target as a string ie "FX354-QR421"
$comp = "COMPUTERYOUNEEDTOCLEAN"

#Get the list of directories from the computer
#First get a list of all fixed hdd in the computer using wmi
$directory = Get-WMIObject -ComputerName $comp -Query
{SELECT DeviceID FROM Win32_LogicalDisk WHERE DriveType='3'} |
#Grab only the device ID "C:" "D:" etc
Select DeviceID |
#Foreach Drive Replace the : with a $
Foreach-Object {$_.DeviceID.Replace(":", "$")} |
#Foreach drive use .Net class to search only top Directories so we
can
#filter out the System Volume Information since only the OS hass
access to this folder
Foreach-Object{[System.IO.Directory]::GetDirectories("\\$comp\$_")} |
Where-Object {!$_.Contains("System Volume Information")} |
# Foreach top level directory search recursively for a folder named
"UPDATE"
Foreach-Object{$_, [System.IO.Directory]::GetDirectories("$_",
"UPDATE",
[System.IO.SearchOption]::AllDirectories)} |
# Foreach "UPDATE" Directory get the parent directory and store it in
the $directory variable
Foreach-Object{[System.IO.Directory]::GetParent($_)}
#For each directory, take ownership
$directory | Foreach-Object
{$_.GetAccessControl().setowner($permission.GetOwner([System.Security.Princ*
ipal.NTAccount]))}
#copy permissions
foreach($dir in $directory) {Set-Acl $dir -AclObject $permission}
#Delete the directory Remove the -whatif after you test it
$directory | Foreach-Object {del $_.FullName -Whatif}

The only idea i have at the moment is that you have an UPDATE folder
directly under the root drive. From you post above that shouldn't be
the case though.

I would say try to set the $permission variable and $computername
variable
then start inputting that big pipeline one step at a time. Check
$directory before you add
another pipe.

ie set vars then run $directory = Get-WMIObject -ComputerName $comp -
Query {SELECT DeviceID
FROM Win32_LogicalDisk WHERE DriveType='3'}
view $directory
then add the next part of the pipe
view $directory
etc...
It's working allright when i build a C:\a9y4bag897ay890ag\UPDATE
directory on a remote box then remove
my permissions from it. Its able to delete it with no problem. Let me
know if it works out for you.


My System SpecsSystem Spec
Old 07-08-2008   #10 (permalink)
Kuma
Guest


 

Re: deleting sms junk folders that require admin permission

On Jun 27, 10:48*am, "IT STAFF" <jkk...@xxxxxx> wrote:
Quote:

> When sms fails to install package on a machine, it will create some *junk
> folders* eg d:\01b23a6a69662dce1aef
>
> I know how to delete it manually by the following :
>
> a) Go to folder's security tab properties and select Administrators, allow
> full control.
> b) delete it manually.
>
> Problem is there are numerous *junk folders* and the *COMMON * folder under
> it is "update" folder. Therefore i need to loop every folders and if detect
> "update" subfolder, it should delete the root folder which is eg
> d:\01b23a6a69662dce1aef *OR *d:\17aaa9a1d699800e0de905789dae4b16
>
> At the same time, i need to ensure that i take the root junk folders and
> assign full permission over it and delete it.
>
> I also need to do it REMOTELY, ie delete these folders at remote pc that sms
> created.
>
> Any help ?
Cant figure out why this isnt posting but set the SearchOption to
AllDirectories
[System.IO.SearchOption]::AllDirectories
not
[System.IO.SearchOption]::TopDirectoryOnly
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
For ITStaff Reply for deleting junk folders Kuma PowerShell 0 07-08-2008 03:30 AM
Several programs require Permission paroots Vista General 5 04-13-2008 08:10 AM
Setting process priority on applications that require Run as Admin Aidan Chalk Vista performance & maintenance 2 02-13-2008 03:04 PM
Re: Running 3rd party apps that require admin privs on Vista PA Bear [MS MVP] Vista security 1 01-25-2008 05:15 PM
Adjust font size (DPI) does not require admin privs Marco Vista security 1 07-01-2006 01:21 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51