Skip to main content

Posts

Showing posts with the label MOC 10135

Expire and Un-Expire User Accounts with PowerShell

In class we had a project that required us to read in a text file that started with a users email address and then was followed by dates on the same line.  The data file appeared as below JDoe@contoso.com,1/12/2012,1/13/2012,1/14,2012 JaneD@contoso.com,2/3/2012,3/4/2012 The requirement was for this script to run every morning and expire any accounts who had a date that matched the current date.  Also, any accounts who’s expiration date was the previous day needed to be un-expired.  Below is the code to do it.   <# Function : Test - File Verifies that a file exists . Returns True is the file is present . #> Function Test-File { param ( $FilePath , $FileName ) $TestPath = $FilePath + "\" + $FileName $FileReady = Test-Path -path $TestPath Write-output $FileReady } #End: Test File <# . SYNOPSIS Confirms if a module is available . . DESCRIPTION Confirms if the provided parameter is available on the local c...

How to extract the file permissions of every file and folder, and subfolder, inside of a share.

The objective of this one liner is to allow you to enumerate all the shares on a client. Then recurse through the files and folders to get the NTFS permissions on each. Get-WmiObject Win32_Share | Select-Object – Property Path | Get-ChildItem – recurse | get-acl To get only directorys: Get-WmiObject Win32_Share | Select-Object – Property Path | Get-ChildItem – recurse | Where-Object { $_ . mode – match “ d ” } | get-acl To only get information on files: Get-WmiObject Win32_Share | Select-Object – Property Path | Get-ChildItem – recurse | Where-Object { $_ . mode – notmatch “ d ” } | get-acl

Case Sensitive PowerShell–Contains Comparison Operator

In PowerShell, you can test to see if a variable or array contains a specific piece of data.  Take the following example: $Arr1 = "PowerShell" , "Rocks" , "The" , "Windows" , "World" If I was interested in knows if this array contained the string “rocks”, I would execute this command: $Arr1 -contains "rocks" The response would be True .  Notice that in the array, the data is spelled with a capitol letter.  The query used a lower case letter.  PowerShell has a case sensitive contains operator called ccontains.  When the same query is executed, but this time with ccontains , the answer returned is False .  If the query was changed to $Arr1 -ccontains "Rocks" Then the response would be True

Get the Access Control List entries on a resource using PowerShell

PowerShell comes with the Get-ACL cmdlet that allows you to see who has security rights to a resource  Below is the syntax: (Get-ACL –Path path ).Access The path is a location (eg. C:\Logs) that you want to enumerate the ACL for. We first need to create the ACL object before we can view it.  To do that, we encase part of this command in parenthesis.  Once the command completes, we ask for the Access properties.  Below is sample output. FileSystemRights  : FullControl AccessControlType : Allow IdentityReference : BUILTIN\Administrators IsInherited       : True InheritanceFlags  : None PropagationFlags  : None FileSystemRights  : 268435456 AccessControlType : Allow IdentityReference : BUILTIN\Administrators IsInherited       : True InheritanceFlags  : ContainerInherit, ObjectInherit PropagationFlags  : InheritOnly FileSystemRights  : FullControl AccessControlType : Al...

How to get the members of a array, and not the members of the objects in the array in PowerShell

Let’s start off by explaining the situation by creating an array. $myArray = 1 , 2 , 3 , 4 If I execute $myArray | Get-Member I get the member information for the integer objects in the array: TypeName: System.Int32   Name MemberType Definition CompareTo Method int … Equals Method bool … GetHashCode Method int … GetType Method type GetType … GetTypeCode Method System.TypeCode GetTypeCode() … ToString Method string …   However, If I execute $MyArray.count , I get a value of 4 .  Where did this count property come from?  By looking at the members above, the count property is not listed.  The Count property can from the object of the array, not the objects contained in the array.  To see the members of the object array, type: Get-Member -InputObject $MyArray This will give you the members of the object of $MyArray.  Below is a listing of what you will receive.   Name              ...

How to set up a security group to be email enabled

In an Exchange environment, only Universal Groups can be emailed enabled. To convert a Global or Domain Local group to a Universal Group: - Open the properties of the group. - In the Group Scope box, click Universal . - Click OK . To mail enable the group: - Click Start à All Programs à Microsoft Exchange Server 2010 à Exchange Management Console - Expand Microsoft Exchange à Microsoft Exchange On-Premises à Recipient Configuration - Click Distribution Group . - Click New Distribution Group in the Action pane. - Select Existing Group and click Browse . - Click the group and then click OK . - Click Next - Provide an Alias for the group and click Next - Click New - Click Finish The group is now email enabled. To email enable an existing universal group with powershell: - Click Start à All Programs à Microsoft Exchange Server 2010 à Exchange Management Shell - We will assume the name of the group is Group1 with an SMTP address of Cont...

Create a new public folder using PowerShell

Public folders are a common way people exchange information in an exchange environment. Even though the GUI is simple to use, you may need to create or work with public folders in mass. The example below will create a public folder using the PowerShell cmdlet New-PublicFolder . We are going to create a new public folder called HR on the server Exch04. · On your Exchange 2010 server, open the Exchange Management Shell . · Type New-PublicFolder –Name HR –server Exch04 If you check the Public Folder Management Console (look for it in the Tools of the Exchange Management Console) you will see your new public folder. For a complete description of the New-PublicFolder cmdlet, type Get-Help New-PublicFolder -Full in your Exchange Management Shell.

Control how often a warning message is sent to users in Exchange 2010

By default, Exchange 2010 sends a warning email to all users every day at 1:00 AM. In the past, I’ve often needed users to be more aware of their utilization. Especially if we were approaching storage capacities. You can create a custom schedule to send more notices throughout the day if needed. · Open the Exchange Management Console. · Expand Organization Configuration . · Click Mailbox . · Right click the database you want to configure and select Properties . · Click the Limits tab · Click Customize · Configure your notification schedule and then click OK . · In the drop down box, click Use Custom Schedule . · Click OK . To configure the notification schedule with PowerShell by using the –QuotaNotificationSchedule switch with the Set-MailboxDatabase cmdlet. Here is an example Set-MailboxDatabase –identity “ ” –QuotaNotificationSchedule “Mon.9:00-Mon.10:00”, “Wed.9:00-Wed...

Unable to get Exchange 2010 Console to log into its On-Premises Server

This issue is geared more towards MCTs getting ready to instruct 10135. In very rare cases, it may apply to production environments as well. The situation is the first boot of the virtual machine 10135A-VAN-EX1. When you open the Exchange Management Console and click Microsoft Exchange On-Premises (can-ex1.adatum.com) , you receive the following message: exception calling "GetComputerSite" with "0" argument(s): "The computer is not in a site." It was running the command ‘Discover-ExchangeServer –UseWIA $true –SuppressError $true’. When opening the Exchange Management Shell, you are not able to connect with the error: [van-ex1.adatum.com] Connecting to remote server failed with the following error message : WinRM cannot process the requet. The following error occured while using Kerberos authentication: There are currently no logon server availible to service the logon request. A quick check of the DC showed that it did not have a static IP address. Aft...