Thursday, December 14, 2006

Quick Create Mailbox Powershell Form for Exchange 2007

A lot of times when your evaluating or testing code you may want to create some temporary mailboxes very quickly to test this or that. In Exchange 2007 the Exchange Command Shell’s new-mailbox commandlet gives a quick way of doing this. But because of the complexities of actually creating a mailbox eg knowing the Conical name of the OU and the name of the database you want to put it into etc actually typing all these values isn’t a fast or easy task. If your scripting this its not such a big deal because when your creating the script you can just cut and paste the values into your script and then you can run the thing a number of times and not have to worry about it. The Exchange Management Console provides wizards to create a mailbox but like all wizards they are designed to be easy to use not fast. So what I decided to do was see if I could put together a small 1 page form that you could run from the Exchange Command shell that would allow me to quickly put in the information that I wanted and then call the New-Mailbox commandlet to create the account.

Using the example from get-help new-mailbox as a template I created a form and populated it with textboxes to allow input of


To remove the requirement of knowing the canonical name of the OU and exact servername and database name I used Comboboxes for these values and then wired these to some other code and cmdlets to fill the values in the drop downs.

For the OU Name box an ADSI query of all the OU’s in the domain is used to populate the OU Name dropdown . For the Servername box the get-mailboxserver cmdlet is used to populate the list of mailbox servers. The servername combobox has one wired event so when a servername is select the get-mailboxdatabase cmdlet is run to then populate the Mailstore combobox for the selected severname. If the servername is change the Mailstore dropdown values should also change (to be honest I didn’t test this because I don’t have more the one server)

The password box is just a textbox as well with the UseSystemPasswordChar property set true to provide the normal password masking.

The rest of the codes is relatively simple I used some hashtables to mask some of the values to make them more practical to use in a Winform such as trimming the domain from the conical name. But the rest of the code just builds the form and then builds the new-mailbox command. The result of the command is written back to the commandline so any error messages will be displayed there.

The script only runs in the Exchange Command Shell because it’s using the Exchange cmdlets to do the work. I’ve put a down-loadable copy of the code here the code itself looks like.


