Showing posts with label Scripting. Show all posts
Showing posts with label Scripting. Show all posts

Monday, February 16, 2015

Basic Exchange Management PowerShell Scripts

This page describes and lists various Exchange Mgmt Shell Scripts and how to use them. 

Document Creator 
Todd Walters    7/16/2010 


Requirements 
  • Exchange Management Shell -   
  • Windows PowerShell - Scripting tool from Microsoft. 
  • To add mailbox permissions for yourself use run-as to launch Exchange Mgmt Shell using the  someserviceacct  service account and enter this: 
  • Add-mailboxpermission -identity <user> -accessrights fullaccess -user <yourname> 
  1. note - Must Add Exchange Mgmt Shell SnapIn to PowerShell to Run Scripts on PowerShell 
  1. run this in PowerSherll: add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
  1. Microsoft.Exchange.Management.PowerShell.E2010
  1. Microsoft.Exchange.Management.PowerShell.Support

  1.  
  1. How to list mailbox user 
  1. GET-Mailbox –identity twalters  
  1. How to get mailbox statisics of user 
  1. Get-MailboxStatistics -identity twalters 
  1. set-MailboxStatistics - identity twalters | select DisplayName, TotalItemSize, TotalDeletedItemsize, DatabaseName | format-table 
  1. Get Mailbox Stats of Mailbox Server 
  1. get-mailboxstatistics -server SomeMailServer | Sort-Object TotalItemSize –Descending | ft DisplayName,TotalItemSize,ItemCount
  1.  
  1. How to Increase a mailbox storage size from defaults. Use the set-mailbox cmdlet. This increases and sets the warning, prohibit send, and prohibit send and receive limits to 750mb, 800mb, and 900mb respectively and the defaults are ignored. 
  1. set-mailbox -identity username -IssueWarningQuota 786432000 -ProhibitSendQuota 838860800 -ProhibitSendReceiveQuota  943718400 -UseDatabaseQuotaDefaults $false
  1. or 
  1. Set-Mailbox testmbx -UseDatabaseQuotaDefaults:$False -IssueWarningQuota 750MB -ProhibitSendQuota 800MB -ProhibitSendReceiveQuota 900MB

  1.  
  1. Set Mailbox to Default Limits 
  1. set-mailbox -identity username -UseDatabaseQuotaDefaults $true 
  1. Get-Queue -Filter {status -eq "retry"} 

  1. How to list all distribution groups in OU 
  1. get-distributiongroup -OrganizationalUnit "mydomain/My DL GROUPs"
  1.  
  1. How to list members of a Distribution Group 
  1. Get-DistributionGroupMember –identity “distro - some distrogroup" (replace " " w/any DG)  add | ft name, primarysmtpaddress | Export-CSV c:\members.csv to export to CSV 
  1. How to list a User’s Distribution Group Membership 
  1. How to Remove a Distribution Group 
  1. Remove-DistributionGroup -Identity "DG Name"
  1.  
  1. How to Remove a User from a Distribution Group 
  1. Remove-DistributionGroupMember -Identity "DG Name" -Member user@Mydomain.com 
  1. How to add permission to Manage a Distribution Group 
  1. Set-DistributionList DLName -ManagedBy user1@domain.com,user2@domain.com 
  1. get-content Distros.txt | foreach-object { set-group -id $_ -managedBy user1@mydom.comuser2@mydom.com } 
  1. Add-ADPermission -Identity distro -User username -AccessRights WriteProperty -Properties "Member"
  1.  
  1. How to export mailbox for archiving (use z1.ps1 from NetAdmin Script Repo
  1. $username = Read-Host "Enter Username"
  1. $servername = Read-Host "Enter the Servername for User's H: drive"
  1. $pathname = "\\" + $servername + "\" + $username + "$\data\other"
  1. Export-Mailbox -Identity $username -PSTFolderPath $pathname -Confirm:$false 
  • $addy = (get-mailbox twalters).PrimarySMTPAddress.toString() ; write-host $addy 
  • get-distributiongroup "Distro Name" | select ManagedBy 
  • dsquery group -samid mySrv0citrix_users | dsget group -members  
  User1
dsget succeeded
 






  samid
permissions 
Mailbox Storage and Statistics

Mailbox Queue 


Mailbox Distribution Lists

Various 

list primary smtp address 

See Managed By for Distro     
 
  
dsquery Group 
How to List Member of said group or dl. 
[PS] H:\>dsget group  -members "CN=XX,OU=YY,DC=12,DC=com" | dsget user -samid


This command allows other command to access the mailbox in all the child domains: 
Set-ADServerSettings -ViewEntireForest:$true 


Mailbox migration commands that will migrate any mailbox in any domain that is listed in the Alias column of a .CSV file but Suspend the move until you are ready to start: 
Set-ADServerSettings -ViewEntireForest:$true 
import-csv C:\TempUserMoves1.csv | foreach {New-MoveRequest -Identity $_.Alias -BadItemLimit 10 -suspend } | find multiple 

Mailbox migration commands that will migrate any mailbox in any domain thats listed in the Alias column of a .CSV file but Suspend the move at the end of the migration. Only works on Exchange 2010 to 2010: 
Set-ADServerSettings -ViewEntireForest:$true 
import-csv C:\Temp\UserMoves1.csv | foreach {New-MoveRequest -Identity $_.Alias -BadItemLimit 10 -SuspendWhenReadyToComplete} | find multiple 

Resume suspended move request: 
import-csv C:\Temp\UserMoves1.csv | foreach {Resume-MoveRequest -Identity $_.Alias -Confirm:$False} | find multiple 

To exclude mailbox database from provisioning , launch EMS and type: 
Set-MailboxDatabase -Identity  ussd-mbdb01 -IsExcludedFromProvisioning $true 

To re-enable the mailbox database for provisioning, launch EMS and type: 
Set-MailboxDatabase -Identity  ussd-mbdb01 -IsExcludedFromProvisioning $false 

A script that move all public folder content from one server to another server: 
cd 'C:\Program Files\Microsoft\Exchange Server\v14\Scripts' 
.\MoveAllReplicas.ps1 -Server ussd-prd-esmb01 -NewServer ussd-prd-esmb03 

The location were the Exchange 2010 Scrip's are Stored: 
cd 'C:\Program Files\Microsoft\Exchange Server\v14\Scripts' 

These are the commands I used to set the attributes on the conference  after they were migrated to Exchange 2010: 
import-csv C:\temp\roomlist.csv | foreach {Set-Mailbox -Identity $_.Alias -Type Room} 
import-csv C:\temp\roomlist.csv | foreach {Set-CalendarProcessing -Identity $_.Alias -AutomateProcessing AutoAccept -BookingWindowInDays 270} 

A command will export a mailbox to a PST file on a file share: (In order for these commands to work the [Exchange Servers] group must have full access to the folder you are righting to) 
Set-ADServerSettings -ViewEntireForest:$true 
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
New-MailboxExportRequest -Mailbox Alias -FilePath "\\server1\folder\filename.pst

This command is used when create conference room to the Calendar reviewer for everyone using the Alias column of a .CSV file. Most push Enter twice for command to run: 
import-csv C:\Temp\ConfRoom.csv | foreach { $room =  $_.Alias + ':\calendar'  
                              Set-MailboxFolderPermission -Identity $room -AccessRights Reviewer -User "Default" } 

This command creates Room List DLs: 
New-DistributionGroup “Room Name” –RoomList –Members “Conference You would like to added to the DL” 

This command is used to check the health of the Content Index on the DBs. It must be ran from the mailbox server: 
Get-MailboxDatabaseCopyStatus | fl name, contentindexstate 

This command forces DAG fail over ofdatabase when it is Crawling: 
Move-ActiveMailboxDatabase USSD-MBDB08 -SkipClientExperienceChecks  

List Mailboxes by Size on a Database: 
Get-MailboxDatabase ussd-mbdb02 | Get-MailboxStatistics | Sort totalitemsize -desc | ft displayname, totalitemsize, itemcount 

Removes the Hidden from Address book using the Alias filed in a .CSV: 
import-csv C:\Temp\GoLive.csv | foreach {Set-Mailbox -Identity $_.Alias -HiddenFromAddressListsEnabled $false} | find multiple 

Set the Accept Messages to all if a DL is set to be the only group to have rights to send to a user based on the Alias filed in a .CSV: 
import-csv C:\Temp\GoLive2.csv | foreach {Set-Mailbox -Identity $_.Alias -AcceptMessagesOnlyFromDLMembers $NULL} | find multiple 

When creating a new Public Database you will need to include it has a replicate. This scrip will add a new Public Database as a replicate based on the server name to all of the public folders.  This command needs to be ran from a server that already contains a Public Database: 
cd 'C:\Program Files\Microsoft\Exchange Server\v14\Scripts' 
.\AddReplicaToPFRecursive.ps1 -TopPublicFolder "\" -ServerToAdd servername 
.\AddReplicaToPFRecursive.ps1 -TopPublicFolder "\NON_IPM_SUBTREE" -ServerToAdd servername 

Give the members of a DL Send on Behalf of right of the DL. You must have manager permissions to the group for this command to work and the group must be both a DL and a security group. 
Set-DistributionGroup -Identity "DL-Finance_Revenue" -GrantSendOnBehalfTo "DL-Finance_Revenue" 

This command shows you the size of a Database and how much free space is available in it. 
Get-MailboxDatabase "MailBoxServerName" -Status | Select-Object Server,Name,AvailableNewMailboxSpace,databasesize 

Exchange Mgmt Shell Links 



Thursday, January 30, 2014

Satellite Post Install Configuration

This document will explain how to activate Satellite and then how to configure the first Channel. 
Reference 
  • Chapter 6 in Red_Hat_Network_Satellite/5.4 Installation Guide 
  
How to Register Satellite & Download & Import Channel Content ISO’s. 
  1. Verify Activation in RHN (optional if using spacewalk) 
  2. Check for spacewalk-backend-tools package 
    1. # rpm –qa | grep backend   
  3. To see list of rhn commands run # rhn-
     
  4. To view channels available run 
    1. tmp]# satellite-sync -l | tee channels 
    2. # satellite-sync --list-channels | more   
  5. Run the following to reregister system and entitle/activate Satellite 
    1. [root@satserv rhn]# rhn_register 
    2. [root@satserv rhn]# rhn-satellite-activate --rhn-cert=/root/myco.cert
       
  6. Download Satellite Channel Content ISO’s for each channel you will need. 
    1. Red Hat recommends using Channel Content ISO’s locally versus importing directly from RHN website to save time. 
    2. Our example, we only user v6.3 RHEL 
    3. The process to copy Channel Content ISOs is to mount each one, copy its contents to the temporary repository, and then unmount the ISO. 
    4. Mount from your laptop to vmware to satellite server
       
  7. [root@satserv mnt]# mkdir /var/satellite/sat-import
     
  8. Mount the iso to local in vCenter and then copy from mount point to sat-import 
    1. [root@satserv media]# mount /dev/cdrom /media   
    2. [root@satserv media]# cp -ruv  * /mnt /var/satellite/sat-import/
       
    3. Repeat these steps for each Channel Content ISO of every channel to be imported.   
  9. The first step in importing channels into the database is listing the channels available for import. This is accomplished with the command:  
    1. satellite-sync --list-channels --mount-point /var/satellite/sat-import
    2. notes –  
      1. run ‘satellite-sync  --list-channels’ option to obtain a list of all channels by label.
  10. View local channels available 
    1. [root@satserv sat-import]# satellite-sync --list-channels --mount-point /var/satellite/sat-import/  
  11. Start the import of a channel 
    1. [root@satserv sat-import]# satellite-sync  -c rhel-x86_64-server-6 --mount-point /var/satellite/sat-import/  
    2. ..output..  13:20:07 Red Hat Network Satellite - file-system synchronization 
