Showing posts with label Script. Show all posts
Showing posts with label Script. Show all posts

Tuesday, July 28, 2015

10 PowerShell hot pedaling in your Exchange environment

As one Arrentino saying "How are you"?
Staff, the footprint here is as follows; put 10 hot commands for you streamline your daily tasks.
come on:
# 01 - Test-MAPIConnectivity -Identity EMAILDOUSUARIO@DOMINIO.COM | fl
This command being positive ensures that system services, such as Managed Folder Assistant and OWA able to successfully access the mailbox in question, it also brings that server information is located Database and the user's Mailbox. Bears the name of the Mailbox and the coolest, brings Latency. Not to mention that the camando also shows you the status.
# 02 - Get-MailboxDatabaseCopyStatus * | where {$ _ eq ContentIndexState "Failed".}
This is maniero Pakas Mermão. The more show this command is that it shows you which Databases are with the millennium bug's in the Index. Likes? It has more Mermão.
# 03 - Get-MailboxDatabaseCopyStatus * | where {$ _. ContentIndexState -eq "Failed"} | Update-MailboxDatabaseCopy -CatalogOnly
Recalls that the tip # 02 I said I had more? Command that you identified which Databases are with Millennium Bug in the Index, right? It is Mermão, now you correct. Is not it beautiful?
# 04 - Get-MailboxServer | fl name
Get-ClientAccessServer | fl name
Get-TransportServer | fl name
The above commands list the servers of their respective functions. Convenient and fast as well.
# 05 - Get-MailboxDatabase -Status | ft name, last -auto *
Get that is supimpa. The crazy list the status of the last backup (Full / incremental / copy) of databases.
# 06 - Move-ActiveMailboxDatabase NOMEDODATABASE -ActivateOnServer SERVERNAME -Confirm: $ false
Command to move mailbox.
# 07 - Get-Mailbox -Identity CONTADOUSUARIO | Get-MailboxPermission | fl
It happens sometimes, users report that they are receiving pop up asking for password. This command checks the access permissions.
# 08 - New-MoveRequest -identify CONTADOUSUARIO -TargetDatabase DATABASENAME -BadItemLimit 50 -AcceptLargeDataLoss
Comandinho supimpa to move users. And an environment that there are several rules that comanado Database is very useful.
# 09 - Get-MailboxServer -identity NOMEDOSERVERMAILBOX | Get-MailboxDatabase | where {$ _ name -match "NOMEDATABASE."} | Get-Mailbox
Cool command that shows users on the database.
# 10 - Get-Mailbox -identity EMAILDOUSUARIO@DOMINIO.COM | Select-Object Alias ​​| foreach-object {Get-MailboxFolderStatistics -Identity $ _ alias | select-object Identity, ItemsInFolder, FolderSize.}
This command is to close with a flourish. Get this shows all your folders created in your mailbox, items in your folder and the size of each.

I hope these tips to accelerate everyday tasks. Soon we will bring the TOP 10 PowerShell for Active Directory.

Microsoft Cluster - Disco reserved

