#Powershell and Send-MailMessage cmdlet

#Exchange2010 – Found this and it’s damm handy and what’s cool is that its a Windows Powershell v2 thing and you don’t need Exchange :-|


Source: http://www.howexchangeworks.com/2009/11/send-emails-easily-using-powershell-v2.html 

-and-

Source: http://technet.microsoft.com/en-us/library/dd347693.aspx

The Send-MailMessage cmdlet sends an e-mail message from within Windows PowerShell.

Send-MailMessage –From Rajith@chakka.local –To Deepak@chakka.local –Subject “Test Email” –Body “Testing the cmdlet” –SmtpServer exch07.chakka.local

Powershell Cmdlets for SCOM 2007 R2 (beta)

PsSnapin is called: Microsoft.EnterpriseManagement.OperationsManager.Client

get-help * | where {$_.pssnapin -like “*Enter*”} | sort name | select name,synopsis | ft –auto

Name

Synopis

Add-ConnectorToTier

Configures an Operations Manager Connector Framework connector for a specified tier.

Add-RemotelyManagedComputer

Adds a remotely-managed computer to an agent.

Add-RemotelyManagedDevice

Adds a remotely managed device to an agent.

Add-UserToUserRole

Adds the specified user to an Operations Manager role.

Approve-AgentPendingAction

Approves the specified agent pending action.

Disable-NotificationSubscription

Disables a notification subscription.

Disable-Rule

Disables a rule.

Enable-NotificationSubscription

Enables a notification subscription.

Enable-Rule

Enables a rule.

Export-ManagementPack

Exports a management pack to a file.

Get-Agent

Gets the agents associated with the specified management server.

Get-AgentPendingAction

Gets agent-pending actions.

Get-Alert

Gets the specified alerts.

Get-AlertDestinatin

Gets the connector to which the alert is forwarded.

Get-AlertHistory

Get the history for the specified alerts.

Get-Connector

Get the connectors for a management group.

Get-DefaultSetting

Gets the default settings for a management group.

Get-Diagnostic

Returns the available diagnostics.

Get-Discovery

Returns available discoveries.

Get-Event

Gets events.

Get-FailoverManagementServer

Returns the failover management servers.

Get-GatewayManagementServer

Returns the gateway management servers.

Get-MaintenanceWindow

Gets maintenance window information.

Get-ManagementGroupConnection

Gets all open Management Group connections.

Get-ManagementPack

Gets imported management packs

Get-ManagementServer

Gets management servers.

Get-Monitor

Gets management pack monitors.

Get-MonitorHierarchy

Retrieves the hierarchy of monitors for a particular monitoring object.

Get-MonitoringClass

Gets monitoring classes.

Get-MonitoringClassProperty

Gets the properties of a specified monitoring class.

Get-MonitoringObject

Gets monitoring objects.

Get-MonitoringObjectGroup

Returns the list of monitoring object groups.

Get-MonitoringObjectPath

Gets path to a monitoring object.

Get-MonitoringObjectProperty

Gets properties and associated values of monitoring objects.

Get-NotificationAction

Gets notification actions.

Get-NotificationEndpoint

Gets notification end points.

Get-NotificationRecipient

Gets notification recipients.

Get-NotificationSubscription

Gets notification subscriptions.

Get-OperationsManagerCommand

Returns all cmdlets that are provided by Operations Manager.

Get-Override

Gets management pack overrides.

Get-PerformanceCounter

Gets performance counters.

Get-PerformanceCounterValue

Gets data associated with a specified performance counter.

Get-PrimaryManagementServer

Returns the primary management server.

Get-Recovery

Returns available recovery objects.

Get-RelationshipClass

Gets monito
ring relationship classes.

Get-RelationshipObject

Gets monitoring relationship objects.

Get-RemotelyManagedComputer

Gets remotely managed computers.

Get-RemotelyManagedDevice

Gets remotely managed devices.

Get-ResultantCategoryOverride