Function createmailbox{
$psSecurePasswordString = new-object System.Security.SecureString
foreach($char in $pwPassWordTextBox.Text.ToCharArray())
$result = New-mailbox -UserPrincipalName $unUserNameTextBox.text -alias $emAliasTextBox.text -database $MBhash1[$msMailStoreDrop.SelectedItem.ToString()] `
-Name $dsDisplayNameTextBox.text -OrganizationalUnit $OUhash1[$ouOuNameDrop.SelectedItem.ToString()] -password $psSecurePasswordString `
-FirstName $unFirstNameTextBox.text -LastName $lnLastNameTextBox.text -DisplayName $dsDisplayNameTextBox.text
$msgbox = new-object -comobject
if ($result -ne $null){write-host "Mailbox Created Sucessfully"}
else{write-host "Error Creating Mailbox check command Line for Details"}


$OUhash1 = @{ }
$MBhash1 = @{ }

$form = new-object System.Windows.Forms.form
$form.Text = "Exchange 2007 Quick User Create Form"
$form.size = new-object System.Drawing.Size(430,400)

# Add UserName Box
$unUserNameTextBox = new-object System.Windows.Forms.TextBox
$unUserNameTextBox.Location = new-object System.Drawing.Size(100,30)
$unUserNameTextBox.size = new-object System.Drawing.Size(130,20)

# Add Username Lable
$unUserNamelableBox = new-object System.Windows.Forms.Label
$unUserNamelableBox.Location = new-object System.Drawing.Size(10,30)
$unUserNamelableBox.size = new-object System.Drawing.Size(100,20)
$unUserNamelableBox.Text = "Username UPN"

# Add Alias Box
$emAliasTextBox = new-object System.Windows.Forms.TextBox
$emAliasTextBox.Location = new-object System.Drawing.Size(100,60)
$emAliasTextBox.size = new-object System.Drawing.Size(130,20)

# Add Alias Lable
$emAliaslableBox = new-object System.Windows.Forms.Label
$emAliaslableBox.Location = new-object System.Drawing.Size(10,60)
$emAliaslableBox.size = new-object System.Drawing.Size(100,20)
$emAliaslableBox.Text = "Alias"

# Add FirstName Box
$unFirstNameTextBox = new-object System.Windows.Forms.TextBox
$unFirstNameTextBox.Location = new-object System.Drawing.Size(100,90)
$unFirstNameTextBox.size = new-object System.Drawing.Size(130,20)

# Add FirstName Lable
$unFirstNamelableBox = new-object System.Windows.Forms.Label
$unFirstNamelableBox.Location = new-object System.Drawing.Size(10,90)
$unFirstNamelableBox.size = new-object System.Drawing.Size(60,20)
$unFirstNamelableBox.Text = "First Name"

# Add LastName Box
$lnLastNameTextBox = new-object System.Windows.Forms.TextBox
$lnLastNameTextBox.Location = new-object System.Drawing.Size(100,120)
$lnLastNameTextBox.size = new-object System.Drawing.Size(130,20)

# Add LastName Lable
$lnLastNamelableBox = new-object System.Windows.Forms.Label
$lnLastNamelableBox.Location = new-object System.Drawing.Size(10,120)
$lnLastNamelableBox.size = new-object System.Drawing.Size(60,20)
$lnLastNamelableBox.Text = "Last Name"

# Add DisplayName Box
$dsDisplayNameTextBox = new-object System.Windows.Forms.TextBox
$dsDisplayNameTextBox.Location = new-object System.Drawing.Size(100,150)
$dsDisplayNameTextBox.size = new-object System.Drawing.Size(130,20)

# Add DisplayName Lable
$dsDisplayNamelableBox = new-object System.Windows.Forms.Label
$dsDisplayNamelableBox.Location = new-object System.Drawing.Size(10,150)
$dsDisplayNamelableBox.size = new-object System.Drawing.Size(100,20)
$dsDisplayNamelableBox.Text = "Display Name"

# Add OU Drop Down
$ouOuNameDrop = new-object System.Windows.Forms.ComboBox
$ouOuNameDrop.Location = new-object System.Drawing.Size(100,180)
$ouOuNameDrop.Size = new-object System.Drawing.Size(230,30)
$root = [ADSI]''
$searcher = new-object System.DirectoryServices.DirectorySearcher($root)
$searcher.Filter = '(objectClass=organizationalUnit)'
$searcher1 = $searcher.FindAll()
foreach ($person in $searcher1){
[string]$ent = $person.Properties.canonicalname

# Add OU DropLable
$ouOuNamelableBox = new-object System.Windows.Forms.Label
$ouOuNamelableBox.Location = new-object System.Drawing.Size(10,180)
$ouOuNamelableBox.size = new-object System.Drawing.Size(100,20)
$ouOuNamelableBox.Text = "OU Name"

# Add Server Drop Down
$snServerNameDrop = new-object System.Windows.Forms.ComboBox
$snServerNameDrop.Location = new-object System.Drawing.Size(100,210)
$snServerNameDrop.Size = new-object System.Drawing.Size(130,30)
get-mailboxserver | ForEach-Object{$snServerNameDrop.Items.Add($_.Name)}
get-mailboxdatabase -Server $snServerNameDrop.SelectedItem.ToString()| ForEach-Object{$msMailStoreDrop.Items.Add($_.Name)
$MBhash1.add($_.Name,$_.ServerName + "\" + $_.StorageGroup.Name + "\" + $_.Name)

# Add Server DropLable
$snServerNamelableBox = new-object System.Windows.Forms.Label
$snServerNamelableBox.Location = new-object System.Drawing.Size(10,210)
$snServerNamelableBox.size = new-object System.Drawing.Size(100,20)
$snServerNamelableBox.Text = "ServerName"

# Add MailStore Drop Down
$msMailStoreDrop = new-object System.Windows.Forms.ComboBox
$msMailStoreDrop.Location = new-object System.Drawing.Size(100,240)
$msMailStoreDrop.Size = new-object System.Drawing.Size(130,30)

# Add MailStore DropLable
$msMailStorelableBox = new-object System.Windows.Forms.Label
$msMailStorelableBox.Location = new-object System.Drawing.Size(10,240)
$msMailStorelableBox.size = new-object System.Drawing.Size(100,20)
$msMailStorelableBox.Text = "Mail-Store"

# Add Password Box
$pwPassWordTextBox = new-object System.Windows.Forms.TextBox
$pwPassWordTextBox.Location = new-object System.Drawing.Size(100,270)
$pwPassWordTextBox.size = new-object System.Drawing.Size(130,20)
$pwPasswordTextBox.UseSystemPasswordChar = $true

# Add Password Lable
$pwPassWordlableBox = new-object System.Windows.Forms.Label
$pwPassWordlableBox.Location = new-object System.Drawing.Size(10,270)
$pwPassWordlableBox.size = new-object System.Drawing.Size(60,20)
$pwPassWordlableBox.Text = "Password"

# Add Create Button

$crButton = new-object System.Windows.Forms.Button
$crButton.Location = new-object System.Drawing.Size(110,310)
$crButton.Size = new-object System.Drawing.Size(100,23)
$crButton.Text = "Create Mailbox"

$form.topmost = $true

Friday, December 08, 2006

Scripting Exchange Web Services (2007) with VBS and Powershell

I’ve been playing around with the new Exchange 2007 Web Services and thought I would share a few scripts. With a lot of API’s being deemphasized or disappearing completely in Exchange 2007, Exchange Web Services are the brave new world that confronts people who want to develop applications that run against an Exchange 2007 server. Like any other WebService EWS allows you to invoke different methods which will perform specific tasks by sending SOAP messages that contain certain properties and then receiving specifically formatted responses. For a scripting point of view it’s pretty easy firstly you need to authenticate the default authentication is NTLM so there is no need to worry about FBA synthetic logons and then it’s just a matter of posting a XML formatted SOAP message. If your familiar with using WebDAV the underlying methods you use are the same but the requests and responses are very different. Lets start with a simple send email example.

smSoapMessage = "<?xml version='1.0' encoding='utf-8'?>" _
& "<soap:Envelope xmlns:soap="""" " _
& " xmlns:xsi=""""
xmlns:xsd="""">" _
& "<soap:Body><CreateItem MessageDisposition=""SendAndSaveCopy"" " _
& " xmlns=""""> " _
& "<SavedItemFolderId><DistinguishedFolderId Id=""sentitems""
xmlns=""""/>" _
& "</SavedItemFolderId><Items><Message
xmlns="""">" _
& "<ItemClass>IPM.Note</ItemClass><Subject>" & stSubjet & "</Subject><Body
BodyType=""Text"">" & ebEmailBody & "</Body><ToRecipients>" _
& "<Mailbox><EmailAddress>" & EmailAddress &
"</EmailAddress></Mailbox></ToRecipients></Message></Items>" _
& "</CreateItem></soap:Body></soap:Envelope>"
set req = createobject("microsoft.xmlhttp")

The first thing you need to do is build a SOAP message for scripting I prefer to just to build the message manually as a string. You could use the XMLDOM object but this requires a lot more lines of code and complexity. This soap message is a CreateItem request that creates a message and saves it in the SentItems folder. The MessageDisposition Attribute controls how the Exchange server goes about handling this message after its received in this instance it is sent and also a copy is saved to the folder listed in the DistinguishedFolderId element.

set req = createobject("microsoft.xmlhttp")
req.Open "post", "http://" & servername & "/ews/Exchange.asmx", False,"domain\user", "password"
req.setRequestHeader "Content-Type", "text/xml"
req.setRequestHeader "translate", "F"
req.send smSoapMessage
wscript.echo req.status
wscript.echo req.responsetext

The IIS virtual directory you use to access the Exchange Webservice is http://Servername/EWS. If your send is successful you will see a Status of 200 returned if not you usually get a 50x error message. The response messages are usually pretty good for diagnosing what your doing wrong (its generally a formatting issue with the soap message).

Another method of interest is the GetFolder method which is roughly equivalent to a propfind in WebDAV in that it allows you to retrieve properties from a folder. Some properties of interest might be things like the foldersize or the unread message count on the inbox. The following is a SOAP request that can be used to get the unread message count on the inbox. (Switching from VBS to Powershell this time)

$smSoapMessage = "<?xml version='1.0' encoding='utf-8'?>" `
+ "<soap:Envelope xmlns:soap=`"`" " `
+ " xmlns:xsi=`"`" xmlns:xsd=`"`"" `
+ " xmlns:t=`"`" >" `
+ "<soap:Body>" `
+ "<GetFolder xmlns=`"`"
" `
+ " xmlns:t=`"`"> " `
+ "<FolderShape> " `
+ "<t:BaseShape>Default</t:BaseShape> " `
+ "</FolderShape> " `
+ "<FolderIds> " `
+ "<t:DistinguishedFolderId Id=`"inbox`"/> " `
+ "</FolderIds> " `
+ "</GetFolder> " `
+ "</soap:Body></soap:Envelope>"

The BaseShape element controls which properties are returned by the query the default set generally contains all the properties you need to do basic tasks (including the unread count). But if you want to get all the properties or include additional properties there are other elements to do this job.

$servername = "ws03r2eeexchlcs"
$strRootURI = "http://" + $servername + "/ews/Exchange.asmx"
$WDRequest = [System.Net.WebRequest]::Create($strRootURI)
$WDRequest.ContentType = "text/xml"
$WDRequest.Headers.Add("Translate", "F")
$WDRequest.Method = "Post"
$WDRequest.Credentials = $cdUsrCredentials
$bytes = [System.Text.Encoding]::UTF8.GetBytes($smSoapMessage)
$WDRequest.ContentLength = $bytes.Length
$RequestStream = $WDRequest.GetRequestStream()
$RequestStream.Write($bytes, 0, $bytes.Length)
$WDResponse = $WDRequest.GetResponse()
$ResponseStream = $WDResponse.GetResponseStream()
$ResponseXmlDoc = new-object System.Xml.XmlDocument
$UreadNameNodes = @($ResponseXmlDoc.GetElementsByTagName("t:UnreadCount"))
"Number of Unread Email : " + $UreadNameNodes[0].'#text'

The one important thing here when you are looking at the results returned by the EWS and your using getElementsByTagName method in Powershell is make sure you use the @ array specifier In front of the method call or you wont be able to index into the collection and access the elements. Authentication in Powershell can be handled in two ways if you want to specify which credentials to use you can use a credential object with a line such as

$cdUsrCredentials = new-object System.Net.NetworkCredential("Administrator", "Evaluation1", "CONTOSO")

And then set the request object to use those credentials

$WDRequest.Credentials = $cdUsrCredentials

Or you can specify to use the credentials from the user context that is invoking the script by setting the request object like

$WDRequest.UseDefaultCredentials = $True

The Last thing to look at is the restriction element this allows you to specify which items you want to return. So if you where to use the FindItem method to list items in your inbox and you wanted to just return those items that where unread and only 24 hours old then you could use something like this in the restriction section of the SOAP message.

+ "<Restriction>" `
+ "<t:And>" `
+ "<t:IsEqualTo>" `
+ "<t:FieldURI FieldURI=`"message:IsRead`"/>"`
+ "<t:FieldURIOrConstant>" `
+ "<t:Constant Value=`"0`"/>" `
+ "</t:FieldURIOrConstant>" `
+ "</t:IsEqualTo>" `
+ "<t:IsGreaterThanOrEqualTo>" `
+ "<t:FieldURI FieldURI=`"item:DateTimeSent`"/>"`
+ "<t:FieldURIOrConstant>" `
+ "<t:Constant Value=`"" + $datetimetoquery.ToUniversalTime().AddDays(-1).ToString("yyyy-MM-ddThh:mm:ssZ")
+ "`"/>"`
+ "</t:FieldURIOrConstant>"`
+ "</t:IsGreaterThanOrEqualTo>"`
+ "</t:And>"`
+ "</Restriction>"`

Like Exchange 200x when you query the Exchange store with a Datetime range that datetime range should be converted to the ISO dateformat and also because Exchange stores date and times in UTC you should convert the date and time you want to query for into UTC before you use it (and also convert the returned times back into Local time so they make sense). Powershell lets you tap into the .NET time conversion functions which makes things a lot simpler then they where in VBS.

I’ve created 4 scripts all up both in VBS and Powershell the scripts do the following tasks

Sendews : Sends a message using EWS
Ureadews : Reads the UnreadCount property of the inbox
Shureadews : Shows the Time,From,Subject and size of all unread messages in the inbox
Shureadewstday Shows the Time,From,Subject and size of all unread messages in the inbox just for the past 24 hours

I’ve put a downloadable copy of the script here.

Friday, December 01, 2006

Exchange SMTP Log file DNS Test tool Powershell script

This powershell script is a combination of some of my past scripts (in particular the DNS util script) wrapped up in a nice little GUI with buttons to make it easy to use on a daily basis. What this script does is allows you to open a SMTP log file (or if you don’t want to read the whole log file just a certain number of lines from a file) and it will then parse that log file into a DataGrid on a Winform. You can then select a line in the datagrid and use one of the Buttons provided to perform different DNS test on that log file entry. The tests it can do are

Reverse DNS query on the Source Mail server IP Address (from the log file)

MX lookup of the parsed domain name from a RCPT or MAIL SMTP command

SPF lookup of the parsed domain name from a RCPT or MAIL SMTP command

A Record lookup of the parsed domain name from a RCPT or MAIL SMTP command

RBL lookup of Source Mail Server IP Address (Using SORB’s or any other RBL you like). To configure which RBL server to use you need to modify the following line in the RBLLookup() function.

$RBLService = ""

Helo Banner Check does a connection to the Mail server source IP address and reports on the banner. To do this it creates a connection on Port 25 of the source mail server IP address then reads the response and then issues a Quit to end the connection.

Whois Lookup of the Source Mail Server IP Address using (or any other whois server you want to configure). This will only return results for IP’s and domains this whois server is authorative for or it will return a referral to the whois server you should be using.

I’ve created two versions of the script the second version does Geolocationing of the Source Mail server IP address and gives the option to resolve every IP address in the log file to a geographical location or just do single queries on the location of certain ip addresses. This is based on my previous post of Geolocationing Message tracking logs .The reason for creating two versions is that the second script is quire complex and blows out to the size to around 800 lines so I wanted to have a simple script for anyone who doesn’t care about geolocatiion. Personally I think it’s really useful if you’re trying to diagnose something with a SMTP log file.

The parsing section of the script uses the get-content commandlet to read the log file you select this commandlet allows you to pass in the number of lines you want it to read from a file or pass -1 and it will read everything. The one thing I wasn’t 100 % sure about is the file locking operation of this commandlet. If it does lock the file when its retrieving the content then this could be a bad thing if you where to open a live log file. If anyone knows the answer to this one please let me know I haven’t come across any issues thus far.

To use the script just run it from powershell and you should see it build and popup a Winfrom. Use the select file button which will popup a file browser to allow you to select the log file you want to use. To use the geolocation version please see my other post about where you need to obtain the download from the iptocountry.csv file and where to place it to make the script work correctly. If you’re using the Geolocation version and you want the ipaddress resolved to a county location make sure you select the Show Cnty check box.

I’ve put a download of this script here the whole script is a bit too large to post but here are some highlights.

function openLog{
$exFileName = new-object System.Windows.Forms.openFileDialog
$fnFileNamelableBox.Text = $exFileName.FileName
$tcountline = -1
if ($rbVeiwAllOnlyRadioButton.Checked -eq $true){$tcountline = $lnLogfileLineNum.value}
get-content $exFileName.FileName -totalCount $tcountline | %{
$linarr = $_.split(" ")
$lfDate = ""
$lfTime = ""
$lfSourceIP = ""
$lfHostName = ""
$lfDestIP = ""
$lfSMTPVerb = ""
$lfCommandText = ""
if ($linarr[0].substring(0, 1) -ne "#"){
if ($linarr.Length -gt 0){$lfDate = $linarr[0]}
if ($linarr.Length -gt 1){$lfTime = $linarr[1]}
if ($linarr.Length -gt 2){$lfSourceIP= $linarr[2]}
if ($linarr.Length -gt 3){$lfHostName = $linarr[3]}
if ($linarr.Length -gt 6){$lfDestIP = $linarr[6]}
if ($linarr.Length -gt 8){$lfSMTPVerb = $linarr[8]}
if ($linarr.Length -gt 10){$lfCommandText = $linarr[10]}

$dgDataGrid.DataSource = $logTable

Compile-Csharp $code
$form = new-object System.Windows.Forms.form
$form.Text = "SMTP Log Test Tool"
$Dataset = New-Object System.Data.DataSet
$logTable = New-Object System.Data.DataTable
$logTable.TableName = "SMTPLogs"

# Content
$cmClickMenu = new-object System.Windows.Forms.ContextMenuStrip

# Add Open Log file Button

$olButton = new-object System.Windows.Forms.Button
$olButton.Location = new-object System.Drawing.Size(20,19)
$olButton.Size = new-object System.Drawing.Size(75,23)
$olButton.Text = "Select file"

# Add Reverse DNS Lookup Button

$rdnsbutton = new-object System.Windows.Forms.Button
$rdnsbutton.Location = new-object System.Drawing.Size(500,19)
$rdnsbutton.Size = new-object System.Drawing.Size(85,23)
$rdnsbutton.Text = "Reverse DNS"

# Add MX Lookup Button

$mxbutton = new-object System.Windows.Forms.Button
$mxbutton.Location = new-object System.Drawing.Size(500,44)
$mxbutton.Size = new-object System.Drawing.Size(85,23)
$mxbutton.Text = "MX Lookup"

# Add SPF Lookup Button

$spfbutton = new-object System.Windows.Forms.Button
$spfbutton.Location = new-object System.Drawing.Size(590,19)
$spfbutton.Size = new-object System.Drawing.Size(85,23)
$spfbutton.Text = "SPF Lookup"

# Add A Lookup Button

$Abutton = new-object System.Windows.Forms.Button
$Abutton.Location = new-object System.Drawing.Size(590,44)
$Abutton.Size = new-object System.Drawing.Size(85,23)
$Abutton.Text = "A Rec Lookup"

# Add RBL Single Lookup Button

$RBLButton = new-object System.Windows.Forms.Button
$RBLButton.Location = new-object System.Drawing.Size(680,19)
$RBLButton.Size = new-object System.Drawing.Size(85,23)
$RBLButton.Text = "RBL Lookup"

# Add HELO chk Button

$HelochkButton = new-object System.Windows.Forms.Button
$HelochkButton.Location = new-object System.Drawing.Size(680,44)
$HelochkButton.Size = new-object System.Drawing.Size(85,23)
$HelochkButton.Text = "HELO Banner Check"

# Add WhoIS chk Button

$Whois = new-object System.Windows.Forms.Button
$Whois.Location = new-object System.Drawing.Size(770,19)
$Whois.Size = new-object System.Drawing.Size(85,23)
$Whois.Text = "Whois Check"

# Add FileName Lable
$fnFileNamelableBox = new-object System.Windows.Forms.Label
$fnFileNamelableBox.Location = new-object System.Drawing.Size(110,25)
$fnFileNamelableBox.forecolor = "MenuHighlight"
$fnFileNamelableBox.size = new-object System.Drawing.Size(200,20)

# Add Veiw RadioButtons
$rbVeiwAllRadioButton = new-object System.Windows.Forms.RadioButton
$rbVeiwAllRadioButton.Location = new-object System.Drawing.Size(310,19)
$rbVeiwAllRadioButton.size = new-object System.Drawing.Size(69,17)
$rbVeiwAllRadioButton.Checked = $true
$rbVeiwAllRadioButton.Text = "View All"
$rbVeiwAllRadioButton.Add_Click({if ($rbVeiwAllRadioButton.Checked -eq $true){$lnLogfileLineNum.Enabled = $false}})

$rbVeiwAllOnlyRadioButton = new-object System.Windows.Forms.RadioButton
$rbVeiwAllOnlyRadioButton.Location = new-object System.Drawing.Size(310,42)
$rbVeiwAllOnlyRadioButton.size = new-object System.Drawing.Size(89,17)
$rbVeiwAllOnlyRadioButton.Text = "View Only #"
$rbVeiwAllOnlyRadioButton.Add_Click({if ($rbVeiwAllOnlyRadioButton.Checked -eq $true){$lnLogfileLineNum.Enabled = $true}})

# Add Numeric log line number
$lnLogfileLineNum = new-object System.Windows.Forms.numericUpDown
$lnLogfileLineNum.Location = new-object System.Drawing.Size(401,39)
$lnLogfileLineNum.Size = new-object System.Drawing.Size(69,20)
$lnLogfileLineNum.Enabled = $false
$lnLogfileLineNum.Maximum = 10000000000

# File setting Group Box

$OfGbox = new-object System.Windows.Forms.GroupBox
$OfGbox.Location = new-object System.Drawing.Size(12,0)
$OfGbox.Size = new-object System.Drawing.Size(464,75)
$OfGbox.Text = "Log File Settings"

# Add DataGrid View

$dgDataGrid = new-object
$dgDataGrid.AllowSorting = $True
$dgDataGrid.Location = new-object System.Drawing.Size(12,81)
$dgDataGrid.size = new-object System.Drawing.Size(1024,750)

$form.topmost = $true