Multiple NIC Azure VM

I was playing with Azure IAAS & than came the requirement to have multiple NICs on a machine and to my surprise

  • There is no way to have multiple NICs after the machine has already been setup with a single NIC.
  • Multiple NICs are not supported by all VM sizes. (refer below link to know about which size can support multiple NIC)

https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-sizes

  • GUI has no way to create multiple NIC, it needs to be done via Powershell, Template , CLI.

Microsoft should add these capabilities as there can be situations where you want to add multiple NICs & you started with single NIC VM. There should also be an option in GUI to do the same but till MS add these features lets enjoy powershellūüôā

First & foremost note down the VM size that you will be using & it should support multiple NICs.

Login to AZURE resource manage portal using Login-AzureRmAccount

Lets first select the image that we want to deploy &  filter it with powershell.

2016:

get-AzureRmVMImage -Location “Central US” -PublisherName “MicrosoftWindowsServer” -Offer “WindowsServer” -Skus “2016-Datacenter”

2012 R2:

get-AzureRmVMImage -Location “Central US” -PublisherName “MicrosoftWindowsServer” -Offer “WindowsServer” -Skus “2012-R2-Datacenter”

2012:

get-AzureRmVMImage -Location “Central US” -PublisherName “MicrosoftWindowsServer” -Offer “WindowsServer” -Skus “2012-Datacenter”

capture

Following information is required:

$rsgname = “STP-LAB-RES-GRP” ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬†# resource group Name

$netrsgname = “STP-LAB-NET-RES-GRP” ¬† ¬†#network resource name if its different

$stgrsgname = “STP-LAB-STG-ACC” ¬† ¬† ¬† ¬† ¬† ¬† ¬† #Storage¬†resource name if its different
$location = “Central US” ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬†# Location¬†Name
$stgaccname = “stplrsstg” ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬†# storage account
$vnetname = “GlobalNetwork” ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† # Vnet
$subnet1 = “STP-Net-Range1” ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† #subnet1
$subnet2 = “STP-Net-Range2” ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬†#subnet2
$nsg = “STP-LAB-NSG-GEN” ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬†#network security group
$cred = Get-Credential                                           #administrator userid & password

$size = “Standard_A2_V2” ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† #VM Size

$vmname = “EXDAGN1” ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† #VM name

capture

Now enter the following command to start the config process.

$vm = New-AzureRmVMConfig -VMName $vmname -VMSize $size

$vm = Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $vmname -Credential $cred -ProvisionVMAgent -EnableAutoUpdate

ADD image that you want to deploy to the configuration.

$vm = Set-AzureRmVMSourceImage -VM $vm -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2016-Datacenter -Version ‚Äúlatest‚ÄĚ

Crete multiple NICs & piblic ip to be added tp configuation:

$vnet = Get-AzureRmVirtualNetwork -Name $vnetname -ResourceGroupName $netrsgname

$pubip = New-AzureRmPublicIpAddress -Name “ExPubIP” -ResourceGroupName $rsgname -Location $location -AllocationMethod Dynamic

$nic1 = New-AzureRmNetworkInterface -Name “EXDAGN1NIC1” -ResourceGroupName $rsgname -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pubip.Id

$nic2 = New-AzureRmNetworkInterface -Name “EXDAGN1NIC2” -ResourceGroupName $rsgname -Location $location -SubnetId $vnet.Subnets[2].Id

# $vnet.Subnets[0].Id/$vnet.Subnets[2].Id are the subnets that I want to be the NICs to be in.

$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic1.Id

$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic2.Id

Now make one interface as primary(this is mandatory)

$vm.NetworkProfile.NetworkInterfaces.Item(0).Primary = $true

Now we have VM details, Image, Network & now we need storageūüôā

$storageAcc = Get-AzureRMStorageAccount -Name $stgaccname -ResourceGroupName $stgrsgname

$osDiskUri = $storageAcc.PrimaryEndpoints.Blob.ToString() + ‚Äúvhds/WindowsVM2016EXosDisk.vhd‚ÄĚ

$vm = Set-AzureRmVMOSDisk -VM $vm -Name ‚ÄúWindowsVM2016EXosDisk‚ÄĚ -VhdUri $osDiskUri -CreateOption fromImage