Gets resultant category overrides.

Get-ResultantRuleOverride

Gets resultant rule overrides.

Get-ResultantUnitMonitorOverride

Gets resultant monitor overrides.

Get-RootManagementServer

Returns the root management server.

Get-Rule

Gets monitoring rules.

Get-RunAsAccount

Gets run as accounts.

Get-State

Gets monitoring state for specified monitoring objects.

Get-Task

Gets monitoring tasks.

Get-TaskResult

Gets monitoring task results.

Get-Tier

Gets tiered management groups.

Get-UserRole

Gets user roles.

Install-Agent

Installs agents.

Install-AgentByName

Installs an Operations Manager agent on the specified computer.

Install-ManagementPack

Installs a management pack.

New-CustomMonitoringObject

Creates a custom monitoring object.

New-DeviceDiscoveryConfiguration

Creates an object that represents settings to use to discover devices.

New-LdapQueryDiscoveryCriteria

Creates a new LdapQueryDiscoveryCriteria object used to discover computers.

New-MaintenanceWindow

Puts the specified monitoring object into maintenance mode.

New-ManagementGroupConnection

Creates a new connection to a management group or tiered management group.

New-MonitoringPropertyValuePair

Creates a new monitoring property-value pair object.

New-Tier

Creates a new tier connection.

New-WindowsDiscoveryConfiguration

Creates an object that describes computers to discover.

Reject-AgentPendingAction

Rejects the specified agent pending action.

Remove-ConnectorFromTier

Removes an Operations Manager Connector Framework connector from a specified tier.

Remove-DisabledMonitoringObject

Removes all monitoring objects for which discovery is disabled.

Remove-ManagementGroupConnection

Removes a connection to a management group.

Remove-RemotelyManagedComputer

Removes a remotely managed computer from an agent.

Remove-RemotelyManagedDevice

Removes a remotely managed device from an agent.

Remove-Tier

Removes a tier.

Resolve-Alert

Resolves an alert.

Set-AlertDestination

Sets the Operations Manager Connector Framework connector  to which the specified alert will be forwarded.

Set-DefaultSetting

Sets default settings.

Set-MaintenanceWindow

Sets properties of a maintenance window.

Set-ManagementServer

Sets the management server of an agent.

Set-ProxyAgent

Sets the proxy agent for a remotely managed computer or device.

Start-Discovery

Starts a discovery task for discovering devices or computers.

Start-Task

Starts a task.

Uninstall-Agent

Uninstalls the Operations Manager agent from managed computers.

Uninstall-ManagementPack

Uninstalls a management pack.

Export non expiry password accounts

I’m doing requests now ;-)

This script will dump a list of user accounts that have “Password never expires” checked

$CurrentDomain = [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain()
$Forest = $CurrentDomain.Forest.ToString()
$Forest = “dc=” + $Forest
$Forest = $Forest.Replace(“.”,”,dc=”)
$Root     = New-Object DirectoryServices.DirectoryEntry $Dom
$selector = New-Object DirectoryServices.DirectorySearcher
$selector.PageSize = 1000
$selector.SearchRoot = $root
$selector.Filter= “(&(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=65536))”
$objs= $selector.findall()
$objs

 

Setting Exchange mailbox size limits on a group

WHAT! I hear you say, you can’t do that! .. Very true, but you can automate it ;-) using the wonders of Powershell

Exchange 200x

