Struggling with a simple Power Shell command

I have been doing a lot of mailbox moving and after the move, the source winds up in Disconnected Mailboxes. I typically wait a few days before removing the disconnected mailbox to make sure the user is OK. Although I have never restored a mailbox from a
disconnected state, I suppose the situation could arise some day. Anyway, I use the commands below to remove the disconnected mailboxes.
$sdmailbox=Get-MailboxStatistics -Database DB1| where {$_.DisconnectReason -eq “SoftDeleted”}
then
$sdmailbox | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.DisplayName -MailboxState SoftDeleted} $confirm
Of course, the first command returns ALL the softdeleted mailboxes. Is there a way to run this command so it only returns mailboxes that were disconnected say 2 days ago?
Been playing around with the variable $_.DisconnectedDate and just can't get it to work.

Disconnected before two days...
$sdmailbox=Get-MailboxStatistics -Database DB1| where {$_.DisconnectReason -eq “SoftDeleted” -and $_.DisconnectDate -ne $null -and $_.DisconnectDate -lt (get-date).AddDays(-2)}
Disconnected in last two days ...
$sdmailbox=Get-MailboxStatistics -Database DB1| where {$_.DisconnectReason -eq “SoftDeleted” -and $_.DisconnectDate -ne $null -and $_.DisconnectDate -gt (get-date).AddDays(-2)}
Blog |
Get Your Exchange Powershell Tip of the Day from here