You can now see whats its in $vm variable just to check & Lets now create the VM using this configuration.

capture

New-AzureRmVM -ResourceGroupName $rsgname  -Location $location -VM $vm

Now your VM is being Created & you can login to AZURE portal & verify the specs after process is completed.

capture

capture

capture

Regards

Sukhija Vikas

http://msexchange.me

 

Posted in Office 365 | Tagged , , , , | Leave a comment

Control Services for Office 365

Some customers want to control the services that are being pushed by Microsoft to ever expanding office 365 portfolio.

They want to first explore these before activating it for users, we were recently in such a situation where cutomer wants to disable few services.

Customer wants that these should be disabled for all Users as of now.

This script has been written to disable the services for all the o365 users without affecting their existing services.

Download & extract the script from above, update the below variables :

$licenseent = “Company:ENTERPRISEPACK” ¬†#This is the vaule that you can get by using¬†Get-MsolAccountSku

$svctodisable = @(“FLOW_O365_P2”, “TEAMS1”) # services that you want to disable for all users

Use below commands to get services value:

PS C:\> $a=Get-MsolUser -UserPrincipalName sukhijaS@msexchange.me

PS C:\> $a.Licenses.servicestatus

capture

Run the script , it will connect to MSOL (will prompt you for userid & password), if you are already connected to MSOL than just

prepend # to Connect-MsolService inside the script before execution.

Output in csv will be placed under report folder.

I hope this script will assist you in the described situation.

<#     
    .NOTES 
    =========================================================================== 
     Created on:       11/21/2016 4:18 PM 
     Created by:       Vikas Sukhija 
     Organization:      
     Filename:         ControlNewLicenseFeatures.ps1 
    =========================================================================== 
    .DESCRIPTION 
        A description of the file. 
#> 
$Error.clear() 
$date1 = get-date -format d 
$date1 = $date1.ToString().Replace("/", "-") 
$time = get-date -format t 
 
$time = $time.ToString().Replace(":", "-") 
$time = $time.ToString().Replace(" ", "") 
 
$report = ".\report" + "\" + "Report_DisabledSVC" + $date1 + "_" + $time + "_.csv" 
 
$collusers = @() 
$collection = @() 
 
###################Variables to be defined####################### 
 
$licenseent = "Company:ENTERPRISEPACK" 
$svctodisable = @("FLOW_O365_P2", "POWERAPPS_O365_P2", "TEAMS1") 
 
##########################Define functions############## 
function ProgressBar { 
    [CmdletBinding()] 
    param 
    ( 
        $title 
    ) 
     
    For ($i = 1; $i -le "10"; $i++) { 
        Start-Sleep 1; 
        Write-Progress -Activity $Title -status "$i" -percentComplete ($i /10 * 100) 
    } 
} 
##########Connect to MSOL##################### 
Connect-MsolService 
 
$AllLicensingPlans = Get-MsolAccountSku | Where-Object{ $_.AccountSkuId -eq $licenseent } 
 
$allusers = get-msoluser -All | Where-Object{ $_.isLicensed -eq $true } 
if ($error) { Write-Host "Exiting Script -- Error Fetching MSOL Users" -ForegroundColor Red; ProgressBar -title "Error Fetching MSOL Users"; exit } 
 
################Loop thru services for each user##### 
 