13:20:07    mp:  /var/satellite/sat-import 
13:20:07    dbrhnsat/<password>@rhnsat 
 13:20:08 Retrieving / parsing additional arches data 
13:20:08 additional arches data complete 
13:20:08 
13:20:08 Retrieving / parsing channel data 
13:20:09    p = previously imported/synced channel 
13:20:09    . = channel not yet imported/synced 
13:20:09    base-channels: 
13:20:09       . rhel-x86_64-server-6                     8203       full import from Mon Jun 25 12:52:55 2012 
13:20:09 
13:20:10 Channel data complete 
13:20:10 
13:20:10 Retrieving / parsing blacklists data 
13:20:10 blacklists data complete 
13:20:10 
13:20:10 Retrieving / parsing product names data 
13:20:10 
13:20:10 Retrieving short package metadata (used for indexing) 
13:20:10    Retrieving / parsing short package metadata: rhel-x86_64-server-6 (8203) 
13:20:43 Diffing package metadata (what's missing locally?): rhel-x86_64-server-6 
            ________________________________________ 
Diffing:    ######################################## - complete 
13:20:57 
13:20:57 Downloading package metadata 
13:20:57    Retrieving / parsing *relevant* package metadata: rhel-x86_64-server-6 (8203) 
13:20:57    * WARNING: this may be a slow process. 
            ________________________________________ 
Downloading:################################   ---output truncated---       8203/8203 Fetch successful: freeradius-2.1.12-3.el6.x86_64.rpm (1458248 bytes) 
13:38:36 Processing rpm packages complete 
13:38:36 
13:38:36 Importing package metadata 
13:38:36    Importing *relevant* package metadata: rhel-x86_64-server-6 (8203) 
13:38:36    * WARNING: this may be a slow process. 
            ________________________________________ 
Importing:  #   ---output truncated---   
This conducts the following tasks in this order:  
  1. Populating the tables describing common features for channels ( channel families). This can also be accomplished individually by passing the --step=channel-families option to satellite-sync.  
  2. Creating a particular channel in the database and importing the metadata describing the channel. Individually, use the --step=channels option.  
  3. Moving the RPM packages from the temporary repository into their final location. Individually, use the --step=rpms option.  
  4. Parsing the header metadata for each package in the channel, uploading the package data, and associating it with the channel. Individually, use the --step=packages option.  
  5. Identifying Errata associated with the packages and including them in the repository. Individually, use the --step=errata option.     
  6. See Chapter 7 Troubleshooting for help  Download RHN tools (or any channel from –list-channels) 
    • satellite-sync --channel=rhn-tools-rhel-x86_64-server-6 
this process worked and resolved my kickstart profile issue  
Set up a cron job in /etc/cron.daily to sync from Red Hat Network
  • Create satsync file 
    • #!/bin/bash  if { -e /var/lock/satsync ]; then          echo "Satellite sync in progress, exiting"          exit 1  fi   touch /var/lock/satsync  until satellite-sync; do          perl -le 'sleep rand 90' done  rm -f /var/lock/satsync   
  • cron.daily]# ll | grep satsync  -rwxr-xr-x. 1 root root  209 Aug 15 15:09 satsync 
 Define your Organization 
  1. Go to Admin > Organization  ( or create new organization) 
  2. Fill out appropriate information 
  3. Once created, you need to assign system entitlements 
    for:  
    • Management (Needed to register with Satellite file management, etc.)  
    •  Monitoring (Needed for Monitoring) 
    • Provisioning (Needed for bare metal installation, config  
    •  Virtualization (Needed for any machine doing virtualization which is not unlimited) 
    • Virtualization Platform (Needed for any machine with unlimited virtualization) 
Configuration File Management 
  1. Go to Configuration  Create New Config Channel    
  2. Fill in Name, Label, & Description, then click create 
    1. Click Add Files 
    2. Click Create File 
    3.  Create the file 
Create ‘Company default’ Config Channel  #This is the Myco Config File  # It uses variables and will be customized on   # per host basis.  
MY_SYSTEMID={|rhn.system.sid|} MY_PROFILE_NAME={|rhn.system.profile_name|} MY_SYSTEM_DESCRIPTION={|rhn.system.description|} MY_HOSTNAME={|rhn.system.hostname|} MY_SYSTEM_IP={|rhn.system.ip_address|} MY_ETH0_IP={|rhn.system.net_interface.ip_address(eth0)|} MY_ETH0_NETMASK={|rhn.system.net_interface.netmask(eth0)|} MY_ETH0_BCAST={|rhn.system.net_interface.broadcast(eth0)|} MY_ETH0_MAC={|rhn.system.net_interface.hardware_address(eth0)|} MY_ETH0_DRIVER={|  rhn.system.net_interface.driver_module(eth0)|}   
 Create System Groups   
  • We’ll create 3 System Groups based on Environment (Dev, Stg, Prod) 
  • Create 3 system groups on role (app, db, web) 
    • note: Determine additional groups as needed   
  1. Go to Systems > System groups > Create New Group 
  2. Enter group name and description   
Clone a Channel 
  • This is good idea for creating dev, stg, prod channels and keeping track of software at each channel. 
  • Currently only cloned RHEL Server 6 Channel and to Dev-Rhel Server 6 
    • Fill in Description & maintainer information then Update Channel   
  • Clone all Child Channels as well 
  • Repeat for other channels as needed. 
  
Create a Custom Channel (for PostgreSQL )  
  1. Go to Channels                 > Manage Software Channels > Create New Channel 
  2. Enter the following information  
    1. Basic Channel Details 
      1. Channel Name 
      2. Channel Label 
      3. Select Parent Channel 
      4. Select Parent Channel Arch [x86_64] 
      5. Channel Summary            
    2. Channel Maintainer / Contact 
      1. Maintainer Name 
      2. Maintainer Contact info 
      3. Support Policy (if any) 
    3. Channel Access Control 
      1. Per-User Subs 
      2. Organization Sharing 
    4. Security GPG Key 
      1. If you have GPG enter it here 
  3. Then click Create Channel 
  4. Create Custom Repository (if available, otherwise push packages in via rhnpush) 
    1. Locate the YUM Repo URL  
    2. Click on Manage Repositories > Create New Repository 
    3. Enter the Repo – label and URL and then click  Create Repository    
  5. Go to Software Channels  > Select your Channel >  Repositories 
  6. Select the new Repo then click on Update List > Update Repositories 
  7. There are 3 methods to Sync 
    1. Method 1: Go to Repos > Sync  and verify the Repo is there, then click Sync Now 
    2. Method 2 = command line, skip to next step 8 
    3. Method 3 – To only sync select packages to Repo, Skip to Step 10.  
  8. Use spacewalk-repo-sync to sync packages from thirdparty (postgresql ) Repo 
    1. ]# spacewalk-repo-sync --channel postgresql-9.1 
  9. To push single packages Use rhnpush to move to satellite all PostgreSQL server packages. 
    1. tmtw1]# rhnpush postgresql91-9.1.4-3PGDG.rhel6.x86_64.rpm postgresql91-contrib-9.1.4-3PGDG.rhel6.x86_64.rpm postgresql91-libs-9.1.4-3PGDG.rhel6.x86_64.rpm --server=https://satserv.mycoinc.com/APP -u satadm -p satellite -c postgresql-9.1  note: install GPG key                  [root@satserv /]# rpm -ivh pgdg-redhat91-9.1-5.noarch.rpm  Preparing...                ########################################### [100%]     1:pgdg-redhat91          ########################################### [100%]  [root@satserv /]# cd /etc/pki/rpm-gpg/  [root@satserv rpm-gpg]# ls  RPM-GPG-KEY-PGDG-91      RPM-GPG-KEY-redhat-legacy-former   RPM-GPG-KEY-redhat-legacy-rhx  RPM-GPG-KEY-redhat-beta  RPM-GPG-KEY-redhat-legacy-release  RPM-GPG-KEY-redhat-release  [root@satserv rpm-gpg]# rpm --import RPM-GPG-KEY-PGDG-91    Copy the GPG key into /var/www/html/pub on theSatellite Server so that existing servers can access it using: 
