Author: Noel Alvarez

Microsoft Exchange Server 2007 – List Email Addresses

You may use the script below in the Exchange Management Shell to list the primary email address of each mailbox in Microsoft Exchange Server 2007.

<#
.SYNOPSIS
This script will provide a list of all Microsoft Exchange users and their primary email address then provide the results in a text file.
.DESCRIPTION
This script will automate the process of providing a list of all Microsoft Exchange users and their primary email address then provide the results in a text file.
.EXAMPLE
N/A.
.AUTHOR
Written by Noel Enrique Alvarez on Thursday, March 24, 2016.
#>

#Request the name of the output file
$File = Read-Host “What would you like to name the file?”

#List all of the Microsoft Exchange users and their primary email address then provide the results in a text file
Get-Mailbox | Select Name, SamAccountName, PrimarySmtpAddress | format-list | Out-File -filepath “<<<INSERT PATH>>>\$File.txt”


Microsoft Exchange Server 2007 – List Public Folder Permissions

You may use the script below in the Exchange Management Shell to list public folder permissions in Microsoft Exchange Server 2007.

<#
.SYNOPSIS
This script will list a public folder and it’s subfolders in Microsoft Exchange 2007.
.DESCRIPTION
This script will automate the process of listing a public folder and it’s subfolders in Microsoft Exchange 2007.
.EXAMPLE
N/A.
.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?”

#List the Microsoft Exchange Server 2007 public folder and it’s subfolder
Get-PublicFolder –Identity $Folder -Recurse


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