First you will need to use adsiedit.msc and get the groups distinguishedName.  Once you have that, using an account that has access to over the users AD objects you run this code:
$mygroup = “
$grp = [adsi](“
LDAP://$mygroup“)

Now type:
$grp | FL *
This will list out properties of the group ** just to make sure its’ the right one **

What you can do here is type:
$grp.member
This will list the group membership.

Now choose a quota size in KB
$QuotaSize = 5242880

Then if you happy, run this code to set the quota size
forEach($xMem in $Grp.Member){Write-Host $xMem;$user = [adsi](“LDAP://$xMem“); $user.mDBUseDefaults = $False; $user.mDBStorageQuota = $QuotaSize; $user.setinfo()}
 

Exchange 2007

Exchange 2007 is a lot easier. 

Now choose a quota size in KB
$QuotaSize = 5242880

$Grp = get-group ; forEach($xMem in $Grp.Members){Write-Host $xMem; set-mailbox $xMem -IssueWarningQuota $QuotaSize}

Exchange 2007 / Outlook 2003 / Blackberry & OoO

I saw Andy posted this (http://telnetport25.wordpress.com/2008/03/16/quick-ish-tip-exchange-2007-setting-oof-for-users-via-powershell-2/) today and wanted to share my script.

It uses the same dll from Glen(EWSOofUtil.dll) to open the specified users mailbox and Enable/Disable a users Out Off Office Setting. This in theory fixes an Issue with Exchange 2007 and Outlook 2003/Blackberry Enterprise Server

The script also checks to see if a user has a legacy account set as Associated External. If it has it removes it and writes to a log.  It does this as the “Super Account” I was using could open the OoO if this was set!

EWSOofUtil.dll is provided by Glen Scales (http://gsexdev.blogspot.com)

The script can also be used in a pipeline.

##########################################################################################
Param ($Username)
##########################################################################################
$AppName = “Fix-OoO.ps1”
$AppVer  = “v1.1 [6 March 2008]”
#
#v1.0 2 March 2008     : A script it born
#v1.1 6 March 2008     : Updated to remove legacy account and added more logging
#
# This script uses EWSOofUtil.dll to open the specified users mailbox and Enable/Disable
# a users Out Off Office Setting.  This in theory fixes an Issue with Exchange 2007
# and Outlook 2003/Blackberry Enterprise Server
#
# The script also checks to see if a user has a legacy account set as Associated External
# If it has it removes it and writes to a log
#
#Written By Paul Flaherty                  
#blogs.flaphead.com                        
#
#Syntax
#Fix-OoO.ps1
#
#Can be in the pipeline
#get-mailbox -database M03VASG03-M03VASG03-DB01-M03VA  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#
#Other samples
#
#$Server = “M01VA”
#get-mailbox -database $ServerSG01-$ServerSG01-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG02-$ServerSG02-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG03-$ServerSG03-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG04-$ServerSG04-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG05-$ServerSG05-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG06-$ServerSG06-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG07-$ServerSG07-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#get-mailbox -database $ServerSG08-$ServerSG08-DB01-$Server  -resultsize unlimited | where {$_.islinked -eq $False} | foreach-object {c:psFix-OoO.ps1 $_.Name}
#
##########################################################################################

IF ($Username -eq $Null)
{
    Write-Host “Enter UserName: ” -NoNewLine
    $Username = Read-Host
}

IF ($username -ne $null)
{
    #Check Permissions
    $xPerms = get-mailboxPermission -Identity $Username -user corebus1$Username
    ForEach ($xPerm in $xPerms)
    {
        $xAccess = $xPerm.AccessRights | Out-String
        $xAccess = $xAccess.Trim()
        If ($xAccess.Contains(“ExternalAccount”))
        {
            write-host $xPerm.User -NoNewLine -foregroundcolor Yellow
            write-host ” : ” -NoNewLine
            write-host $xPerm.AccessRights

            Add-content c:tempOoO-Fail-AccessRights.txt “$UserName,corebus1$Username,$xAccess “
            Remove-MailboxPermission -Identity $Username -user $xPerm.User -AccessRight ExternalAccount -Confirm:$False

        }
    }

    $Username += “@flaphead.local”
    Write-host $Username -foregroundcolor Green
    $MsxServer =
https://cas01.flaphead.local/EWS/Exchange.asmx

    [Reflection.Assembly]::LoadFile(“c:psEWSOofUtil.dll”)
    $oofutil = new-object EWSOofUtil.OofUtil
    $oofutil.getoof($Username ,””,””,””,$MsxServer)

    $xOoOInternal = $oofutil.InternalMessage
    $xOoOExternal = $oofutil.ExternalMessage

    $xOoOStatus = $oofutil.OofStatus

    IF ($xOoOStatus.Length -eq 0) {Add-content c:tempOoO-Fail.txt $UserName}

    IF ($xOoOStatus.Length -gt 0)
    {

        Write-Host “OoO Status: $xOoOStatus”
        Add-content c:tempOoO-Success.txt “$UserName,$xOoOStatus”

        If ($xOoOStatus -eq “Enabled”)
        {
            Write-Host $xOoOInternal
            $oofutil.setoof($Username ,”Disabled”,””,””,””,””,””,$MsxServer)
            $oofutil.setoof($Username ,”Enabled”,””,””,””,””,””,$MsxServer)
        }
        ELSE
        {
            $oofutil.setoof($Username ,”Enabled”,””,””,””,””,””,$MsxServer)
            $oofutil.setoof($Username ,”Disabled”,””,””,””,””,””,$MsxServer)
        }
    }
}
 &nb
sp;  ELSE
{
    Write-Host “No Username specified”
}

##########################################################################################
#End
##########################################################################################

.. omatic

Been surfing today and found a whole load of Microsoft .. omatic utilities

Tweakomatic
The Tweakomatic is a nifty new utility that writes scripts that allow you to retrieve and/or configure Windows and Internet Explorer settings. So what, you might ask. Well, think about it. Because these are WMI scripts, they can be used to configure settings on remote computers. Need to change something on a remote machine? Then haul out the Tweakomatic. And think about this: because the Tweakomatic writes scripts, you could do something like run these scripts as logon or logoff scripts. In other words, you could quickly, easily, and automatically configure settings on any or all the computers in your organization. http://www.microsoft.com/downloads/details.aspx?familyid=bd328d1e-6c01-4447-bd7c-c09646d722c8&displaylang=en

ADSI Scriptomatic
The ADSI Scriptomatic is designed to help you write ADSI scripts; that is, scripts that can be used to manage Active Directory. The ADSI Scriptomatic also teaches you an important point about ADSI scripting: like WMI, there are consistent patterns to ADSI scripts. http://www.microsoft.com/downloads/details.aspx?FamilyID=39044e17-2490-487d-9a92-ce5dcd311228&DisplayLang=en

HTA Helpomatic
The HTA Helpomatic is a utility that helps script writers create HTML Applications (HTAs). HTAs enable you to provide a graphical user interface for your scripts, an interface that can include anything from list boxes to radio buttons to checkboxes. The HTA Helpomatic includes sample VBScript code and sample HTML code showing you how to do things like add a button to an HTA. Equally important, the Helpomatic also shows you how you can run a script any time that button is clicked. As an added bonus, the Helpomatic enables you to modify the scripts and HTML code and test those modifications in the utility itself. http://www.microsoft.com/downloads/details.aspx?FamilyId=231D8143-F21B-4707-B583-AE7B9152E6D9&displaylang=en

Scriptomatic 2.0
A completely new version of the famous Scriptomatic, the utility that writes WMI scripts for you. (And, in the process, teaches you the fundamental concepts behind writing WMI scripts for yourself.) Unlike its predecessor, Scriptomatic 2.0 isn’t limited to writing just VBScript scripts; instead, Scriptomatic 2.0 can write scripts in Perl, Python, or JScript as well. In addition, Scriptomatic 2.0 gives you a host of new output formats to use when running scripts, including saving data as plain-text, as a stand-alone Web page, or even as XML. Scriptomatic 2.0 handles arrays, it converts dates to a more readable format, and it works with all the WMI classes on your computer; on top of all that, it also writes scripts that can be run against multiple machines. http://www.microsoft.com/downloads/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&DisplayLang=en