Wednesday, April 5, 2017

Cross Forest Exchange Migration

AD PowerShell Cross Forest Migration


MyLocalDomain
$LocalCredentials = Get-Credential
TheirRemoteDomain
$RemoteCredentials = Get-Credential

Mydomain\Myadmin
Theirdomain\Theiradmin

Prepare Before Migration:
.\Prepare-MoveRequest.ps1 -Identity remoteuser@theirdomain.net -RemoteForestDomainController theirdomaincontrollerfqdn -RemoteForestCredential $RemoteCredentials -UseLocalObject -OverwriteLocalObject -TargetMailUserOU "OU=mydomain,DC=net"

Migrate:
New-MoveRequest -Identity remoteuser@theirdomain.net -Remote -TargetDatabase "MDB01" -RemoteGlobalCatalog "theirdomaincontrollerfqdn" -RemoteCredential $RemoteCredentials -TargetDeliveryDomain "mydomain.net" -RemoteHostName "theirdomain.net"

With Bad Items & Suspend:
New-MoveRequest -Identity remoteuser@theirdomain.net -Remote -TargetDatabase "MDB01" -RemoteGlobalCatalog "theirdomaincontrollerfqdn" -RemoteCredential $RemoteCredentials -BadItemLimit 500 -AcceptLargeDataLoss -LargeItemLimit 100 -TargetDeliveryDomain "mydomain.net" -RemoteHostName "theirdomain.net" -SuspendWhenReadyToComplete

Bulk Migration:

Import File:
$InputFile = "C:\Batch01.csv"

Prepare Migration:
Import-Csv $InputFile | Foreach{.\Prepare-MoveRequest.ps1 -Identity $_.PrimarySmtpAddress -RemoteForestDomainController "theirdomaincontrollerfqdn" -RemoteForestCredential $RemoteCredentials -UseLocalObject -OverwriteLocalObject -TargetMailUserOU "Mydomain,DC=net"}

Migrate:
Import-Csv $InputFile | Foreach{Update-Recipient –Identity $_.PrimarySmtpAddress}

Bad Items & Suspend:
Import-Csv $InputFile | foreach {New-MoveRequest -Identity $_.PrimarySMTPAddress -Remote -TargetDatabase MDB01 -RemoteGlobalCatalog "theirdomaincontrollerfqdn" -RemoteCredential $RemoteCredentials -BadItemLimit 200 -AcceptLargeDataLoss -LargeItemLimit 100 -TargetDeliveryDomain "mydomain.net" -RemoteHostName "mail.theirdomain.net" -SuspendWhenReadyToComplete}

Check Status:
Get-MoveRequestStatistics -Identity username@theirdomain.net
Resume after 95% completion:
Resume-MoveRequest -Identity "username@theirdomain.net


Sunday, May 29, 2016

Wednesday, January 27, 2016

ActiveSync does not work for one user

Open Active Directory Users and Computers.
On the menu at the top of the console, click View > Advanced Features.
Locate and right-click the mailbox account in the console, and then click Properties.
Click the Security tab.
Click Advanced.
Make sure that the check box for "Include inheritable permissions from this object's parent" is selected.

Wednesday, September 16, 2015

EMC Source One search folder in outlook


Script below will create a folder in outlook to search archived items. Kind of browser inside outlook.
Save it as .vbs and execute or deploy through group policy on logon script.

=========================================================
Const olFolderInbox = 6

Dim FolderStatus
Dim OstFileCount

'Retrieve Username of the logged in user
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
'WScript.Echo "User Name: " & strUserName

'Define the path of the .ost file
Path = "C:\users\" & strUserName & "\appdata\local\Microsoft\Outlook"

'WScript.Echo "User Name: " & strUserName
'WScript.Echo "Path: " & Path

Function ReportFolderStatus(fldr)
   Dim fso, msg
   Set fso = CreateObject("Scripting.FileSystemObject")
   If (fso.FolderExists(fldr)) Then
      'MsgBox ("1")
      FolderStatus = "1"
   Else
      'MsgBox ("0")
      FolderStatus = "0"
   End If
   ReportFolderStatus = FolderStatus
End Function

'obiFile = "C:\users\" & strUserName & "\appdata\local\Microsoft\Outlook" & "\Outlook.sharing.xml.obi"
'WScript.Echo "File: " & obiFile

'http://blogs.technet.com/b/heyscriptingguy/archive/2005/01/14/how-can-i-tell-if-a-folder-has-any-files-with-a-specific-file-extension.aspx
Function IsOSTFilePresent(Path)
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService. _
   ExecQuery("SELECT * FROM CIM_DataFile WHERE Path = '\\Users\\" & strUserName & "\\AppData\\Local\\Microsoft\\Outlook\\' " & _
       "AND Drive = 'C:' AND Extension = 'ost'")

'Wscript.Echo "Number of .ost files found: " & colFiles.Count
IsOSTFilePresent = colFiles.Count
End Function

FolderStatus = ReportFolderStatus(Path)
'WScript.Echo "Folder Status: " & FileStatus

OstFileCount = IsOSTFilePresent(Path)
'WScript.Echo "# of Ost Files: " & OstFileCount

