30
Jul/09
0

Sort Drivers in MDT 2008 DriverGroups.xml

Came to my mind to do the same thing for the Driver Groups :)
This little utility sorts the DriverGroups.xml File in your Microsoft Deployment Toolkit which makes it easier to select the Driver Groups you want to assign to Distribution Points and WinPE images.

Download: MDTSortDriversGUI

Expand Screenshots

Print This Post
(5 votes, average: 4.60 out of 5)
Loading ... Loading ...
335 views
30
Jul/09
2

Ping and verify access to multiple Computers in AD

Here’s a Powershell script that queries Active Directory for Computers and then starts to Ping them and tries to access the C$ Share on each Computer. Finally it generates an Excel sheet with the Result.
Note: If you’d like to check for access rights, run the script using an Account that should have access rights on the Client Computers.

Modify the Directory entry path to suit your environment.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
trap [System.Management.Automation.MethodInvocationException]{
    write-host ("ERROR: " + $_) -Foregroundcolor Red;
	Continue
	}
 
$erroractionpreference = "SilentlyContinue"
 
$strCategory = "computer"
 
$objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=Laptops,OU=Computers,dc=yourdomain,dc=com")
 
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(objectCategory=$strCategory)")
 
$colProplist = "name","description"
foreach ($i in $colPropList) {
    $objSearcher.PropertiesToLoad.Add($i)
    }
 
$colResults = $objSearcher.FindAll()
$count = 1
$total = $colResults.count
$arrComputers = @{}
 
 
 
foreach ($strComputer in $colResults) {
    $ping = new-object System.Net.NetworkInformation.Ping
    $name = $strComputer.Properties.name
    $description = $strComputer.Properties.description
 
	write-progress -id 1 -activity  "Checking Computer $name $description ($count / $total )" -status "Getting IP address" #-percentComplete 
 
	Try {
	$ip = ([System.Net.Dns]::GetHostAddresses("$name"))
 
	write-progress -id 1 -activity  "Checking Computer $name $description ($count / $total )" -status "IP: $ip" 
 
	sleep 1
	}
	Catch {
	    echo "Cannot handle the error: $_"
    	#throw $_
	}
 
	write-progress -id 1 -activity  "Checking Computer $name $description ($count / $total )" -status "Pinging" #-percentComplete 
 
	Try {
	$Reply = $ping.send($strComputer.Properties.name)
	}
	Catch {
		$Reply = "Failed"
	    echo "Cannot handle the error: $_"
    	#throw $_
	}	
 
    if ($Reply.status –eq “Success”) {
		write-progress -id 1 -activity  "Checking Computer $name $description ($count / $total )" -status "Checking Access"
        if (Test-Path "\\$name\C$") {
			$arrComputerAccess += $strComputer.Properties.name
			}
		else {
			$arrComputerPing += $strComputer.Properties.name
			}		
        }
    else {
    $arrComputerOffline += $strComputer.Properties.name
    }
    $Reply = ""
    $count ++
    }
 
$a = New-Object -comobject Excel.Application
$a.visible = $True 
 
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
 
$c.Cells.Item(1,1) = "Machine Name"
$c.Cells.Item(1,2) = "Ping Status"
$c.Cells.Item(1,3) = "Access Check"
 
$d = $c.UsedRange
$d.Interior.ColorIndex = 48
$d.Font.ColorIndex = 1
$d.Font.Bold = $True
#$d.EntireColumn.AutoFit($True)
 
$intRow = 2
 
foreach ($Computer in $arrComputerOffline)
{
$c.Cells.Item($intRow, 1) = $Computer.ToUpper()
$c.Cells.Item($intRow, 2) = "Offline"
$intRow ++
}
 
foreach ($Computer in $arrComputerPing)
{
$c.Cells.Item($intRow, 1) = $Computer.ToUpper()
$c.Cells.Item($intRow, 2) = "Online"
$c.Cells.Item($intRow, 3) = "Failed"
$intRow ++
}
 
foreach ($Computer in $arrComputerAccess)
{
$c.Cells.Item($intRow, 1) = $Computer.ToUpper()
$c.Cells.Item($intRow, 2) = "Online"
$c.Cells.Item($intRow, 3) = "Passed"
$intRow ++
}
 
$d.EntireColumn.AutoFit()
Print This Post
(6 votes, average: 3.50 out of 5)
Loading ... Loading ...
638 views
27
Jul/09
0

Get XML Childnode Count

A Class to get the amount of child nodes using C#

