Powershell help


Just to pieces of advice I need:

1. We have W2008 servers and some of the time, their disk space gets low on the C:. Rather than right click each folder to see properties/size, is there a PS command I can run that will show the sizes of folders (and pref sub-folders too)?

2. I'm running a Get-mailboxserver command where I want all mailboxes except those with the name "E2010" in them. How can I filter the Get-mailbox command so it ignores any servers with "E2010" in their name?

3. I'd like to run a Get-mailboxserver command where the mailbox names are in the CSV flie, how can I use this?

Many thanks in advance!
Who is Participating?
QlemoConnect With a Mentor Batchelor, Developer and EE Topic AdvisorCommented:
2) get-mailbox  | where-object {$_.name -notlike '*E2010*"}
3) import-csv YourFileHere.csv | get-mailbox

Suliman Abu KharroubIT Consultant Commented:
1) you can use Jdeskreport (GUI):

2) I would suggest to past eh result to excel and remove unwanted entries...

3) just appeand ">filename.svc" in the end of line.
get-mailobxerver >c:\filesname.svc
Chris DentConnect With a Mentor PowerShell DeveloperCommented:
1. Yes, but PS has some limitations (or rather, .NET has some limitations). It cannot handle path lengths longer than 256(ish) characters. I work-around this using the DOS version of dir. Making my recursive size counting script this:
Get-ChildItem C:\ | Select-Object Name, FullName, 
    @{n='Data';e={ cmd /c "dir $($_.FullName) /s" | Select-Object -Last 2 }} | 
  ForEach-Object {

    $FileCount = 0; $FolderCount = 0; $TotalSize = 0

    If ($_.Data[0] -Match '\d*(?=\sFile\(s\))') { $FileCount = $Matches[0] }
    If ($_.Data[1] -Match '\d*(?=\sDir\(s\))')  { $FolderCount = $Matches[0] }
    If ($_.Data[0] -Match '(?<=File\(s\)\s*)[\d,]*(?=\sbytes)') { $TotalSize = ([UInt64]($Matches[0] -Replace ',')) / 1Mb }

    $_ | Select-Object Name, FullName, @{n='FileCount';e={ $FileCount }}, @{n='FolderCount';e={ $FolderCount }}, @{n='TotalSize';e={ $TotalSize }}


Open in new window

Sizes are reported in Mb.
2 and 3. Qlemo has it :)

Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

kam_ukAuthor Commented:
Thanks All

One question regarding: get-mailbox  | where-object {$_.name -notlike '*E2010*"}

What If I wanted to say, object not like E2010xxx *or* E2003xx, how could I write that?
Chris DentPowerShell DeveloperCommented:
You actually want AND rather than OR, so it's not like either (excludes both).

get-mailbox  | where-object {$_.name -notlike '*E2010*" -And $_.Name -NotLike "E2003*" }

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
    get-mailbox  | where-object {$_.name -notlike 'E2010*" -and $_,name -notlike "E2003*"}
or, for exactly 3 resp. 2 chars after the name:
   get-mailbox  | where-object {$_.name -notlike 'E2010???" -and $_,name -notlike "E2003??"}
Chris DentPowerShell DeveloperCommented:
I tend to use RegEx for things like this. I probably like them too much :) For example:

Get-Mailbox  | Where-Object { $_.Name -NotMatch '^(E2003.{2}|E2010.{3})$' }


Get-Mailbox  | Where-Object { $_.Name -NotMatch '^E20(03\w{2}|10\w{3})$' }
Probably a bit over the top though, and harder to get right unless you like RegEx already.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.