Posts Tagged PowerShell

Cannot add Windows PowerShell snap-in VeeamPSSnapin


You may encounter an error Cannot add Windows PowerShell snap-in VeeamPSSnapin when you run PowerShell scripts on Veeam Backup & Replication to start Backup Jobs after an upgrade from Veeam  Backup v6.x to v6.5

Symptoms:

  • PowerShell Scripts scheduled via Task Scheduler doesn’t start automatically.
  • If you run the script manually via Veeam PowerShell snap-in VeeamPSSnapin, you will receive an error. Cannot add Windows PowerShell snap-in VeeamPSSnapin. But the job will start.

Solution:

Upgrade to PowerShell 3.0 by installing Windows Management Framework 3.0 (http://www.microsoft.com/en-us/download … x?id=34595) which supports .Net 4.0 natively.

Advertisements

, , , , , , , ,

Leave a comment

View Mailboxes in Exchange Server 2007 who Exceed Quota Limit


Mailbox quotas help control the size of mailboxes, For example, would you like to know which mailboxes have reached their prohibit send receive quota, Or view the mailbox size and quota status of a specific mailbox?

You can do all that with the Get-Mailbox and Get-MailboxStatistics Exchange PowerShell cmdlets.
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | where {$_.StorageLimitStatus -notlike "BelowLimit*"} | select DisplayName,LegacyDN,DatabaseName,StorageLimitStatus|Export-Csv c:\ExceedQuota.csv

The above script will loop through each Mailboxes and will get each Mailbox Statistics where their StorageLimitStatus not BelowLimit.

The Get-MailboxStatistics has a property where you can fetch each a property with Where statement and braces bracket {} to get the StorageLimitStatus Property.

The result of the above script is the below table;

DisplayName LegacyDN DatabaseName StorageLimitStatus
Full Display Name /O=Organization/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=Alias Students-DB10 ProhibitSend

Manual work has to be done to remove the LegacyDN and keep only the Alias CTRL+H find what and Replace All is a good to delete the entire LegacyDN name and keep only the Alias.

You can use another script to move the mailbox from one Database which has got a quota limited quota to a higher Database which has higher quota.

In order to move the Mailbox to higher quota Database, you need to know the Database Storage Limit Size. You can achieve this by running the Get-MailboxDatabase cmdlet in Exchange PowerShell and pipe it with the property of ProhibitSendReceiveQuota
 Get-MailboxDatabase | select Name, StorageGroup, ProhibitSendReceiveQuta | Export-CSV C:\DBQuota.csv

Name StorageGroup ProhibitSendReceiveQuota
Staff-DB1-H MAILSERVER\Staff-SG 2355MB
Staff-DB2-N MAILSERVER\Staff-SG 1111520KB
Staff-DB3-L MAILSERVER\Staff-SG 515520KB
Students-DB1 MAILSERVER\Students-SG 1000MB
Students-DB2 MAILSERVER\Students-SG 100MB
Students-DB3 MAILSERVER\Students-SG 200MB
Students-DB4 MAILSERVER\Students-SG 311999KB
Students-DB5 MAILSERVER\Students-SG 1300000KB
Students-DB6 MAILSERVER\Students-SG2 400MB
Students-DB7 MAILSERVER\Students-SG2 522000KB
Students-DB8 MAILSERVER\Students-SG2 800MB
Students-DB9 MAILSERVER\Students-SG2 919200KB
Students-DB10 MAILSERVER\Students-SG2 1024160KB
Staff-DB4-O MAILSERVER\Staff-SG 5000MB
Students-DB11 MAILSERVER\Students-SG3 200MB
Students-DB12 MAILSERVER\Students-SG3 200MB
Students-DB13 MAILSERVER\Students-SG3 200MB
Students-DB14 MAILSERVER\Students-SG3 200MB

Now it’s time to move the Mailboxes from their current Database where has got limited quota to the higher Databases which has higher quota.

In order to move the require users from one Database to another, you need to put their Alias/EmailID into a text file to be called by another script and start moving the mailbox to the target Database.

You can filter the first CSV export by Database Column to get all the users in the limited quota database, copy only the  Alias/EmailID to a text file and use the below script to move them to the target Database;


#############################
# Move-Multiple-Mailbox.ps1 #
# Created By Assaf Miron #
# Date : 06/11/07 #
#############################

Param(
[String]$TargetDB,
[String]$FileToOpen,
[Boolean]$ValidateOnly=$False
)

function IsHelpRequest
{
param($argument)
return ($argument -eq "-?" -or $argument -eq "-help");
}

# Function that displays the help related to this script following
# the same format provided by get-help or -?
Function Usage
{
@"

NAME:
`tMove-Multiple-Mailbox.ps1 [-FileToOpen][-TargetDB]

SYNOPSIS:
`tMoves a list of mailboxes listed in an Excel File to
`ta specific Database.

SYNTAX:
`tMove-Multiple-Mailbox.ps1
`t`t[ -FileToOpen ]
`t`t[ -TargetDB ]
`t`t[ -ValidateOnly [True/False] ]

PARAMETERS:
`t-FileToOpen (required)
`t`tAn Text File wich Contains Principle Names of Users to Move
`t-TagretDB (required)
`t`tTarget Databse Name
`t-ValidateOnly (optional)
`t`tDoesn't move the mailboxes but checks if they can move to the target DB

`t-------------------------- EXAMPLE 1 --------------------------

C:\PS> .\Move-Multiple-Mailbox.ps1 -FileToOpen "C:\UsersToMove.txt" -TargetDB "Students-DB6"

`t-------------------------- EXAMPLE 2 --------------------------

C:\PS> .\Move-Multiple-Mailbox.ps1 -FileToOpen "C:\UsersToMove.txt" -TargetDB "Students-DB6" -ValidateOnly $true

REMARKS:
`tThe Move Mailbox accours with the Max threads Parameter
`tit will not move mailboxes that have errors
`tor mailboxes that need to preserve thier size.

"@
}

####################################################################################################
# Script starts here
####################################################################################################

# Check for Usage Statement Request
$args | foreach { if (IsHelpRequest $_) { Usage; exit; } }

$arrMailboxes = @()

# Validate the parameters
If ($TargetDB -eq "") { Usage; exit; }
Else {
If ($FileToOpen -eq "") { Usage; exit; }
Else {
write-host $FileToOpen

$arrMailboxes = Get-Content $FileToOpen

Write-Host "About to move"$arrMailboxes.Count"Mailboxes to"$TargetDB
$Ans = Read-Host "is This information Correct ? `n[Yes,No]`nDefault(Yes)"
If ($Ans.Contains("n")) { exit; }
If ($ValidateOnly -eq $True)
{
$arrMailboxes | Move-Mailbox -TargetDatabase $TargetDB -MaxThreads 16 -ValidateOnly
}
Else
{
$arrMailboxes | Move-Mailbox -TargetDatabase $TargetDB -MaxThreads 16
}
}
}

, , , , , , , ,

Leave a comment

Scheduling Veeam Backup Jobs for Daily Incremental and Weekly Full using PowerShell


As every Veeam Backup & Replication User/Administrator can see that only one schedule can be configured for each job, which will includes First Full backup, Active Full backup and Daily Increments.

Daily incremental takes less time than the full backup and if you have configured the jobs to run each after another with minimum 20 – 30 minutes cap. In the same job there you are restricted to select either Synthetic Backup with Transforming the Backups into one Full Backup *.VBK file chain of all previous incremental or you have to select Active Full.

Synthetic takes less time to finish incremental, but if you don’t have good CPU/Memory resources and Disk I/O, the transformation process could take time or you might end up with full VM freezing.

But if you are in Active Backup and selected Weekly Active Full Backup on Friday let assume, which again if Friday trigger it will run as Full in the same time that the daily incremental runs which will take longer to finish and in the same time the second job will start before the first job finish and will end up having whole jobs running and will slow down the read and write performance of the disks and Veeam server.

Since Friday is the day off and the servers/systems are being utilized very less, I have the whole day to run my backup, but can I can configure the Active Full Backup to run on different day other than the one which is configured in the Job Scheduler of the Backup Job?

Currently there is no way to configure it from the Veeam GUI and it would be very fantastic feature if Veeam.com would consider to add a separate schedule for the Active Full Backup.

The only way to make sure you run your jobs without overlapping with other jobs and will run into performance issue; with very simple Veeam PowerShell script and a Windows batch script to call the PS1 script will make sure all jobs runs as per your needs.
In my environment, I’m backing up 44 VMs those VMs divided into 5 Jobs; I have created 5 scripts for each job and I disabled the Backup Job Schedule;

Critical VMs-1

Critical VMs-2

Critical VMs-3

Critical VMs-4

Critical VMs-5

I have created two scripts for each job as follows;

PowerShell Script “Critical VMs-1.PS1

Add-PSSnapIn -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
Get-VBRJob -Name "Critical VMs-1" | Start-VBRJob

This Power Shell Script, will find the job name “Critical VMs-1” via the Get-VBRJob command and will start the Backup job via Start-VBRJob.

And another Windows Batch Script to call the Critical VMs-1.PS1 PowerShell script and invoke it into the PowerShell;

Windows Batch Script “RunCritical-1.bat

PowerShell.exe G:\Scripts\Critical VMs-1.PS1

I have repeated the same scripts for each job. Then in the task Scheduler in windows server 2008 R2, I configured two schedules for each backup job, so one schedule will run the same script RunCritical-1.bat from Sunday to Thursday as daily incremental and the same script will run on Friday on different time than the daily schedule, this will make sure that I have enough time window to run my backup jobs from early morning on Friday.  And since the Veeam Backup Job already configured as Active Full on Friday, it will automatically triggered and run as Full.

Hope it helps;

, , , , ,

1 Comment

Automating Windows 7 Joining Microsoft Domain With PowerShell Scripts


Automating Windows 7 to join a Microsoft Active Directory Domain

Rename Computer: VBS Script

strComputer = “.”
strNewName = InputBox(“New Computer Name:”)
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)

Set colComputers = objWMIService.ExecQuery _
(“Select * from Win32_ComputerSystem”)

For Each objComputer in colComputers
err = objComputer.Rename(strNewName)

Next

==========================================================

Reboot Batch File: .BAT

shutdown -r -t 1

==========================================================

Add-Computer to Domain: PowerShell Script

Add-Computer -DomainName DomainName.com -cred Domain\Username -PassThru
Restart-Computer

=========================================================

, , , , , , ,

1 Comment