Similar Messages

  • Find Software with Version using Power-shell Command

    Hi All,
             In have very urgent requirement to find the version of particular software .Is there any way to find the result as we write below snippet of code to find the software list using batch script.
    batch script.
    WMIC product where 'name like "%Opera%"' get name,version
    Thanks, Quality Communication Provides Quality Work. http://siddiq-sharepoint2010.blogspot.in/ Siddiqali Mohammad .

    Does that WMI query grab all installed software?  When I check via WMI I get many pieces of software, but some appear to not be registered there, e.g. adobe flash player.  most identify in both queries, however some show up in WMI but not in the
    registry and v/v.
    PS C:\WINDOWS\system32> Get-WmiObject win32_product | Select-Object -Property Name,Version | Sort-Object -Property Name
    Name Version
    64 Bit HP CIO Components Installer 4.2.1
    ActivClient x64 7.0.2
    Adobe Acrobat X Pro - English, Français, Deutsch 10.1.9
    Adobe AIR 4.0.0.1390
    Adobe Customization Wizard XI 11.0.0
    etc.
    When I check the uninstall reg keys (which processes a bitfaster, about 2-3 seconds instead of 12-13 seconds on a test machine ) I see:
    Function Get-InstalledProgramInfo
    $InstalledSoftware = (Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ | Get-ItemProperty)
    IF (Test-path HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\) {
    $InstalledSoftware += (Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\ | Get-ItemProperty)
    IF (Test-path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\) {
    $InstalledSoftware += (Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ | Get-ItemProperty) }
    ($InstalledSoftware | Where {$_.DisplayName -ne $Null -AND $_.SystemComponent -ne "1" -AND $_.ParentKeyName -eq $Null})| Select-Object -Property DisplayName,DisplayVersion,InstallDate | Sort-Object -Property DisplayName
    DisplayName DisplayVersion InstallDate
    ActivClient x64 7.0.2 20140314
    Adobe Acrobat X Pro - E... 10.1.9 20140227
    Adobe AIR 4.0.0.1390
    Adobe Customization Wiz... 11.0.0 20140325
    Adobe Flash Player 12 P... 12.0.0.43
    etc.

  • Need a power shell command for Front End fail over?

    We have a Lync 2013 infrastructure with 2 front ends and 2 edges. 
    The environment was setup by a partner and the servers were configured for failover in case one goes down in the pool. 
    However the last time windows updates were applied and the primary FE had to be restarted, the secondary FE did not automatically switch over as the active server and it caused a companywide outage. 
    In speaking with the contractor, they said that well no it would not automatically do this, you need to run a Lync PowerShell to have it switch over. 
    My BS radar went off, but I wanted to ask you if this sounds right or is possible. 
    If it must be done, could you give me the power shell command.
    Thanks

    Hi,
    Did you solve the issue with the help of the people above provided?
    If you use a Lync server Enterprise edition, it is recommended to deploy at least three FE servers.
    If you use two Lync server Standard edition for DR,
    when one of the servers fails in the Pool Pair, the administrator need to manually failover the pool to the other member of the Pool Pair using the
    command: Invoke-CsPoolFailover -PoolFQDN <Pool1 FQDN> -DisasterMode -Verbose
    The Automatic failover and failback for
    Voice option and the associated time intervals in Topology Builder apply only to the voice resiliency features that were introduced in Lync Server 2010. Selecting this option does not imply that the pool failover discussed in this document is automatic.
    Pool failover and failback always require an administrator to manually invoke the failover and failback.
    You can refer to the link below about how to failover a pool: 
    http://technet.microsoft.com/en-gb/library/jj204678.aspx
    Best Regards,
    Eason Huang
    Eason Huang
    TechNet Community Support
    Does it help, yes and no.  FYI, we are running Enterprise Edition front ends for our single pool.  The new environment was setup as a proof of concept and we installed the bare minimum # of servers at the time.
    The articles suggested from above pretty much just say if one of your FE's goes down, bring it back up as soon as possible.  Both of our FE's need windows updates applied ASAP and it could an hour or more (likely).  Here is a quote from the article:
    If for some reason you need to bring both servers down at the same time, do the following when the downtime for the pool is finished:
    The best practice is to restart both Front End Servers at the same time.
    If the two servers cannot be restarted at the same time, you should bring them back up in the reverse order of the order they went down.
    If you cannot bring them back up in that order, then use the following cmdlet before bringing the pool back up:
    Reset-CsPoolRegistrarState -ResetType QuorumLossRecovery -PoolFQDN <FQDN>
    The last time the main FE went down for service, we left the secondary FE on but there was still an outage.  Then brought back the formerly active FE fist and service was restored.  Basically I need to know how to switch the passive to the active
    node before/while the primary is offline.  And if required once both FE's are back up, to switch the service from the secondary that became active, back to the primary server as it was before.  Make sense?  Perhaps I'm still missing something
    after reading the articles.  The powershell commands list just updating the topology after both servers come back online.

  • Power Shell Command using CSOM

    Hi,
    We have prepared a Power Shell command using Client Side scripts as per client requirements. The client did not had access to the SharePoint Server. So, PS commands with
    server side scripts was out of scope. 
    The client requirement was to delete all the permissions on the list that was being inherited from site. Since the number of users were huge, so deleting all the users using ribbon was not possible.
    Please have a look at the scripts below and let me know your feedback. If you have better suggestion than this, please let me know.
    #location of client dlls on users' local system
    $loc = "C:\SharePoint\ClientDLL" 
    //SharePoint Site URL
    $siteUrl = "" 
    #Write your Login ID
    $loginname = "" 
    #Write the Name of the List
    $listname = "" 
    Set-Location $loc 
    Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
    Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll") 
    Write-Host "Please enter password for $($siteUrl):"
    $pwd = Read-Host -AsSecureString
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) 
    Try
    # Remove or replace line below to change authentication method
    $ctx.Credentials = New-Object System.Net.NetworkCredential($loginname, $pwd) 
    $web = $ctx.Web
    $ctx.Load($web)
    $ctx.ExecuteQuery() 
    #Write-Host "Current web title is '$($web.Title)', $($web.Url)"  
    $list = $Web.Lists.GetByTitle($listname); 
    $ctx.Load($list); 
    $ctx.ExecuteQuery(); 
    Write-Host "Deleting Permissions on List : $($list.Title)" 
    if($list.HasUniquePermissions)
                    #Write-Host "Has Unique Permissions"
                    $list.ResetRoleInheritance()
                    $list.BreakRoleInheritance($false, $true)
                    Write-Host "Permissions deleted" -foregroundcolor Green
    if(-not $list.HasUniquePermissions)
                    #Write-Host "Does not has Unique Permissions"
                    $list.ResetRoleInheritance()
                    $list.BreakRoleInheritance($false, $true)
                    Write-Host "Permissions deleted" -foregroundcolor Green
    Catch
                    Write-Host "Some Error, Please Contact Administrator" -foregroundcolor Red
                    return
    $list.Update() 
    $ctx.ExecuteQuery();​
    Regards,
    Sudheer
    Thanks & Regards, Sudheer

    Hi Sudheer,
    In Client-Side, we can also use .NET Client Object Model to achieve your requirement.
    Remove permission in Sharepoint List using Client Object Model
    https://rambabualaparthi.wordpress.com/2013/12/30/remove-permission-in-sharepoint-list-using-client-object-model/
    In order to better manage SharePoint in Client side, I suggest develop a Winform or WPF application and use .Net Client Object Model to achieve some requirements.
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to run 'Get-AssignedAccess' or 'Set-AssignedAccess' power shell commands in c# Application

    Hi,
    I have console application using which i am trying to run power shell command  like 'Get-AssignedAccess' or 'Set-AssignedAccess'.
    i am using below code for this it is throwing exception 'Get-AssignedAccess' doesn't exist in cmdlet which is correct because these commands belongs to function category.
    using (PowerShell pwInstance = PowerShell.Create())
                            pwInstance .AddScript("Get-AssignedAccess");
                            var result = pwInstance .Invoke();
    How can we execute this kind of command using c#?
    Thanks,

    Hi prakashlight,
    Thank you for comming back and tell us the result. For more information about how to run PowerShell script in C# language, you can refer to this blogpost here:
    Executing PowerShell scripts from C#
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to Execute Power Shell Command From Windows Application.

    Hi All Experts,
    I want to execute power shell commands from my windows application.
    Is it possible ?
    Please let me know your comments..
    Thanks.

    I have not tried this, but apprently it is easy as in the sample pasted below. please see this article for more details
    http://geekswithblogs.net/Norgean/archive/2012/09/19/running-powershell-from-within-sharepoint.aspx.
    Let me know how it goes...
    public string RunPowershell(string powershellText, SPWeb web, string param1, string param2) {
    // Powershell ~= RunspaceFactory - i.e. Create a powershell context
    var runspace = RunspaceFactory.CreateRunspace();
    var resultString = new StringBuilder();
    try
    // load the SharePoint snapin - Note: you cannot do this in the script itself (i.e. add-pssnapin etc does not work)
    PSSnapInException snapInError;
    runspace.RunspaceConfiguration.AddPSSnapIn("Microsoft.SharePoint.PowerShell", out snapInError);
    runspace.Open();
    // set a web variable.
    runspace.SessionStateProxy.SetVariable("webContext", web);
    // and some user defined parameters
    runspace.SessionStateProxy.SetVariable("param1", param1);
    runspace.SessionStateProxy.SetVariable("param2", param2);
    var pipeline = runspace.CreatePipeline();
    pipeline.Commands.AddScript(powershellText);
    // add a "return" variable
    pipeline.Commands.Add("Out-String");
    // execute!
    var results = pipeline.Invoke();
    // convert the script result into a single string
    foreach (PSObject obj in results)
    resultString.AppendLine(obj.ToString());
    finally
    // close the runspace
    runspace.Close();
    // consider logging the result. Or something.
    return resultString.ToString();
    Ok. We've written some code. Let us test it.
    var runner = new PowershellRunner();
    runner.RunPowershellScript(@"
    $web = Get-SPWeb 'http://server/web' # or $webContext
    $web.Title = $param1
    $web.Update()
    $web.Dispose()
    ", null, "New title", "not used");
    -Sangeetha

  • Any good Power Shell command or script to see connected users in real time for Lync 2013

    Are there any good Power Shell commands or scripts that can tell you how many users are connected to a pool in real time so you can evaluate the current load. I have 3 FE servers in a single pool. We just started deploying the lync client to the users and
    were curious as to how many are actually connected. I saw a number of home made scripts but really didn't care for any of them. I just want to find out how many users that are actually connected to the pool at a particular moment so we can see how many users
    are really using the product.

    Have you looked at Pat Richard's get-csconnections script?: http://www.ehloworld.com/269
    Please mark posts as answers/helpful if it answers your question.
    Blog
    Lync Validator - Used to assist in the validation and documentation of Lync Server 2013.

  • Power shell command not working in Power shell ISE

    I was looking for guidance on a problem I was having and found a post from
    Bigteddy on TechNet that had this command
    Get-ADUser -Identity sam -Properties memberof | select -ExpandProperty memberof
    I kept trying it many ways and it always fails in power shell ISE. 
    I get the below output
    The term 'Get-ADUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
    the name, or if a path was included, verify that the path is c
    orrect and try again.
    At line:1 char:11
    + Get-ADUser <<<< 
    -Identity rwhite -Properties memberof | select -ExpandProperty memberof
    + CategoryInfo         
    : ObjectNotFound: (Get-ADUser:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    I put the same command in the power shell module window and it works perfectly
    Any idea how I can make this work for striping purposes in power shell ise
    ronald white

    Import-Module ActiveDirectory
    If that returns an error, chances are that you do not have the module on your computer.  You can verify that by running
    Get-Module -ListAvailable
    Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP
    Engineering Efficiency
    @Rich_Prescott
    Windows System Administration tool 2.0
    AD User Creation tool

  • AAA with CatOS and ACS (shell command autorization set)

    Hi,
    I have an ACS that authenticates and authorizes IOS devices.
    I use "shell command autorization set" to authorize some commands for some groups.
    Is it possible to do so with CatOS?
    For example, I'd like that the groupe FULL can access all command and the group LOW can onmy access "sho" commands?
    Regards,
    ROMS

    Console> (enable) set tacacs server [IP] [primary]
    set tacacs key [key]
    set tacacs attempts [number] (optional)
    set localuser user [user] password [password] privilege 15
    set authentication login local enable
    set authentication login tacacs enable [all | console | http | telnet] [primary]
    set authorization exec enable tacacs+ [deny | none] [console | telnet | both]
    set authorization commands enable [config | all] tacacs+ [deny | none] [console |telnet | both]
    regards,
    ~JG

  • Power Shell command

    hi 
    I would like to help me with a command that will give me the clearance of each mailbox in Exchange 2013
    Thanks!

    Hi,
    Do you mean the security clearance of each mailbox in Exchange 2013?
    In Exchange 2013, we can use the EAC or the Shell to assign permissions to users or groups (called delegates) that allow them to open or send messages from other mailboxes. To perform this procedure, user need to be assigned a member of Organization Management
    role group.
    Refer to this article about Manage Permissions For Recipients.
    http://technet.microsoft.com/en-us/library/jj919240(v=exchg.150).aspx
    Best Regards.

  • What is the meaning of the status value in resulted table via power shell command?

    Hello,
    I have queries about result given by powershell command:
    Get-WmiObject -Class Win32_Processor results Status code as
    OK - What does it mean ? what are other status code options  ?
    Get-WmiObject -Class Win32_ComputerSystem results Status code as OK - What does it mean ? what are other status code options  ?
    [System.Net.WebRequest]::Create($site) > GetResponse() results StatusCode as OK - What does it mean ? whats are other status code options  ?
    Would you please clarify ?
    Thanks and Kind Regards,
    Dipti Chhatrapati

    Dipti...Check the msdn site for that particular class for all the info.
    The values will differ from class to class.
    http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx
    Status
    Data type: string
    Access type: Read-only
    Qualifiers: MaxLen (10)
    Current status of an object. This property is inherited from CIM_ManagedSystemElement.
    The values are:
    "OK"
    "Error"
    "Degraded"
    "Unknown"
    "Pred Fail"
    "Starting"
    "Stopping"
    "Service"
    "Stressed"
    "NonRecover"
    "NoContact"
    "LostComm"
    Thanks Azam When you see answers please Mark as Answer if Helpful..vote as helpful.

  • How to bring a prompt to User sitting on a laptop/desktop using Power shell command/script before machine gets rebooted.

    Hi Experts,
    I am a novice in Powershell and trying to learn PowerShell.
    Currently, i need to reboot some 50-60 desktops remotely.
    i am using the below powershell command
    gc c:\Temp\machineList.txt |%{Restart-computer -computername $_ -force}
    It is working perfect for me but what i want is before machine gets rebooted User should get a prompt like "Your machine will be rebooted in 60 seconds, Please save your work".
    How i can achieve this in a powershell script.
    Thanks in advance.
    Daya

    an other option is to start taskmanager on Domain Controller
    go to users right click user Object send message
    regards Thomas Paetzold visit my blog on: http://sus42.wordpress.com
    "taskmanager"?
    That only works for users logged into the dc. Users should not be allowed to log into the DC directly.
    I suspect you mean to use the MSG facility if it is not disabled.  MSG /?.  This can send messages to uses on various systems.
    ¯\_(ツ)_/¯

  • Problems with making javac a shell command

    I am running win98. I use the command line to compile my java applications except the javac command doesn't work outside of the bin directory.
    How can I setup my java tools to run at my command?
    so far I have tried
    PATH :\WINDOWS;C:\WINDOWS\COMMAND;C:\JDK1.3\BIN
    in my autoexec.bat.
    but, that doesn't work.

    The line in your autoexec.bat should read:
    SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\JDK1.3\BIN
    Note the missing part in bold.
    V.V.

  • Is there any power shell command available to get all information/settings from Config Database/Farm

    Hi,
    Basically we are rebuilidng a new farm which will be a replica of other environment. We have setup Sharepoint and migrated all contents.So everything looks same. Now the question is, what else info need to check from the current FARM whether it is 100% matched
    with new one.
    Is there any script I can run which will give me all information from SP FARM then I could have compared with new farm.
    Thanks  
    srabon

    Check the below script which provides common service application settings, AAM, Designer settings,Farm configuration and few more details..  you can run it in both farms and validate the outputs
    http://technet.microsoft.com/en-us/library/ff645391%28v=office.15%29.aspx
    Hope this helps.
    My Blog- http://www.sharepoint-journey.com|
    If a post answers your question, please click Mark As Answer on that post and Vote as Helpful

  • Intermittent "Power Shell Script failed to run" after installing SQL MP 6.5.4.0

    We recently installed the SQL MP.  One thing I am struggling with is this "Power Shell Script failed to run" that occasionally comes up, but, not always on the same server, and not always at the same time. 
    It says it ran past the configured timeout of 300 seconds. 
    The post that seemed to have me on the right track was
    https://social.technet.microsoft.com/Forums/en-US/c539a55d-dd48-438f-b7d5-06ed2cecf6e9/powershell-script-failed-to-run-alerts-from-sql-management-pack-6410?forum=operationsmanagergeneral
    However, even after getting one of the several scripts that have been generating the error, out of the extract management pack, it has parameters that need to be fed to it that I have no idea what they are....
    Example.  ActiveRequestsDataSource.ps1 requires $computername, $connectionstring, $tcpport, $sql_wmi_namespace, and $servicename. 
    The computername is easy enough...  so is tcpport.  but, the others... not so much. 
    I am fairly certain I will be able to run these manually, if I just knew the parameters...  I am also fairly certain we are getting these because at the time of the check, resources on that server are tied up for one reason or another. 
    Can someone please help?  This is killing me. 

    Hi,
    As this issue happens after you installing SQL MP, so from my point of view, it seems like caused by the runas account for the SQL MP is not configured well, I would like to suggest you follow the article below to configure runas account for the management
    pack:
    Configuring Run As Accounts and Profiles in OpsMgr – A SQL Management Pack Example
    http://blogs.technet.com/b/kevinholman/archive/2010/09/08/configuring-run-as-accounts-and-profiles-in-r2-a-sql-management-pack-example.aspx
    Regards,
    Yan Li
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

Maybe you are looking for

  • Memory(RAM) upgrade on a Mid-2012 MacBook Pro

    Hello Apple fans and users. My Mid-2012 MacBook Pro 13" is a bit slow. It has 2x2GB DDR3 1600MHz Ram and when I open more than 4-5 tabs in Safari it becomes really really slow. So that's what's bothering me and I have decided that I need to upgrade m

  • Is it possible to convert a Word document with embedded files?

    I am using Acrobat 8 Professional and have tried converting a word file, which contains embedded word, excel and pdf files within it.  The document converts but the embedded files are not accessible.  I have tried converting the document using print

  • Why is the rented movie from iTunes not playing?

    I have rented a movie from iTunes in my iPad, and it is not playing.  When I press on the movie title from the iPod > purchsed section, it gives me a black/blank screen for a second or two and then takes me back to the main desk-top screen.  Is there

  • Right margin ?  and JSrollBar question

    To keep my components from being too close to the edge on the left hand side of my app, i use: container.add(Box.createRigidArea(new Dimension(5,0))); My question is how i can acheive the same 5 pixel wide margin on the right handside of my container

  • Mailboxes migration to new partition

    Dear Folks, We had to migrate the mailboxes from one partition to another, (partition 1 got full). We mounted another disk from SAN (600 GB) the double the size of existing partition (300 GB). How ever after the migration (mailboxes migration from ol