Month: July 2016

Microsoft Exchange Server 2007 – Configure Public Folder Permissions

The Microsoft Windows PowerShell script below may be run with the Exchange Management Shell to automate the configuration of public folder permissions in Microsoft Exchange Server 2007. Additionally, you may modify the script by manually adding a list of public folders (which is included in the EXAMPLE section) to help with further automation of configuring public folder permissions.

<#
.SYNOPSIS
This script will apply access rights to a user for a public folder and it’s subfolders in Microsoft Exchange 2007.
.DESCRIPTION
This script will automate the process of applying access rights to a user for a public fodler and it’s subfolders in Microsoft Exchange 2007.
.EXAMPLE
Get-PublicFolder -Identity “\Departments\Accounting” -Recurse | Add-PublicFolderClientPermission -User $User -AccessRights $Access
Get-PublicFolder -Identity “\Departments\Information Technology” -Recurse | Add-PublicFolderClientPermission -User $User -AccessRights $Access
Get-PublicFolder -Identity “\Departments\Marketing” -Recurse | Add-PublicFolderClientPermission -User $User -AccessRights $Access
.AUTHOR
Written by Noel Enrique Alvarez on Thursday, March 24, 2016.
#>

#Request the Microsoft Exchange public folder
$Folder = Read-Host “What is the path to the Microsoft Exchange public folder?”

#Request the user’s Microsoft Active Directory display name
$User = Read-Host “What is the user’s Microsoft Active Directory display name?”

#Request the users access right
$Access = Read-Host “What access right should be applied to user (i.e. Editor)?”

#Configure the access right on the Microsoft Exchange Public Folder for the Microsoft Active Directory user
Get-PublicFolder –Identity $Folder –Recurse | Add-PublicFolderClientPermission –User $User –AccessRights $Access


Microsoft Active Directory – Export Group Members

The Microsoft Windows PowerShell script below will the export the list of users from a Microsoft Active Directory group to a notepad (.txt) file. You may modify the script to provide a file format of your choice.

<#

.SYNOPSIS
This script will provide the members of a Microsoft Active Directory group and export them to a notepad (.txt) file.
.DESCRIPTION
This script automates the process of exporting the users in a Microsoft Active Directory group.
.EXAMPLE
N/A.
.AUTHOR
Written by Noel Enrique Alvarez on Thursday, March 17, 2016.
#>

#Import the Microsoft Active Directory module
Import-Module ActiveDirectory

#Request the name of the Microsoft Active Directory group
$GROUP = Read-Host “What is the name of the Microsoft Active Directory group?”

#Export the members of the Microsoft Active Directory group and export them.
Get-ADGroupMember -identity $GROUP | Select Name, SamAccountName | out-file -filepath “<<<INSERT PATH>>>\$GROUP.txt”


Microsoft Active Directory – Verify the Status of User Accounts

The Microsoft Windows PowerShell script below will verify the status, enabled or disabled, of Microsoft Active Directory user accounts.

<#
.SYNOPSIS
This scrip will query a list of SAMAccountNames from a notepad (.txt) file and provide the Name and Enabled status.
.DESCRIPTION
This script will automate the process of querying a list of SAMAccountNames and provide the Name and Enabled status.
.EXAMPLE
N/A.
.AUTHOR
Written by Noel Enrique Alvarez on Thursday, March 24, 2016.
#>

#Import the Microsoft Active Directory module
Import-Module ActiveDirectory

#Provide the path to the Notepad (.txt) file that contains the list of SAMAccountNames
$– USERS = Get-Content “<<<INSERT PATH>>>\Users.txt”

#Query the list of users and provide the output in the specified comma seperate value (.csv) file
$– USERS | ForEach {Get-ADUser $_ -Properties * | Select SAMAccountName, Name, Enabled} | Export-CSV -Path “<<<INSERT PATH>>>\Users.csv”


Scripting – List Remote Hard Disk Space

You may use the script below to query a list of remote servers for their drive letters, drive sizes, and the amount of free space on each drive in gigabytes (GB).

<#
.SYNOPSIS
This script will provide the drive letter, drive size and free space of a list of servers.
.DESCRIPTION
This script will automate the process of providing the drive letter, drive size and free space of a list of servers.
.EXAMPLE
N/A.
.AUTHOR
Written by Noel Enrique Alvarez on Wednesday, March 23, 2016.
#>

#Provide the hard drive information for the servers in the Remote_Servers.txt file
$Computers = Get-Content “<<<INSERT PATH>>>\Remote_Servers.txt”
gwmi Win32_LogicalDisk -Computer $Computers -Filter ‘DriveType = 3′ `
| select SystemName, DeviceID,
@{n=’Size’;e={[int]($_.Size/1GB)}},
@{n=’FreeSpace’;e={[int]($_.FreeSpace/1GB)}}


Scripting – List Local Hard Disk Space

You may use the script below to query the drive letters, drive sizes, and the amount of free space on each drive in gigabytes (GB) for the local host.

<#
.SYNOPSIS
This script will provide the drive letter, drive size and free space of the local server.
.DESCRIPTION
This script will automate the process of providing the drive letter, drive size and free space of the local server.
.EXAMPLE
N/A.
.AUTHOR
Written by Noel Enrique Alvarez on Wednesday, March 23, 2016.
#>

#Provide the hard drive information for the local server
Get-WmiObject Win32_LogicalDisk -Filter ‘DriveType = 3′ `
| select SystemName, DeviceID,
@{n=’Size’;e={[int]($_.Size/1GB)}},
@{n=’FreeSpace’;e={[int]($_.FreeSpace/1GB)}}