foreach ($user in $allusers) { 
    $status = $user.Licenses.servicestatus 
    $upn = $user.userprincipalname 
     
    if ($status -ne $null) { 
         
        foreach ($svc in $status) { 
            $svcnm = $svc.Serviceplan.ServiceName 
            $svcsts = $svc.ProvisioningStatus 
            foreach ($newsvc in $svctodisable) { 
                if (($svcnm -eq $newsvc) -and ($svcsts -ne "Disabled")) { 
                    Write-Host "$svcnm is enabled for user $upn" -foregroundcolor Magenta 
                    $collusers += $upn 
                } 
            } 
        } 
    } 
} 
$collusers = $collusers | Select-Object -Unique 
if ($error) { Write-Host "Exiting Script -- Error Collecting MSOL Users" -ForegroundColor Red; ProgressBar -title "Error  Collecting MSOL Users"; exit } 
####loop thru collected user to disable required services witout affecting enabled ####### 
$collusers | foreach-object{ 
    $mcoll = "" | Select-Object UserPrincipalName, DisabledSVC 
    $USR = $_ 
    $lic1 = get-msoluser -UserPrincipalName $USR 
     
    foreach ($sts in $lic1.Licenses) { 
        if ($sts.AccountSkuId -eq $licenseent) { 
            $status1 = $sts.servicestatus 
        } 
    } 
     
    $mcoll.UserPrincipalName = $USR 
     
    if ($status1 -ne $null) { 
        $collnmsts = @() 
        foreach ($svc1 in $status1) { 
            $svcnm1 = $svc1.Serviceplan.ServiceName 
            $svcsts1 = $svc1.ProvisioningStatus 
            if ($svcsts1 -eq "Disabled") { 
                $collnmsts += $svcnm1 
            } 
        } 
        $collnmsts += $svctodisable 
        $mcoll.DisabledSVC = $collnmsts 
        $O365Licences = $null 
        for ($i = 0; $i -lt $AllLicensingPlans.Count; $i++) { 
            $O365Licences = New-MsolLicenseOptions -AccountSkuId $AllLicensingPlans[$i].AccountSkuId -DisabledPlans $collnmsts 
        } 
        Write-Host "Processing ........................ $USR" -ForegroundColor Green 
        Set-MsolUserLicense -UserPrincipalName $USR -LicenseOptions $O365Licences 
        if ($error) { 
            Write-Host "Exiting Script -- Error setting License for $USR" -ForegroundColor Red; ProgressBar -title "Error seeting License for $USR"; exit 
        } 
    } 
    else { 
        Write-Host "Processing ........................ $USR" -ForegroundColor Green 
        $mcoll.DisabledSVC = "NA" 
    } 
    $collection += $mcoll 
} 
$collection | Select-Object UserPrincipalName, @{ Name = "DisabledSVC"; Expression = { $_.DisabledSVC } } | Export-Csv $report -NoTypeInformation 
#############################################################################

 

Regards

Sukhija Vikas

http://msexchange.me

Posted in Office 365 | Tagged , , , | Leave a comment

ADD additional SMTP Email Address Exchange Hybrid

When you run Hybrid Wizard for setting up Exchange onpremise to Exchange online integration, one of the step –> updates the email address policy to include

alias@domain.mail.microsoft.com.

 This adds additional email address to all the users that have Automatically update Email adddresses based on e-mail address policy is checked.

There are always mailboxes in the enviornment where this policy is set to false for reasons.

This nice litte script will update those mailboxes with the required email adddress along with logging & reporting.

Download & extract the zip file from below link , update the .ps1 :

https://gallery.technet.microsoft.com/scriptcenter/ADD-additional-SMTP-b3c3a055

#update the values as per your enviornment

$hybemaildom = “@domain.mail.onmicrosoft.com”¬†

$email1 = “VikasS@labtest.com”

$from = “EolemailFix@labtest.com”

$smtpserver = “smtpserver”

Run the batch file or run the .ps1 in the exchange shell. Execution scope is only the mailboxes that have email address policy set to false.

CSV report will be sent on email address specified & will also be saved in report folder.

Note: Script has been tested with exchange2010 but should work with other versions as well.

