Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Powershell help

Posted on 2011-05-08
7
Medium Priority
?
207 Views
Last Modified: 2012-06-21
Hi

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!
0
Comment
Question by:kam_uk
7 Comments
 
LVL 23

Expert Comment

by:Suliman Abu Kharroub
ID: 35716874
1) you can use Jdeskreport (GUI):
http://www.jgoodies.com/freeware/jdiskreport/

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
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 1000 total points
ID: 35716923
2) get-mailbox  | where-object {$_.name -notlike '*E2010*"}
3) import-csv YourFileHere.csv | get-mailbox

0
 
LVL 71

Assisted Solution

by:Chris Dent
Chris Dent earned 1000 total points
ID: 35720001
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 :)

Chris
0
New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

 
LVL 3

Author Comment

by:kam_uk
ID: 35724113
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?
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 35724320
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*" }

Chris
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 35724347
    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??"}
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 35724463
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})$' }

Or:

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.

Chris
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
This article will help to fix the below errors for MS Exchange Server 2016 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question