Personal, recently something happened at least interesting with a Mailbox server (MS-Exchange 2010).
This machine was running on ESXi 5.0. How interesting:
In a VMware environment provisioning happens machines from a template, ie a customized Windows with C and D units, right? You install a Windows update patches, install BKP client and other tools according to your environment. Nice!And how the bidding of templates? When you request to be provisioned a machine from a template vCenter makes a clone of that template, that looks cool. Folks, this is perfect if you are not using this as vmware couple of other, that is, if you are not using as Microsoft Cluster or a DAG (MS-Exchange).
The cluster creation process in one of the steps is necessary make a validation. In this validation step these machines created from the clone with D discs received a warning! Ai houses the personal danger ... It's just a warning. The validation is successful.
what can hapen? It may happen that this disk D please reserved. Now imagine that this machine, as in my example, is running an Exchange that was made in the installation disk D. Oh, my friends, when the phone your table play and the GI or the Help Desk say that dozens of boxes mail are out, or rather, the business executive is no mail. At this time you pick up all your mess and go to the nearest cinema, or you start to cry.
How can we validate it? Staff, the goal of this post is not to bring the fastest and practical troubleshooting to get the reserved disk. The idea here is to show that it exists and should not happen.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C: \ Users \ Admin> diskpart
Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: VMTESTECLUSTER01
DISKPART> list disk
Disk ### Status Size Free Dyn Gpt
--- ----- --- --- - -
Disk 0 Online 100 GB 1024 KB
Disk 1 Online 80 GB 1024 KB
Disk 2 Online 600 GB 0 B
Disk 3 Online 600 GB 0 B
Disk 4 Online 600 GB 0 B
DISKPART> select disk 1
Disk 1 is now the selected disk.
DISKPART> detail disk
VMware Virtual Disk SCSI Disk Device
Disk ID: E87C0E42
Type: SAS
Status: Online
Path: 0
Target: 1
LUN ID: 0
Location Path: PCIROOT (0) #PCI (1500) #PCI (0000) #SAS (P00T01L00)
Current read-only state: No
Read-only: No
Boot Disk: No
Pagefile Disk On
Hibernation File Disk On
Crashdump Disk On
Clustered Disk On
Volume ### Ltr Label Fs Type Size Status Info
---- - ---- - ---- --- --- ---
Volume 3 D New Volume NTFS Partition 79 GB Healthy
DISKPART>
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C: \ Users \ Admin> diskpart
Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: VMTESTECLUSTER02
DISKPART> list disk
Disk ### Status Size Free Dyn Gpt
--- ----- --- --- - -
Disk 0 Online 100 GB 1024 KB
Disk 1 Online 80 GB 1024 KB
Disk 2 Online 600 GB 0 B
Disk 3 Online 600 GB 0 B
Disk 4 Online 600 GB 0 B
DISKPART> select disk 1
Disk 1 is now the selected disk.
DISKPART> detail disk
VMware Virtual Disk SCSI Disk Device
Disk ID: E87C0E42
Type: SAS
Status: Online
Path: 0
Target: 1
LUN ID: 0
Location Path: PCIROOT (0) #PCI (1500) #PCI (0000) #SAS (P00T01L00)
Current read-only state: No
Read-only: No
Boot Disk: No
Pagefile Disk On
Hibernation File Disk On
Crashdump Disk On
Clustered Disk On
Volume ### Ltr Label Fs Type Size Status Info
---- - ---- - ---- --- --- ---
Volume 3 D NTFS Partition 79 GB Healthy
DISKPART>
The Disk ID same in both machines. What's wrong with having the same ID's? The cluster resource not to promote competition in access to this disk puts in reserve.
clip_image001
Best practices in this case is to remove the D drive, what's in your template, and adds it again, the ID will be different for each machine.
and now?I get it best practice to not happen to get in a disk reserved. Okay, tell me there? How do I remove the disc reserves in a situation like this? Well, you can remove the so reserved but can not request a cluster validation on that machine. Remove the reservation and migrate resources, in my example, uninstall disk MS-Exchange D. Remove the disc D. After that add the D disk and install MS-Exchange again. Then do the validation.
Let's put the resolution to remove the reserved mode. Recalling that the idea of ​​this post is to guide so that does not happen.
Open Powershell and type the following command line:
Clear-ClusterDiskReservation -Disk 1 -node node1 -Force
I hope that by sharing this experience I can add something.

List Domain Group Members

My dear colleagues, below script to list the members of all Active Directory domain security groups:
$ Groupinfo = "| Select 'Group Name', 'Group Description', 'Member Name', 'Member Description'
AllGroups = $ @ ()
$ MyGroups = Get-ADGROUP -filter {GroupCategory -eq "Security"} -SearchBase "dc = DOMAIN, DC = LOCAL" -Properties Name, Member | select Name, Member
foreach ($ Group in $ MyGroups) {
$ GroupInfo.'Group Name '= $ Group.Name
$ GroupInfo.'Group Description '= $ Group.Description
foreach ($ Member in $ Group.Member) {
$ User = Get-Member ADUser $ -Properties Name | select Name
$ GroupInfo.'Member Name '= $ User.Name
$ Groupinfo | select 'Group Name', 'Member Name'
$ AllGroups + = $ groupinfo | Select 'Group Name', 'Member Name'
}
}
$ AllGroups | Export-CSV allginfo.csv -NoTypeInformation
We can use the same script to filter out members of a single chain.For it changed the filter parameter $ MyGroups = Get-ADGROUP -filter {GroupCategory -eq "Security"} that selects all domain security groups for $ MyGroups = Get -ADGroup -filter {Name -eq "groupname"}.
I hope you find it useful!

Saved Queries

Active Directory Queries!!!!!!

Find Groups that contains the word admin