<#     
    .NOTES 
    =========================================================================== 
     Created on:       10/19/2016 12:30 PM 
     Created by:       Diwakar Sharma 
          Reviewed by:   Vikas Sukhija (http://msexchange.me) 
     Organization:      
     Filename:   Additional SMTP o365       
    =========================================================================== 
    .DESCRIPTION 
        This script will be used to add additional SMTP addtess for o365 hybrid setup. 
        There are situation where Email policy is uncheked so this script can be utilized. 
#> 
################Add Snapin & Logs/ variables######################### 
$Error.clear() 
If ((Get-PSSnapin | where { $_.Name -match "Microsoft.Exchange.Management.PowerShell.E2010" }) -eq $null) 
{ 
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
} 
$date1 = get-date -format d 
$date1 = $date1.ToString().Replace("/", "-") 
$time = get-date -format t 
 
$time = $time.ToString().Replace(":", "-") 
$time = $time.ToString().Replace(" ", "") 
 
$log = ".\logs" + "\" + "Ps_log_" + $date1 + "_" + $time + "_.log" 
$report1 = (Get-Location).path + "\" + "Report" + "\" + "Report_Hybemail" + $date1 + "_" + $time + "_.csv" 
 
$hybemaildom = "@domain.mail.onmicrosoft.com" 
$collection = @() 
 
$email1 = "VikasS@labtest.com" 
$from = "EolemailFix@labtest.com" 
$smtpserver = "smtpserver" 
 
Start-Transcript -Path $log 
 
#############get all mailboxes where policy is not applied##### 
 
$AliasAll = Get-Mailbox -ResultSize Unlimited | Where { $_.EmailAddressPolicyEnabled -ne "True" } | select Alias,emailaddresses 
$Error.clear() 
Foreach ($Als in $AliasAll) 
{ 
    Write-Host "Processing ..............."$Als.alias"" -ForegroundColor green 
    $mcoll = "" | select Alias, hybemail, Status 
    $AddSMTP = $Als.Alias + $hybemaildom 
    $mcoll.Alias = $Als.Alias 
    $mcoll.hybemail = $AddSMTP 
    $AddSMTP 
    $alladdreses = $Als.EmailAddresses | select -ExpandProperty addressstring 
    if($alladdreses -contains $AddSMTP){ 
    $mcoll.Status = "already Present" 
    } 
    else{ 
    $Error.clear() 
    Set-Mailbox $Als.Alias -EmailAddresses @{ add = $AddSMTP } 
    if ($error) 
    { 
        $mcoll.Status = "Error" 
        $Error.clear() 
    } 
    else 
    { 
        $mcoll.Status = "Success" 
    }} 
    $collection+=$mcoll 
} 
$collection | Export-Csv $report1 -NoTypeInformation 
#############Send Report############################## 
$msg = new-object Net.Mail.MailMessage 
$smtp = new-object Net.Mail.SmtpClient($smtpServer) 
$msg.From = $from 
$attach = new-object Net.Mail.Attachment($report1) 
$msg.To.Add($email1) 
$msg.Subject = "Exchange Online Emal Address Fix Report" 
$msg.Body = "Exchange Online Emal Address Fix Report" 
$msg.Attachments.Add($attach) 
$smtp.Send($msg) 
get-date 
Stop-Transcript 
################################################################

Regards

Sukhija Vikas

http://msexchange.me

Posted in Exchange, Office 365, Scripting | Tagged , , , , , , | Leave a comment

NetApp Space Reclaimer

This has been requested by our Storage Team as they were doing lot of manual stuff , uploading it in the community may be it fulfills needs for others as well.

It can act as reference script only as every environment has different needs.

Below were the requirement:

  • Monday, Wednesday, Friday

Run reclaim commands on particular times on some of the DBs

$tm1,2,3,4 variables have been defined accordingly as per times of execution

  • Tuesday,Thursday, Saturday, Sunday

Run reclaim commands on particular times on some of the DBs

$tm1,2,3,4 variables have been defined accordingly as per times of execution

  • Space reclaim staus to be shown every 30 mins in a log.(used while loop)
  • Seperate log of process initiation to be logged.
  • Full log of whole session.
  • script run time would be 320 min(divided it by 30 so that we know the number of times while loop should be run for first requirement)

You have to customize the script to detect servers as per your enviornment.(variables part)

Example:

$dag1 = “DAGVG01” (server might have this in the name)

if($hostname -like “*$dag1*”){
$dagex= $dag1 -replace “VG” ,”EX”

$dagd1 = “Y:\” + $dagex + “_DB01”

$dagl1 = “Y:\” + $dagex + “_LOG01”

}

ServerDAGVG01 (Host Name Matches)

$dagd1 = “Y:\” + $dagex + “_DB01” ¬†–> Y:\dagex_db01 (drive formation)

Extract the Zip file from below link:(after customizations batch file can be schedule or run manually to test)

Note : schedule times should be as per times defined inside script else it will not run.

example:

$tm1 =”3″

if((($day -eq $day1) – ($day -eq $day3) -or ($day -eq $day5)) -and ($tm -eq $tm1))

it checks if hour is 3 or not , if hour value is 4 than that code will not execute.

https://gallery.technet.microsoft.com/scriptcenter/NetApp-Space-Reclaimer-85629cb9

PowerShell

######################################################################### 
#            Author: Vikas Sukhija 
#            Reviewer: 
#            date: 9/9/2016 
#            Modified:                         
#            Description: Run Netapp Reclaim commands 
######################################################################### 
 
 
$date1 = get-date -format d 
$date1 = $date1.ToString().Replace("/","-") 
$time = get-date -format t 
 
$time = $time.ToString().Replace(":", "-") 
$time = $time.ToString().Replace(" ", "") 
 
$logs = ".\Logs" + "\" + "Processed_PS_" + $date1 + "_" + $time + "_.log" 
 
$log1 = ".\Logs" + "\" + "snapdrive_" + $date1 + "_" + $time + "_.log" 
 
$log2 = ".\Logs" + "\" + "snapdrive_Spacereclaim_" + $date1 + "_" + $time + "_.log" 
 
Start-Transcript -Path $logs 
 
##############Import Netap module####################### 
 
Import-Module SnapDrive 
 
if($error){Write-host "Snapdrive module not imported Exit pls" -foregroundcolor Red 
Exit} 
else{ 
Write-host "Snapdrive module imported" -foregroundcolor green } 
 
###################variables ######################## 
 
$dag1 = "DAGVG01" 
 
$day = (get-date).dayofweek 
 
$tm = (get-date).Hour 
 
$day1 = "Monday" 
 
$day2 = "Tuesday" 
 
$day3 = "Wednesday" 
 
$day4 = "Thursday" 
 
$day5 = "Friday" 
 
$day6 = "Saturday" 
 
$day7 = "Sunday" 
 
$tm1 = "5" 
 
$tm2 = "11" 
 
$tm3 = "17" 
 
$tm4 =  "23" 
 
$runtime1 = "320" 
$timeout = $runtime1/30 
 
$hostname = hostname 
 
if($hostname -like "*$dag1*"){ 
 
$dagex= $dag1 -replace "VG" ,"EX" 
 
$dagd1 = "Y:\" + $dagex + "_DB01" 
$dagd2 = "Y:\" + $dagex + "_DB02" 
$dagd3 = "Y:\" + $dagex + "_DB03" 
$dagd4 = "Y:\" + $dagex + "_DB04" 
$dagd5 = "Y:\" + $dagex + "_DB05" 
$dagd6 = "Y:\" + $dagex + "_DB06" 
$dagd7 = "Y:\" + $dagex + "_DB07" 
$dagd8 = "Y:\" + $dagex + "_DB08" 
$dagd9 = "Y:\" + $dagex + "_DB09" 
$dagd10 = "Y:\" + $dagex + "_DB10" 
 
$dagl1 = "Y:\" + $dagex + "_LOG01" 
$dagl2 = "Y:\" + $dagex + "_LOG02" 
$dagl3 = "Y:\" + $dagex + "_LOG03" 
$dagl4 = "Y:\" + $dagex + "_LOG04" 
$dagl5 = "Y:\" + $dagex + "_LOG05" 
$dagl6 = "Y:\" + $dagex + "_LOG06" 
$dagl7 = "Y:\" + $dagex + "_LOG07" 
$dagl8 = "Y:\" + $dagex + "_LOG08" 
$dagl9 = "Y:\" + $dagex + "_LOG09" 
$dagl10 = "Y:\" + $dagex + "_LOG10" 
} 
 
 
 
####################################################### 
 
if((($day -eq $day1) - ($day -eq $day3) -or ($day -eq $day5)) -and ($tm -eq $tm1)){ 
 
Write-host "Processing .....Snapdrive Commands on Databases" -foregroundcolor green 
 
sdcli spacereclaimer analyze -d $dagd1 >> $log1  
 
Write-host "Space reclaimer analysis on $dagd1 " -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagd1 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagd1 " -foregroundcolor blue 
 
sdcli spacereclaimer analyze -d $dagd2 >> $log1  
 
Write-host "Space reclaimer analysis on $dagd2 " -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagd2 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagd1 " -foregroundcolor blue 
 
sdcli spacereclaimer analyze -d $dagd3 >> $log1  
 
Write-host "Space reclaimer analysis on $dagd3 " -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagd3 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagd1 " -foregroundcolor blue 
 
} 
 
if((($day -eq $day1) - ($day -eq $day3) -or ($day -eq $day5)) -and ($tm -eq $tm2)){ 
 
Write-host "Processing .....Snapdrive Commands" -foregroundcolor green 
 
sdcli spacereclaimer analyze -d $dagd4 >> $log1  
 
Write-host "Space reclaimer analysis on $dagd4 " -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagd4 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagd4 " -foregroundcolor blue 
 
sdcli spacereclaimer analyze -d $dagd5 >> $log1  
 
Write-host "Space reclaimer analysis on $dagd5 " -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagd5 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagd5 " -foregroundcolor blue 
 
 
} 
 
 
if((($day -eq $day1) - ($day -eq $day3) -or ($day -eq $day5)) -and ($tm -eq $tm3)){ 
 
Write-host "Processing .....Snapdrive Commands" -foregroundcolor green 
 
sdcli spacereclaimer analyze -d $dagd6 >> $log1  
 
Write-host "Space reclaimer analysis on $dagd6 " -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagd6 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagd6" -foregroundcolor blue 
 
sdcli spacereclaimer analyze -d $dagd7 >> $log1  
 
Write-host "Space reclaimer analysis on $dagd7 " -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagd7 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagd7 " -foregroundcolor blue 
 
} 
 
if((($day -eq $day1) - ($day -eq $day3) -or ($day -eq $day5)) -and ($tm -eq $tm4)){ 
 
Write-host "Processing .....Snapdrive Commands" -foregroundcolor green 
 
sdcli spacereclaimer analyze -d $dagd8 >> $log1  
 
Write-host "Space reclaimer analysis on $dagd8 " -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagd8 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagd8 " -foregroundcolor blue 
 
sdcli spacereclaimer analyze -d $dagd9 >> $log1  
 
Write-host "Space reclaimer analysis on $dagd9 " -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagd9 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagd9 " -foregroundcolor blue 
 
sdcli spacereclaimer analyze -d $dagd10 >> $log1  
 
Write-host "Space reclaimer analysis on $dagd10" -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagd10 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagd10 " -foregroundcolor blue 
 
 
} 
 
######################LOG Vol####################################### 
 
 
if((($day -eq $day2) - ($day -eq $day4) -or ($day -eq $day6) -or ($day -eq $day7)) -and ($tm -eq $tm1)){ 
 
sdcli spacereclaimer analyze -d $dagl1 >> $log1  
 
Write-host "Space reclaimer analysis on $dagl1" -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagl1 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagl1" -foregroundcolor blue 
 
sdcli spacereclaimer analyze -d $dagl2 >> $log1  
 
Write-host "Space reclaimer analysis on $dagl2" -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagl2 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagl2" -foregroundcolor blue 
 
sdcli spacereclaimer analyze -d $dagl3 >> $log1  
 
Write-host "Space reclaimer analysis on $dagl3" -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagl3 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagl3" -foregroundcolor blue 
 
 
} 
 
if((($day -eq $day2) - ($day -eq $day4) -or ($day -eq $day6) -or ($day -eq $day7)) -and ($tm -eq $tm2)){ 
 
Write-host "Processing .....Snapdrive Commands" -foregroundcolor green 
 
sdcli spacereclaimer analyze -d $dagl4 >> $log1  
 
Write-host "Space reclaimer analysis on $dagl4" -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagl4 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagl4" -foregroundcolor blue 
 
sdcli spacereclaimer analyze -d $dagl5 >> $log1  
 
Write-host "Space reclaimer analysis on $dagl5" -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagl5 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagl5" -foregroundcolor blue 
 
 
} 
 
 
if((($day -eq $day2) - ($day -eq $day4) -or ($day -eq $day6) -or ($day -eq $day7)) -and ($tm -eq $tm3)){ 
 
Write-host "Processing .....Snapdrive Commands" -foregroundcolor green 
 
sdcli spacereclaimer analyze -d $dagl6 >> $log1  
 
Write-host "Space reclaimer analysis on $dagl6" -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagl6 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagl6" -foregroundcolor blue 
 
sdcli spacereclaimer analyze -d $dagl7 >> $log1  
 
Write-host "Space reclaimer analysis on $dagl7" -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagl7 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagl7" -foregroundcolor blue 
 
} 
 
 
if((($day -eq $day2) - ($day -eq $day4) -or ($day -eq $day6) -or ($day -eq $day8)) -and ($tm -eq $tm4)){ 
 
Write-host "Processing .....Snapdrive Commands" -foregroundcolor green 
 
sdcli spacereclaimer analyze -d $dagl8 >> $log1  
 
Write-host "Space reclaimer analysis on $dagl8" -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagl8 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagl8" -foregroundcolor blue 
 
sdcli spacereclaimer analyze -d $dagl9 >> $log1  
 
Write-host "Space reclaimer analysis on $dagl9" -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagl9 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagl9" -foregroundcolor blue 
 
sdcli spacereclaimer analyze -d $dagl10 >> $log1  
 
Write-host "Space reclaimer analysis on $dagl10" -foregroundcolor magenta 
 
sdcli spacereclaimer start -d $dagl10 -t $runtime1 
 
Write-host "Space reclaimer Start on $dagl10" -foregroundcolor blue 
 
} 
 
$count=0 
 
do{ 
 
sdcli spacereclaimer status >> $log2  
add-content $log2 "--------------------------------------------------------" 
timeout 1800 
 
$count = $count +1} While($count -lt $timeout) 
 
 
Stop-Transcript 
 
##############################################################
Regards
Sukhija Vikas
Posted in Scripting | Tagged , , | Leave a comment

Playing with Files – Azure Storage

In this blog post I will demonstrate the idea of if you want to upload some files images to Azure Storage so that you can use it, There are multiple methods that can be used but simplest ones are using Microsoft Azure Storage explorer and Azure storage copy command.

Download the Microsoft Azure storage explorer from below link

http://storageexplorer.com/

Ones downloaded follow the wizard & install it on your machine:

capture

Launch the Storage explorer & click connect to Azure storage

capture

It will ask you to enter SAS key or account key which you can get from Azure portal

capture

From azure portal grab the keys by clicking manage access keys( these keys are very important , I am not going in detail for securing them as motive here is to upload files to azure)

capture

After you entered the storage key & Storage account name you can than click next, finish the wizard to connect.

Now you can just browse thru your storage account & use simple upload /download button for file operations.

capture

Note:- Don’t forget to detach it after work is completed.

capture

Another way of doing is via command line using Azcopy tool which is also a good/faster way.

Download the AZcopy from below link:

https://azure.microsoft.com/en-us/downloads/

You can use below command Syntax & copy the data to Azure storage account.

AzCopy.exe /Source:\\server\e$\CloudARchivemigration\ /Dest:”https://SASURL&#8221; /V:E:\CloudARchivemigration\Logs\AzCopy1.log

This method is being used during PST upload in o365 as well.

capture

Regards

Sukhija Vikas

http://msexchange.me

Posted in Office 365 | Tagged , | Leave a comment

Change ActiveSync Policy Based on AD group

There has been a requirement that we need to change the policy of certain users & need to automate the process based on AD group.

We have written below script to do this job, this script uses QAD AD Shell & Exchange management shell.

It fetches group members from the AD group export them in csv (so that it can compare afterwards & only changes are processed)

When running the script for the first time it will generate a CSV file of group members (empty the whole file except one user that you can process manually)

After that you can just schedule the script it will run incrementally.

  • When ever new user is added to the group –> Active sync policy will be updated
  • When user is removed from the group –> Activesync policy will be changed to default
  • Recycle logs after 30 days
  • If error occurs than send alert.

Download & extract the script from below link

https://gallery.technet.microsoft.com/scriptcenter/Change-ActiveSync-Policy-10840be7

Update the below values as per customer’s environment:

———————————————————————–

$smtpServer = “smtpserver”

$fromadd = “DoNotReply@labtest.com”

$email1 = “VikasS@labtest.com”

 

$Asyncpol = “ActiveSync Policy”

$defAsyncpol = “Default ActiveSync Policy”

$group = “AD Group”

——————————————————————————

Thanks to “Lazy Admin” as incremental code has been taken from one of his blog post.

http://www.lazywinadmin.com/

 

###################################################################### 
#               Author: Vikas Sukhija(http://msexchange.me) 
#               Date:- 03/16/2016 
#        Reviewer:- 
#               Description:- Change activesync policy based on  
#               a particular AD group. 
###################################################################### 
 
$date1 = get-date -format d 
$date1 = $date1.ToString().Replace("/","-") 
$dir= ".\logs" 
$limit = (Get-Date).AddDays(-30) 
 
$logs = ".\Logs" + "\" + "Processed_" + $date1 + "_.log" 
 
$smtpServer = "smtpserver" 
$fromadd = "DoNotReply@labtest.com" 
$email1 = "VikasS@labtest.com" 
 
Start-Transcript -Path $logs 
 
######Add Quest Shell & define attrib/ group value############ 
 
If ((Get-PSSnapin | where {$_.Name -match "Quest.ActiveRoles.ADManagement"}) -eq $null) 
{ 
    Add-PSSnapin Quest.ActiveRoles.ADManagement 
} 
 
#######Add exchange Shell ############################## 
 
If ((Get-PSSnapin | where {$_.Name -match "Microsoft.Exchange.Management.PowerShell.E2010"}) -eq $null) 
{ 
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
} 
 
$Asyncpol = "ActiveSync Policy" 
$defAsyncpol = "Default ActiveSync Policy" 
 
$group = "AD Group" 
 
################################################################# 
 
$groupmem = Get-QADGroupMember $group -sizelimit 0 
 
$groupmem 
 
$Statefile = "$($group)-Name.csv" 
 
 
# If the file doesn't exist, create it 
 
   If (!(Test-Path $Statefile)){   
                $groupmem | select Name | Export-csv $Statefile -NoTypeInformation  
                } 
 
# Check Changes 
$Changes =  Compare-Object $groupmem $(Import-Csv $StateFile) -Property Name |  
                Select-Object Name, 
                    @{n='State';e={ 
                        If ($_.SideIndicator -eq "=>"){ 
                            "Removed" } Else { "Added" } 
                        } 
                    } 
 
$Changes | foreach-object{ 
          
    if($_.state -eq "Added") { 
 
        Write-host "$Asyncpol will be updated to "$_.Name"" -foregroundcolor green 
           $checkasync = Get-CASMailbox -Identity $_.Name 
        if($checkasync.ActiveSyncEnabled -eq $true){ 
    Set-CASMailbox -Identity $_.Name -ActiveSyncMailboxPolicy $Asyncpol}} 
     
     
        if($_.state -eq "Removed") { 
        $userid = "$_.Name" 
        Write-host "$Asyncpol will be removed from "$_.Name"" -foregroundcolor Red 
    $checkasync = Get-CASMailbox -Identity $_.Name 
        if($checkasync.ActiveSyncEnabled -eq $true){ 
    Set-CASMailbox -Identity $_.Name -ActiveSyncMailboxPolicy $defAsyncpol}} 
     
      } 
 
$groupmem | select Name | Export-csv $StateFile -NoTypeInformation 
 
###########################Recycle########################################## 
 
$path = $dir  
  
Get-ChildItem -Path $path  | Where-Object {   
$_.CreationTime -lt $limit } | Remove-Item -recurse -Force  
 
#######################Report Error######################################### 
if ($error -ne $null) 
      { 
#SMTP Relay address 
$msg = new-object Net.Mail.MailMessage 
$smtp = new-object Net.Mail.SmtpClient($smtpServer) 
 
#Mail sender 
$msg.From = $fromadd 
#mail recipient 
$msg.To.Add($email1) 
$msg.Subject = "Activesync Policy Script error" 
$msg.Body = $error 
$smtp.Send($msg) 
$error.clear() 
       } 
  else 
 
      { 
    Write-host "no errors till now" 
      } 
 
$path = ".\logs\" 
$limit = (Get-Date).AddDays(-30) #for log recycling 
 
########################Recycle logs ###################################### 
 
Get-ChildItem -Path $path  | Where-Object {   
$_.CreationTime -lt $limit } | Remove-Item -recurse -Force  
stop-transcript 
 
##########################################################################

Regards

Sukhija Vikas

http://msexchange.me

Posted in Exchange, Scripting | Tagged , , | Leave a comment