Dell Compellent – Verify Front and Back End Ports

You may use the Dell Enterprise Manager Data Collector Manager to configure the SMTP settings of a Dell Compellent Storage Area Network (SAN) and provide you with alerts. In addition to this you may manually verify that the front and back end ports of the storage array are Up. To do so navigate to Dell Storage > Storage CentersStorage Center > Fault Domains. As you can see from the output below all of the ports are Up.

01

02


Scripting – Dell iDRAC 8 User

You may use the script below to delete a user account from an Integrated Dell Remote Access Controller 8 (iDRAC8). I would like to acknowledge that I did not write this script and the original link may be found here.

<#
.SYNOPSIS
Removes a DRAC user.
.DESCRIPTION
Removes a DRAC user. Requires Dell’s RACADM.EXE utility, which is distributed as part of the Dell DRAC Tools kit.
.PARAMETER TargetSystem
The IP address or hostname of the target system.
.PARAMETER Index
The numerical index of the user to remove.
.EXAMPLE
Remove-DRACUser -TargetSystem 192.168.100.20 -Index 4
#>

[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact=”High”)]
param(
[Parameter(Mandatory=$true, HelpMessage=”Enter the hostname or IP address of the target”)]
[String]$TargetSystem,

[Parameter(Mandatory=$true, HelpMessage=”Enter the index of the user to remove”)]
[ValidateRange(3, 16)]
[Int32]$Index
)

BEGIN
{
New-Variable -Name RACADMExe -Value “C:\Program Files\Dell\SysMgt\rac5\racadm.exe”
New-Variable -Name RACRootUser -Value “root” -Option Constant
New-Variable -Name RACRootUserPass -Value “7Re`$rupU” -Option Constant
$UserToRemove = “”
}
PROCESS
{
$Error.Clear()
Write-Verbose “Checking for existence of racadm.exe”
if(!(Test-Path -Path $RACADMExe))
{
Write-Error “Run this script from the folder that contains racadm.exe”
return
}

Write-Verbose “Attempting to connect to $TargetSystem”
[String[]]$RawResult = & $RACADMExe -r $TargetSystem -u $RACRootUser -p $RACRootUserPass getconfig -g cfgUserAdmin -i $Index 2>&1

foreach($RawLine in $RawResult)
{
if($RawLine -cmatch “^ERROR”)
{
Write-Error $RawLine
return
}
elseif($RawLine -match “^cfgUserAdminUserName=(.*)”)
{
$UserToRemove = $Matches[1]
}
}
if([String]::IsNullOrEmpty($UserToRemove))
{
Write-Error “No user found at index $Index”
return
}
if($PSCmdlet.ShouldProcess($UserToRemove, “Remove DRAC user”))
{
Write-Verbose “Attempting delete…”
[String[]]$RawDeleteResult = & racadm -r $TargetSystem -u $RACRootUser -p $RACRootUserPass config -g cfgUserAdmin -o cfgUserAdminUserName -i $Index `”`” 2>&1
foreach($RawDeleteLine in $RawDeleteResult)
{
if($RawDeleteLine -cmatch “^ERROR”)
{
Write-Error $RawDeleteLine
return # only necessary for future-proofing, in case other script is added beyond this
}
if($RawDeleteLine -match “successfully”)
{
Write-Verbose “Deletion of $UserToRemove was successful.”
}
}
}
}
END {}


Microsoft Windows Server 2012 R2 Core – Rename Network Interface Card

You may use the following the following command to rename a network interface card (NIC) using Windows PowerShell in Microsoft Windows Server 2012 R2 Core. In this particular example the NIC is being renamed from Ethernet0 to LAN01.

 

Rename-NetAdapter -Name Ethernet0 -NewName LAN01


Microsoft Windows Server 2012 R2 Core – Configure Hostname

After logging into a Microsoft Windows Server 2012 R2 Core installation you may use the following commands to configure the hostname of the server.

1. powershell
2. hostname
3. Rename-Computer HOSTNAME
4. shutdown -r -t 00


Group Policy Object – Disable Windows PowerShell

You may use a Microsoft Active Directory (AD) Group Policy Object (GPO) to restrict access to the Windows PowerShell. Below you will find the settings for this configuration.

Computer Configuration > Policies > Windows Settings > Security Settings > Software Restrictions > Additional Rules

Right click Additional Rules and select New Path Rule…. In the New Path Rule dialog box, enter C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe for the Path:, and select Disallowed for the Security level:, then click OK.