Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts

2016/03/22

Add an NFS data store to every node in a VMware cluster

This will create the data store with the given name on each host in the given cluster attached to the given vCenter server:

Run the VMware vSphere PowerCLI
PowerCLI> connect-VIServer <vCenterServerName>
PowerCLI> Get-Cluster -Name <ClusterName> | Get-vmhost | foreach-object {
>> new-datastore -VMHost $_.Name -Name "<DataStoreName>" 
                -Path "<NfsExportPath>" -Nfs -NfsHost "<NfsServerFQDN>"
>> }

2009/12/22

Exchange PowerShell tips

Add Full Mailbox permissions to all mailboxes in the exchange organization:
# Matt’s Powershell Script (see tigermatt.wordpress.com) to add Full Mailbox permissions to all mailboxes in the Exchange organization
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
$userAccounts = get-mailbox -resultsize unlimited
ForEach ($user in $userAccounts)
{
add-MailboxPermission -identity $user -user “your-admin-account-name” -AccessRights FullAccess
}


Delete all messages in specific users' mailboxes with a specific title:
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
#$userAccounts = get-mailbox -resultsize unlimited
ForEach ($user in "John Doe", "Jane Doe", "Humpty Dumpty")
{
get-Mailbox -Identity $user | Export-Mailbox -SubjectKeywords "This is the message subject" –DeleteContent –MaxThreads 10
}


Delete all messages in an Exchange organization with a specific title:
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
$userAccounts = get-mailbox -resultsize unlimited
ForEach ($user in $userAccounts)
{
Export-Mailbox -Identity $user-SubjectKeywords "This is the message subject" –DeleteContent –MaxThreads 10
}

2009/11/21

PowerShell examples

ping an ip address range and report which hosts are down:
PS H:\> for ( $i=200; $i -lt 255; $i++ ) { ping -n 1 -a -w 1000 192.168.0.$i > $null; if (!$?) { echo "192.168.0.$i is
down" }; }

Send an email with attachments (like logs), quick and dirty:
send-mailmessage -to me@foo.com -Subject "see attachment" -from myhost@foo.com -attachments "C:\bar.log" -smtpserver mail.foo.com