24 Oct 2011 @ 6:59 AM 

Last weekend I’ve been asked to write a script that will output the size of all files within a folder, and the files in all its sub-folders.
So, again something that’s possible with a one-liner Smile

Get-ChildItem D:\Software -recurse | Select-Object Name, @{Name="KiloBytes";Expression={$_.Length / 1KB}}

You don’t want the output to be in Kb but in MB? No problem…

Get-ChildItem D:\Software -recurse | Select-Object Name, @{Name="MegaBytes";Expression={$_.Length / 1MB}}

Post to Twitter

Posted By: Jeff Wouters
Last Edit: 24 Oct 2011 @ 06:59 AM

EmailPermalinkComments (5)
Tags
Categories: PowerShell, Script, Windows
 22 Oct 2011 @ 10:11 PM 

A few seconds ago I saw a tweet passing by telling me that SetACL had a new version.
That got me thinking… could I do some of the basics with PowerShell? Not that it would replace a great tool like SetACL, but what if I could type in the command in the same time it would take me to download and install SetACL?
And yes I could, as normally with PowerShell it would only take a simple command.

First, create a file or folder and set the appropriate ACL to it, for example through the GUI in Windows. Next, open a PowerShell window and enter the following command which will get the ACL from a target and put it into a variable:
$NewAcl = Get-ACL D:\Software

Now that we have a point of reference and saved it to a variable, we can use this information when setting the ACL on whatever target (and all it’s sub files and folders by using the –recurse parameter) we specify with the following command:
Get-ChildItem D:\Pictures -recurse | Set-ACL –ACLObject $NewACL

But what if you only want to set the ACL for specific files, for example all files with the .pptx extension?
Get-ChildItem D:\Pictures –recurse –include *.pptx –force | Set-ACL –ACLObject $NewACL

I would like to explain again that this would not be a replacement of a tool, since such a simple command can’t replace the full functionality of the SetACL tool.

Post to Twitter

Posted By: Jeff Wouters
Last Edit: 22 Oct 2011 @ 10:11 PM

EmailPermalinkComments (0)
Tags
Categories: PowerShell, Script, Windows

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
 Last 50 Posts
 Back
Change Theme...
  • Users » 1
  • Posts/Pages » 125
  • Comments » 98
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About



    No Child Pages.

Contact



    No Child Pages.