Category: Microsoft Windows PowerShell

Microsoft Exchange Server 2007 – List Email Forwarding

You may use the script below in the Exchange Management Shell to list all mailboxes that are forwarding in Microsoft Exchange Server 2007.

<#
.SYNOPSIS
This script will provide a list of all Microsoft Exchange 2007 email addresses that are forwarding emails.
.DESCRIPTION
This script will automate the process of creating a list of all Microsoft Exchange 2007 email addresses that are forwarding emails.
.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?”

#Provide a list of all email addresses that are forwarding emails
Get-Mailbox | Where {$_.ForwardingAddress -ne $null} | Select Name, SamAccountName, PrimarySmtpAddress, ForwardingAddress, DeliverToMailboxAndForward | Out-File -filepath “<<<INSERT PATH>>>\$File.txt”


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)}}


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