(objectcategory=group)(samaccountname=*admin*)
Find users who have admin in description field
(objectcategory=person)(description=*admin*)
Find all Universal Groups 
(groupType:1.2.840.113556.1.4.803:=8)
Empty Groups with No Members 
(objectCategory=group)(!member=*)
Finds all groups defined as a Global Group, a Domain Local Group, or a Universal Group
(groupType:1.2.840.113556.1.4.804:=14)
Find all User with the name Bob
(objectcategory=person)(samaccountname=*Bob*)
Find user accounts with passwords set to never expire
(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=65536)
Find all users that never log in to domain
(&(&(objectCategory=person)(objectClass=user))(|(lastLogon=0)(!(lastLogon=*))))
Find user accounts with no log on script
(objectcategory=person)(!scriptPath=*)
Find user accounts with no profile path
(objectcategory=person)(!profilepath=*)
Finds non disabled accounts that must change their password at next logon
(objectCategory=person)(objectClass=user)(pwdLastSet=0)(!useraccountcontrol:1.2.840.113556.1.4.803:=2)
Finds all disabled accounts in active directory
(objectCategory=person)(objectClass=user)(!useraccountcontrol:1.2.840.113556.1.4.803:=2)
Finds all locked out accounts
(objectCategory=person)(objectClass=user)(useraccountcontrol:1.2.840.113556.1.4.803:=16)
Finds Domain Local Groups
(groupType:1.2.840.113556.1.4.803:=4)
Finds all Users with Email Address set
(objectcategory=person)(mail=*)
Finds all Users with no Email Address
(objectcategory=person)(!mail=*)
Find all Users, Groups or Contacts where Company or Description is Contractors
(|(objectcategory=user)(objectcategory=group)(objectcategory=contact))(|(description=North*)(company=Contractors*))
Find all Users with Mobile numbers 712 or 155
(objectcategory=user)(|(mobile=712*)(mobile=155*))
Find all Users with Dial-In permissions
(objectCategory=user)(msNPAllowDialin=TRUE)
Find All printers with Color printing capability
Note: server name must be changed
(&(&(&(uncName=*Servername*)(objectCategory=printQueue)(printColor=TRUE))))
Find Users Mailboxes Overriding Exchange Size Limit Policies
(&(&(&objectCategory=user)(mDBUseDefaults=FALSE)))
Find all Users that need to change password on next login.
(&(objectCategory=user)(pwdLastSet=0))
Find all Users that are almost Locked-Out
Notice the “>=” that means “Greater than or equal to”.
(objectCategory=user)(badPwdCount>=2)
Find all Computers that do not have a Description
(objectCategory=computer)(!description=*)
Find all users with Hidden Mailboxes
(&(objectCategory=person)(objectClass=user)(msExchHideFromAddressLists=TRUE))
Find all Windows 2000 SP4 computers
(&(&(&(objectCategory=Computer)(operatingSystem=Windows 2000 Professional)(operatingSystemServicePack=Service Pack 4))))
Find all Windows XP SP2 computers
(&(&(&(&(&(&(&(objectCategory=Computer)(operatingSystem=Windows XP Professional)(operatingSystemServicePack=Service Pack 2))))))))
Find all Windows XP SP3 computers
(&(&(&(&(&(&(&(objectCategory=Computer)(operatingSystem=Windows XP Professional)(operatingSystemServicePack=Service Pack 3))))))))
Find all Vista SP1 computers
(&(&(&(&(sAMAccountType=805306369)(objectCategory=computer)(operatingSystem=Windows Vista*)(operatingSystemServicePack=Service Pack 1)))))
Find All Workstations
(sAMAccountType=805306369)
Find all 2003 Servers Non-DCs
(&(&(&(samAccountType=805306369)(!(primaryGroupId=516)))(objectCategory=computer)(operatingSystem=Windows Server 2003*)))
Find all 2003 Servers – DCs
(&(&(&(samAccountType=805306369)(primaryGroupID=516)(objectCategory=computer)(operatingSystem=Windows Server 2003*))))
Find all Server 2008
(&(&(&(&(samAccountType=805306369)(!(primaryGroupId=516)))(objectCategory=computer)(operatingSystem=Windows Server 2008*))))

referência: http://www.kreslavsky.com/2008/08/active-directory-saved-queries-templates.html

Wednesday, February 1, 2012

Wallpaper does not load in Windows 7 via GPO

A known bug in Windows 7 and Windows Server 2008 R2 is for the loading of the wallpaper, when it is configured via GPO.

To solve the problem, we can take the following actions:

  • Enter the machine's registry ( http://en.kioskea.net/faq/589-how-to-open-registry )
  • Navigate to the following key:
    • HKEY_CURRENT_USER \ Control Panel \ Desktop
  • Find the REG_SZ value called Wallpaper
  • Change the value with the path where the wallpaper is shared.

image

You can download a fix that will make the change:

If necessary change on multiple workstations, we can effect such change through thePreferences via GPO. As the image below:

image

If your domain is Windows Server 2003 and either does not support the Preferences feature, you need the distribution via script to make the change key in the registry.

The following example:

Const HKEY_CURRENT_USER = & H80000001

strComputer = "."
Set oReg = GetObject ("winmgmts: {ImpersonationLevel = impersonate}! \ \" & _
strComputer & "\ root \ default: StdRegProv")
strKeyPath = "Control Panel \ Desktop"
strValueName = "Wallpaper"
strValue = "\ \ server \ share \ wallpaper.jpg"
oReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue

Libraries and removes the Control Panel icon from the desktop

Personal

This tip can be useful when we set a very restrictive policy in Windows 7 ... .. when we forced the classic theme, the system includes a shortcut on the desktop shell of theLibraries folder and Control Panel. Via GPO until you remove the shortcuts, but it is also remove any link placed on the desktop, even if it is created via logon script ...

The method I found to solve this hurdle, it was deleting the following registry keys:

Remove icon library:

Remove icon in Control Panel:

For those who need to do a VBS for this ... ... follows:

Const HKEY_LOCAL_MACHINE = & H80000002
strComputer = "."
on error resume next
Set oReg = GetObject ("winmgmts: {ImpersonationLevel = impersonate}! \ \" & _
strComputer & "\ root \ default: StdRegProv")
strKeyPath =
strKeyPath =
strKeyPath =
oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath

I hope it's useful!