Archive for the ‘PowerShell’ Category

Update AD EmployeeNumber Attribute From CSV File

Wednesday, June 4th, 2014

2014-06-04 Initial Post

The other month I needed to update the EmployeeNumber attribute of all Active Directory user accounts based on a CSV file generated from Oracle HRMS. You may modify this script to update a different attribute, such as EmployeeID.

#Script updated 2014-03-31, created 2014-03-06, by SysAdmin-E.com.
#PURPOSE: Takes a CSV input file that contains "E-mailAddress,EmployeeNumber" on each line (DO NOT include header in CSV file).
# Searches AD for user account that has the e-mail address as its primary address.
# If found, update that respective AD account with the corresponding EmployeeNumber.
#There is some limited error checking and a status file is generated after script completion.
#I was not able to get the Import-Csv command to work correctly so I used Get-Content to grab data from the input file.
#Tested against Windows Server 2008 R2 SP1 AD.
$strFilePathInput = "X:\TempPowerShell\setAD-EmployeeNumberINPUT.csv"
$strFilePathOutput = "X:\TempPowerShell\setAD-EmployeeNumberOUTPUT.csv"
Get-Content $strFilePathInput | ForEach-Object{
$strUserInfoLineFromFile = $_
$strUserEmailAddress = $strUserInfoLineFromFile.Split(",")[0]
$strUserEmployeeNumber = $strUserInfoLineFromFile.Split(",")[1]
If($objADuser = Get-ADUser -Filter {mail -eq $strUserEmailAddress }) #The mail attribute is the primary/reply e-mail address.
{
Set-ADUser $objADuser -EmployeeNumber $strUserEmployeeNumber
If($?) #If True, which means previous command (set EmployeeNumber) was successful. Invalid e-mail address or insufficient AD permissions will make this False.
{
"OK - Updated," + $strUserInfoLineFromFile | Out-File -Append $strFilePathOutput
}
Else
{
"ERROR - Could not update," + $strUserInfoLineFromFile | Out-File -Append $strFilePathOutput
}
}
Else
{
"E-mail address has no primary match," + $strUserInfoLineFromFile | Out-File -Append $strFilePathOutput
}
}
Exit

VMware vSphere Hypervisor (ESXi 4.1) Test Lab Configuration Notes

Wednesday, June 20th, 2012

2012-06-20 Updated

2010-12-22 Initial Post

I've never had a chance to work with any version of VMware at work. My last company was so far behind in its IT strategy that even in late 2009 it had absolutely no virtualization strategy at all. I did manage to set up one Hyper-V server for them so that one department could use it for software testing. Where I work now, they do use VMware, but they don't use them on any of the messaging servers that I support. So once again, I have no chance to work with VMware. (more…)

New-MailboxExportRequest – How To Export Multiple Well-Known Folder Names

Monday, December 5th, 2011

2011-12-05 Initial Post

A few weeks ago I was trying to get a command together to export only the Calendar and Contacts folders from all mailboxes on an Exchange Server 2010 SP1 mailbox database. (more…)

Exchange 2010 Outlook Web App Calendar URL – Incorrect URL in MS Article 232199 / Permission Error

Thursday, May 26th, 2011

2011-05-26 Initial Post

Exchange Server 2010 Enterprise SP1 RU3

The other day we needed to give all users reviewer permission to our conference room mailboxes and allow the users to access the rooms’ calendars via a direct OWA URL on a SharePoint site. I used the example in the article “Using Outlook Web App Web Parts” at http://technet.microsoft.com/en-us/library/bb232199.aspx. Under the Enter Outlook Web App Web Parts manually section of that article, the URL example it gives is https://email.fourthcoffee.com/owa/tsmith@fourthcoffee.com/?cmd=contents&f=calendar&view=weekly. (more…)

Get Logical Disk Size and Percentage of Free Disk Space with PowerShell

Saturday, May 21st, 2011

2011-05-21 Initial Post

Tested with PS v2 on Windows 7 and Server 2008 R2

I've found a few commands for getting disk size and free space but I wanted percentage of free space also. I modified one of the commands that I found by adding additional commands to show the percentage of free space. Note that DriveType=3 means local disk.

Get-WMIObject Win32_LogicalDisk -Filter "DriveType=3" -Computer . | Select SystemName, DeviceID, VolumeName, @{Name="Total Size (GB)"; Expression={"{0:N1}" -F ($_.Size/1GB)}}, @{Name="Free Space (GB)"; Expression={"{0:N1}" -F ($_.Freespace/1GB)}}, @{Name="Free Space %"; Expression={"{0:N1}" -F (($_.Freespace/$_.Size)*100)}} | FT -AutoSize

The output is below, but it doesn't line up properly in Outlook when I use the output string in an e-mail. I haven't had a chance to play around with the formatting.

SystemName     DeviceID VolumeName  Total Size (GB) Free Space (GB) Free Space %
----------     -------- ---------- --------------- --------------- ------------
Server001          C:        C-System    116.5             79.8              68.5
Server001          X:        X-Util      116.4             102.8             88.3