Powershell help

Posted on 2011-05-08
Last Modified: 2012-06-21

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

    Expert Comment

    by:Suliman Abu Kharroub
    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
    LVL 67

    Accepted Solution

    2) get-mailbox  | where-object {$ -notlike '*E2010*"}
    3) import-csv YourFileHere.csv | get-mailbox

    LVL 70

    Assisted Solution

    by:Chris Dent
    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 :)

    LVL 3

    Author Comment

    Thanks All

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

    What If I wanted to say, object not like E2010xxx *or* E2003xx, how could I write that?
    LVL 70

    Expert Comment

    by:Chris Dent
    You actually want AND rather than OR, so it's not like either (excludes both).

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

    LVL 67

    Expert Comment

        get-mailbox  | where-object {$ -notlike 'E2010*" -and $_,name -notlike "E2003*"}
    or, for exactly 3 resp. 2 chars after the name:
       get-mailbox  | where-object {$ -notlike 'E2010???" -and $_,name -notlike "E2003??"}
    LVL 70

    Expert Comment

    by:Chris Dent
    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Email statistics and Mailbox database quotas You might have an interest in attaining information such as mailbox details, mailbox statistics and mailbox database details from Exchange server. At that point, knowing how to retrieve this information …
    Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
    To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now