'Find out first if the folder exists, then check if the OST file exists, if yes, then proceed in creating the folder

If FolderStatus = 1 Then

If OstFileCount <> 0 Then

On Error Resume Next
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)

strFolderName = objFolder.Parent
Set objMailbox = objNamespace.Folders(strFolderName)

Set objNewFolder = objMailbox.Folders.Add("Tasnee Archive Search")
objNewFolder.WebViewURL = "https://archive.tasnee.com/search"
objNewFolder.WebViewOn = True

If Err.Number <> 0 Then
On Error GoTo 0
'the folder doesn't exist, create it
End If

End If

End If
======================================================

Monday, September 7, 2015

Local Administrators list on all workstations, remote machines.


Create list of Computers with below command

Get-ADComputer -Filter * | select name > c:\computers.txt

Execute below Script: It will create c:\localusers.csv
# ==============================================================================================
# NAME: Listing Administrators and PowerUsers on remote machines

#
# COMMENT:
# This script runs against an input file of computer names , connects to each computer and gets a list of the users in the  local Administrators
#and powerusers Groups . the output can be a csv file which can be readable on excel with all the computers from the input file
# ==============================================================================================
function get-localusers {
        param(
    [Parameter(Mandatory=$true,valuefrompipeline=$true)]
    [string]$strComputer)
    begin {}
    Process {
        $adminlist =""
        $powerlist =""
        $computer = [ADSI]("WinNT://" + $strComputer + ",computer")
        $AdminGroup = $computer.psbase.children.find("Administrators")
        $powerGroup = $computer.psbase.children.find("Power Users")
        $Adminmembers= $AdminGroup.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
        $Powermembers= $PowerGroup.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
        foreach ($admin in $Adminmembers) { $adminlist = $adminlist + $admin + "," }
        foreach ($poweruser in $Powermembers) { $powerlist = $powerlist + $poweruser + "," }
        $Computer = New-Object psobject
        $computer | Add-Member noteproperty ComputerName $strComputer
        $computer | Add-Member noteproperty Administrators $adminlist
        $computer | Add-Member noteproperty PowerUsers $powerlist
        Write-Output $computer


        }
end {}
}

Get-Content c:\computers.txt | get-localusers | Export-Csv c:\localusers.csv 

Users Attributes and Computer Attributes


Users Attributes

=======================================================
$ADUserProperties = @(
"Name",
"SamAccountName",
"OfficePhone",
"MobilePhone",
"Mobile",
"ipphone",
"Country",
"City",
"POBox",
"PostalCode",
"Company",
"proxyAddresses",
"telephoneNumber",
"Title",
"Department",
"Enabled",
"CanonicalName"
)

$SelectADUserProperties = @(
"Name",
"SamAccountName",
"OfficePhone",
"MobilePhone",
"Mobile",
"ipphone",
"Country",
"City",
"POBox",
"PostalCode",
"Company",
"proxyAddresses",
"telephoneNumber",
"Title",
"Department",
"Enabled",
"CanonicalName"
)

Get-ADUser -Filter * -Properties $ADUserProperties  |  select $SelectADUserProperties | Out-GridView
======================================================




Computers Inventory

===================================================
$ADUserProperties = @(
"Name",
"SamAccountName",
"Created",
"Enabled",
"LastLogonDate",
"CanonicalName",
"Title",
"LastLogon",
"Department",
"PasswordExpired"
)

$SelectADUserProperties = @(
"Name",
"SamAccountName",
"Created",
"Enabled",
"LastLogonDate",
"CanonicalName",
"Title",
"LastLogon",
"Department",
"PasswordExpired"
)

Get-ADUser -Filter * -Properties $ADUserProperties  |  select $SelectADUserProperties | Out-GridView

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



Thursday, April 9, 2015

windows patching date for bulk servers

1. Generate a Report for installed Hotfix-Update-ServicePack for Bulk Servers.
2. Check a specific Hotfix is installed or not in Multiple Computers.
3. Get the latest Patching Date for bulk Computers.

Create computers.txt on C drive with below command. (create servers list, remove spaces if any exist at the end of computer names, copy to excel and past back in txt)
Get-ADComputer -Filter 'OperatingSystem -like "*Server*"' -Properties * |
Select-Object Name | Sort-Object Name > c:\computers.txt

Save below script as .ps1 and execute on DC.
function Hotfixreport { 
$computers = Get-Content C:\computers.txt   
$ErrorActionPreference = 'Stop'   
ForEach ($computer in $computers) {  
 
  try  
    { 
Get-HotFix -cn $computer | Select-Object PSComputerName,HotFixID,Description,InstalledBy,InstalledOn | FT -AutoSize 
  
    } 
 
catch  
 
    { 
Write-Warning "System Not reachable:$computer" 
    }  
 
Hotfixreport > "$env:USERPROFILE\Desktop\Hotfixreport.txt"





References:
https://gallery.technet.microsoft.com/scriptcenter/Generate-a-Report-for-f71a6800
http://stackoverflow.com/questions/24039325/get-the-last-windows-update-install-date-using-powershell