?View Code CSHARP
1
2
3
4
5
6
7
public static int GetItemCount(string XmlFile)
{
    XmlDocument doc = new XmlDocument();
    doc.Load(XmlFile);
    XmlNodeList nodelist = doc.SelectNodes("books/book"); //replace with your XML path
    return nodelist.Count;
}
Print This Post
(3 votes, average: 4.67 out of 5)
Loading ... Loading ...
418 views
27
Jul/09
1

How to Check Mailbox Size on Exchange Server via Script

Here’s a small VBScript that enumerates an Exchange Information Store and lists all Mailbox sizes.
Takes 1 Argument (ExchangeServerName)

Run “cscript MSX_GetMailboxSize.vbs YOUREXCHANGESERVER>Output.csv” to get a Comma Separated Value file.

VBScript Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
On Error Resume Next
Dim cComputerName
Const cWMINameSpace = "root/MicrosoftExchangeV2"
Const cWMIInstance = "Exchange_Mailbox"
cComputerName = WScript.Arguments(0)
 
Dim strWinMgmts
Dim objWMIExchange
Dim listExchange_Mailboxs
Dim objExchange_Mailbox	
 
strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//"& _
cComputerName&"/"&cWMINameSpace
Set objWMIExchange =  GetObject(strWinMgmts)
 
If Err.Number <> 0 Then
  WScript.Echo "ERROR: Unable to connect to the WMI namespace."
Else
 
  Set listExchange_Mailboxs = objWMIExchange.InstancesOf(cWMIInstance)
 
  If (listExchange_Mailboxs.count > 0) Then
 
    WScript.Echo "Display Name,SizeMB,SizeGB,Storage Group,Store,Total Items"
    For Each objExchange_Mailbox in listExchange_Mailboxs
       WScript.Echo objExchange_Mailbox.MailboxDisplayName & "," & Round(FormatNumber(objExchange_Mailbox.Size / 1024, 2), 0) & "," & Round(FormatNumber(objExchange_Mailbox.Size / 1024 / 1024, 2), 2) & "," & objExchange_Mailbox.StorageGroupName & "," & objExchange_Mailbox.StoreName & "," & objExchange_Mailbox.TotalItems
    Next
  Else
    WScript.Echo "WARNING: No Exchange_Mailbox instances were returned."
  End If
End If
Print This Post
(5 votes, average: 3.20 out of 5)
Loading ... Loading ...
2,404 views
27
Jul/09
0

Remove Blank Lines from a Text File

I ran into a tricky Problem the other day. I had to remove the terminating blank lines in a CSV File as it was parsed by another program which did not handle the case of blank lines and thus failed. I figured this is not easy to do with a simple batch file so I created a little C# Program that does the trick.

The Program can be run from a command line and requires the path to the Text File where you want to remove the ending blank lines from.

Download Compiled Version: RemoveBlankLines

C# Code:

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string file = args[0];
            if (file == "")
            {
                Console.WriteLine("Please enter the path to the File!");
                Environment.Exit(1);
            }
            if (!File.Exists(file))
            {
                Console.WriteLine("Could not find File {0}!", file);
                Environment.Exit(1);
            }
 
            RemoveBlankRowsFromCSVFile(file, 0);
            RemoveBlankRowsFromCSVFile(file, CountLines(file));
        }
 
        public static void RemoveBlankRowsFromCSVFile(string filepath, int lastline)
        {
            if (filepath == null || filepath.Length == 0)
            {
                throw new ArgumentNullException("filepath");
            }
 
            if (!File.Exists(filepath))
            {
                throw new FileNotFoundException("Could not find file.", filepath);
            }
 
            String tempFile = Path.GetTempFileName();
            int linecount = 0;
 
            using (StreamReader reader = new StreamReader(filepath))
            using (StreamWriter writer = new StreamWriter(tempFile))
            {
                String line = null;
                while ((line = reader.ReadLine()) != null)
                {
                    linecount++;
 
                    line = line.Replace("\r\n", "").Replace("\n", "").Replace("\r", "");
                    if (!line.Equals(String.Empty))
                    {
                        if ((linecount >= lastline) && (lastline != 0))
                            writer.Write(line);
                        else
                            writer.WriteLine(line);
                    }
                }
 
            }
 
            File.Delete(filepath);
            File.Move(tempFile, filepath);
        }
 
        static int CountLines(string file)
        {
            int count = 0;
            using (StreamReader r = new StreamReader(file))
            {
                string line;
                while ((line = r.ReadLine()) != null)
                {
                    count++;
                }
            }
            return count;
        }
 
 
    }
}
Print This Post
(8 votes, average: 4.63 out of 5)
Loading ... Loading ...
2,173 views