How to Create Activation Keys 
  1. Go to Systems > Activation Keys > Create New Key 
  2. Type a description and Key name  
    1. Desc = Master Key 
    2. Key = master-key 
  3. Select Provisioning 
  4. Click ‘Create Activation Key’ 
  5. Click on  Packages and add these packages to all systems  
    • # Add ITM Packages 
    • # Add Packages for MYCO 
    • # Add Telnet Client 
    • compat-libstdc++-33-3.2.3-69.el6.x86_64 
    • glibc.x86_64 
    • ksh.x86_64 
    • nfs-utils 
    • nss-softokn-freebl.x86_64 
    • python-dmidecode 
    • python-ethtool 
    • rhn-check 
    • rhn-setup 
    • rhncfg 
    • rhncfg-actions 
    • rhncfg-client 
    • telnet.x86_64 
    • yum-rhn-plugin 

Create MYCO Configuration Channel 
  • Uploaded the following files into Config Channel 
    • /path/to/files/file1 
    • /path/to/files/file2   
  • Created new Kickstart Post Script with following contents 
    • # Get MYCO Required Packages and Install set -x       SOURCEDIR="/software/MYCO"  
            if [ ! -d $SOURCEDIR ]          then mkdir -p $SOURCEDIR       fi     wget -P /software/MYCO http://myco103/MYCO/gskcrypt64-8.0.14.11.linux.x86_64.rpm wget -P /software http://myco103/MYCO/gskssl64-8.0.14.11.linux.x86_64.rpm wget -P /software http://myco103/MYCO/TIVsm-API64.x86_64.rpm wget -P /software http://myco103/MYCO/TIVsm-BA.x86_64.rpm  
    • # Yum local install the RPM's yum localinstall /software/MYCO/*.rpm -y  
Add  NTP to Script 2 (standard Script  # Configure NTP  echo "server ntp.mycoinc.com >> /etc/ntp.conf ntpdate -u ntp.mycoinc.com chkconfig --levels 2345 ntpd on