Thursday, March 14, 2013

Basic Network Concepts and Minecraft Server

Hi K here is some stuff to get you going – love Dad…

Below are some basic networking concepts if you are looking to host your own Minecraft Server.
Also a possible network design.


IP Address – What computers use to communicate with each other. An example is 192.168.1.80

Domain Name – An internet name like google.com

DNS – Takes a name like google.com and looks up the ip address.

DHCP – Gives the computer an ip address.

Fixed ip address - You enter the ip address (you don’t use DHCP)

Port – When computers communicate the use the ip address and the port number. An example is 192.168.1.80:25565. 25565 is the normal Minecraft port.

Firewall – Used to control which ip addresses and ports you let in and out of your network or computer.

ADSL Router – Connects to the internet and controls internet traffic. It will have 2 ip addresses. Internal Network Address 192.168.1.1 and External Internet Address which is assigned by the internet service provider (ISP) like 74.125.237.130.

Port Forwarding - Takes a request to your external address and port 74.125.237.130:25565 and sends it to an internal ip address 192.168.1.80:25565.


Monday, March 19, 2012

Exchange 2010 Bulk Mailbox enable of Mail users

If you need to change your Mail enabled users to Mailbox users you can user the script below.

You can use wildcards in the identity field or drop -Identity and use -organizationalUnit yourOU.
 
get-MailUser -Identity usernameofuser | Enable-Mailbox -Database "Whatever DB" | get-mailbox |
select name,windowsemailaddress,database

Thursday, March 15, 2012

Exchange 2010 Scripting New-MoveRequest

Exchange 2010 New-MoveRequest can be scripted to take input form a csv and pipe into the New-MoveRequest command.

Here's how I did it...

Command required was:
New-MoveRequest -Identity "CN=Test User,OU=Your OU,OU=Another OU,DC=YourDC,DC=local" -RemoteLegacy -TargetDatabase "EXCH-DB" -RemoteGlobalCatalog "dc.olddomain" -RemoteCredential $Remote -TargetDeliveryDomain "yourdomain.com"

The unique fields required are "CN=Test User,OU=Your OU,OU=Another OU,DC=YourDC,DC=local" which is the distinguishedName of the user we are going to migrate and "EXCH-DB" which is the Exchange Database we want to put the Mailbox in.

First we need to get the distinguishedName for all the users we want to migrate. Here's the script http://sjmeyers.blogspot.com.au/2012/03/vb-script-to-get-distinguishedname-from.html

Then we need to setup our csv file with as the first entry in column 1 distinguishedName, the first entry in column 2 TargetDB.
Then insert the required data


Save the csv as mbusers.csv on the Exchange Server

In Exchange Power Shell

We are connecting to a remote Forest for so first we need to setup the remote credentials
$remote = Get-Credential











Make sure the csv file is in the correct directory and run the following command

import-csv mbusers.csv | foreach {New-MoveRequest -Identity $_.distinguishedName -RemoteLegacy –TargetDatabase $_.TargetDB -RemoteGlobalCatalog "dc.olddomain" -RemoteCredential $Remote -TargetDeliveryDomain "youremaildomain.com"}







If all goes well you should see the move process start.

To check on the progress run Get-MoveRequest

VB Script to get distinguishedName from AD

If you need to get the distinguishedName attribute from Active Directory you can use the script below.

You will need a list of users in c:\scripts\users.txt

The script will output to c:\scripts\dn.txt

OptionExplicit

Dim objRootDSE, strDomain, strUsername, objConnection, objCommand, objRecordSet, strDN
Dim objFSO, objFSO2, objTextFile, objTextFile2, strNextLine, arrUserList, i
Const ADS_SCOPE_SUBTREE = 2

' Get domain components
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")

'Setup Constants for input and output files
Const ForReading = 1
Const ForAppending = 8

'Open input file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\scripts\users.txt", ForReading)
'loop
DoUntil objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrUserList = Split(strNextLine , ",")
    'Wscript.Echo "User: " & arrUserList(0)
    
    ' Get username to search for
    strUsername = arrUserList(0)
    'Wscript.Echo strUsername
    ' Set ADO connection
    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open"Active Directory Provider"

    ' Set ADO command
    Set objCommand = CreateObject("ADODB.Command")
    Set objCommand.ActiveConnection = objConnection
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
    objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://" & strDomain & "' WHERE objectCategory='user' AND samAccountName = '" & strUsername & "'"

    ' Set recordset to hold the query result
    Set objRecordSet = objCommand.Execute

    ' If a user was found - Retrieve the distinguishedName
    IfNot objRecordSet.EOFThen
        strDN = objRecordSet.Fields("distinguishedName").Value
            'Write to Output file
        Set objFSO2 = CreateObject("Scripting.FileSystemObject")
        Set objTextFile2 = objFSO2.OpenTextFile _
        ("c:\scripts\dn.txt", ForAppending, True)    
        objTextFile2.WriteLine(strDN)
        objTextFile2.Close
    Else
        'Can't find the user
        MsgBox"Username not found " & arrUserList(i)
    EndIf
Loop
MsgBox"Finished getting DN for usernames check c:\scripts\dn.txt"

Exchange 2010 New-MoveRequest Fails

I just had an issues when I tried to Migrate some mailboxes from Exchange 2003 to 2010

We have 2 Internal Domains and SMTP namespace sharing setup between Exchange 2003 in old Domain and Exchange 2010 in the new Domain.

Users and been mirgated using ADMT. All users in the new Domain have been mail enabled (using a script). The Mailboxes have moved using New-MoveRequest from the Exchange Powershell.

Most mailboxes migrated without any problems but we had some fail with the error:

Cannot find a recipient that has mailbox GUID.

I found that some of the mail enabled accounts didn't have the targetAddress attribute set.

Setting the email adress on the targetAddress attribute fixed the problem...
BTW: There other reasons for getting this message such as the GUID being different.






















After the Mailbox migrated this attribute returned to <not set> which is correct if the Mailbox is inside the local Exchange Organisation.

Tuesday, March 13, 2012

Exchange 2010 Loop

I just resolved an issue with Exchange 2010 where I was getting loop detected.
Our setup is Exchange 2003 in old domain, Exchange 2010 in new domain with SMTP namespace sharing. http://blog.mimecast.com/2011/06/guest-post-migrating-between-email-servers-smtp-namespace-sharing/

Mail flow was working fine with some users but other users couldn't receive mail at all.

Message tracking logs showed there was a loop
C:\Program Files\Microsoft\Exchange Server\V14\TransportRoles\Logs\MessageTracking
ExchangeServer,,,LoopDetected,,SMTP,DEFER,0,,testuser@contoso.com

The Queue Viewer showed that a local loop was detected


I found that the targetAddress attribute was set in Active Directory


The value of the targetAddress attribute is the address of the user that is outside of the local Exchange  organization that mail should be sent to. When mail is sent to the mail-enabled user or contact, the mail is redirected to the address held in the targetAddress field.

Editing the targetAddress field and selecting Clear sets it to <not set>

After that I was able to send and recieve mail from that account.

BTW the targetAddress attribute can be cleared using Quest Active Server Roles powershell (run on the Domain Controller) here's what I used....

get-qaduser -LDAPFilter "(&(&(&(objectCategory=Person)(objectClass=User)(targetAddress=*)(homeMDB=*))))" | Set-QADUser -ObjectAttributes @{targetAddress=$null}

Let me break it down
get-qaduser get ADuser
-LDAPFilter Filter using an LDAP query
objectCategory=Person Person CategoryobjectClass=User Is a user
targetAddress=* Has the Target Address Set
homeMDB=* Has the homeMDB attribute set - We were doing Exchange 2003 migration in Exchange 2003 this attribute isn't set.
| Pipes users that meet above into our command to change the attribute
Set-QADUser Sets AD Attributes
-ObjectAttributes @{targetAddress=$null} Sets the targetAddress attribute to nothing ($null) in AD this will appear as <not set>

Tuesday, February 21, 2012

How to View an F5 ucs file in windows

I recently made an error with an incorrect ip address in when I was deploying an F5 LTM Template.

I had entered the wrong ip in multiple places so I wanted to check the entire config.

Under System, Archives Create a new Archive

















Click on the Archive and download the Archive.
















Once you have downloaded the file open with 7-Zip.
You will then be able to open the im file to browse the entire configuration.


 


Tuesday, January 31, 2012

Unable to install VMware Tools

IBM HS22 Blade with IBM ESXi 4.1update2  USB Key
VMware tools installation fails with the error below...

Unable to install VMware Tools. An error occurred while trying to access image file "/usr/lib/vmware/isoimages/windows.iso" needed to install VMware Tools: 2 (No such file or directory). If your product shipped with the VMware Tools package, reinstall VMware ESX, then try again to install the VMware Tools package in the virtual machine.
 The required VMware Tools ISO image does not exist or is inaccessible.

Troubleshooting
SSH to the Vmware host reveals that the /usr/lib/vmware is not accessible




ls -l reveals that the isoimages folder is a symbolic link to /productLocker/vmtools/


cd /productLocker is inaccessible




/vmfs/volumes is missing Hypervisor3




The ESXi partition table can be checked using the command fdisk -l













There is a Warning for partition table 8
Warning: ignoring extra data in partition table 8

And the file system for mpx.vmhba32:C0:T0:L0p8 is Unknowm
/dev/disks/mpx.vmhba32:C0:T0:L0p8   ?    740786   1480957 757935405   5a  Unknown

mpx.vmhba32:C0:T0:L0p8 should be the scratch disk location.

The fix

It is recommended that the persistent scratch location be set for ESXi

Configuring persistent scratch location using the vSphere Client

You can configure persistent scratch space for ESXi using the vSphere Client:
  1. Connect to vCenter Server or the ESXi host using the vSphere Client.
  2. Select the ESXi host in the inventory.
  3. Click the Configuration tab.
  4. Click Storage.
  5. Right-click a datastore and select Browse.
  6. Create a uniquely-named directory for this ESX host (eg, .locker-ESXHostname)
  7. Close the Datastore Browser.
  8. Click Advanced Settings under Software. 
  9. Select the ScratchConfig section.
  10. Change the ScratchConfig.ConfiguredScratchLocation configuration option, specifying the full path to the directory. For example:

    /vmfs/volumes/DatastoreName/.locker-ESXHostname
  11. Click OK.
  12. Put the ESXi host in maintenance mode and reboot for the configuration change to take effect.
Recreating scratch files including Vmware tools iso's.

Once the scratch  location has been set you can run the current ESXi 4.1 update 2 patch this will recreate the Vmware tools installation iso in the scratch file location.

Once the patch has applied reboot the host.

You can check that the vmtools iso's have been created by browsing the persistent scratch datastore.















You will then be able to deploy Vmware tools

Wednesday, July 13, 2011

AD Migration moving data to a new server

During a Domain Migration you may want to move file data from an old server in the old domain to a new server in the new domain.

You can use robocopy http://sjmeyers.blogspot.com/2011/05/migrating-data-between-servers.html to migrate the data but you will still be left with old permissions.


You can run the Active Directory Migration Tool ADMT to do a security translation on the new server to change security on files and folders to the new domain.

Open ADMT Security Translation Wizard

Select Previously migrated objects


Select the old domain as the source and the new domain as the target


Select the computer(s)

Select Files and folders

Select Replace

Select Finish


 Run  pre-check and agent operation
Once Agent has run you can verify the logs


Then check file permissions have changed to the new Domain

Please note permissions will only be translated the the new Domain if the Group was previously migrated and has sid history.
In the example above the Domain users Group hasn't been migrated yet.

The Security Translation wizard can be run more than once on the same server. 

Wednesday, May 18, 2011

Adding a Printer with Group Policy Preferences

You can add printers using Group Policy Preferences which is new in Server 2008 provided you have the Group Policy Preference Client Side Extensions installed on the client machines.

Group Policy Preferences are added though the normal Group policy Console.



You can Create, Replace, Update, Delete as required. You can also set as the default printer.

 

If more granular control is required click the Common Tab.
You can apply the setting only once and use the Targeting Editor to get really specific

 

Tuesday, May 17, 2011

Migrating Data between Servers

Robocopy is a good option when migrating data to another server.

It has a number of switches that can preserve attributes, timestamps, security, owner info, auditing info, etc...
Also it can include, exclude, add attributes, rerun and much more.

For a full list of operations type robocopy /? at the command prompt.

I recently migrated data to a new server using the following...
robocopy source destination /E /DCOPY:T /PURGE /COPYALL /TEE /LOG+:c:\robocopylog.txt

/E :: copy subdirectories, including Empty ones.
/DCOPY:T :: COPY Directory Timestamps.
/PURGE :: delete dest files/dirs that no longer exist in source.
/COPYALL :: COPY ALL file info (Data, Attributes, Timestamp, Security, Owner, Auditing).
/TEE :: output to console window, as well as the log file.
/LOG+:file :: output status to LOG file (append to existing log).

The method I used was to copy the data over and checked that everything was OK.
I then disconnected the users on the source, reran the command, and pointed the users to the new location.

Using this method the second run only copied over the changes (and removed anything that was no longer there) so took alot less time than the first run.

Sunday, May 15, 2011

How to reclaim Disk Space using Vmware Thin provisioning

If your drive is thick provisioned
You will need to use either Vmware Tools, Shrink or sdelete
Vmware tools Shrink
 
Sdelete
 
Then migrate to a new datastore.
Note: there is currently an issue where you will need to migrate to a new datastore with different block size.

If your drive is already thin provisioned
Vmware Tools Shrink isn’t available.
You will need to use sdelete to zero out disk then migrate to new datastore.
Warning: using sdelete will expand the thin provisioned disk to it’s full provisioned size so make sure you have enough space on the datastore free.
Note: there is currently an issue where you will need to migrate to a new datastore with different block size.

Monday, April 4, 2011

VB Script to list the current logged in user

The Scipt below reads computers from c:\temp\computers.txt and lists the user who is currently logged in.

'List user currently logged on to a desktop

WScript.Echo "List Currently logged in user for Computers in c:\temp\computers.txt"
On Error Resume Next
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\temp\computers.txt", ForReading)
strText = objTextFile.ReadAll
objTextFile.Close
arrComputers = Split(strText, VbCrLf)

For Each strComputer In arrComputers  
 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
 For Each objItem in colItems
 WScript.Echo "UserName: " & objItem.UserName & " is logged in at computer " & strComputer
 Next
 Set objItem = Nothing: Set colItems = Nothing: Set objWMIService = Nothing
Next
WScript.Echo "Script Finished"

VB Script to Execute Wake on LAN on a different subnet

Wake on Lan packets won't travel over different subnets.

Below is a script which remotely executes the command on a host computer on the same subnet to send the WOL packet.

You will need
  • WOL capable computer you wish to wake.
  • A host machine on the same subnet as the comptuer you wish to wake.
  • WOL software http://sourceforge.net/projects/wake-on-lan/ extract the software to C:\temp\wol
  • MAC address of computer you wish to wake (you can get from DHCP) .
The script copies the WOL files from C:\temp\WOL to the host then remotely executes the command.

'Copy Wake on LAN files to remote computer then execute WOL
'Allows you to select remote computer on a different subnet as a host and wake another computerOption Explicit
Dim strHostComputer, strMAC, strIPComputer, objFSO
Dim objWMIService, objProcess, errReturn
Dim strComputerOn, Count, strCommand
Dim intProcessID, strComputer, colPingedComputers
Dim objComputer
strHostComputer =Inputbox("Wake Computer on another Subnet" & chr(10) & chr(13) & chr(10) & chr(13) & "Enter HOST PC Number on Remote Subnet","Input Required")
If strHostComputer = ""Then
 WScript.Echo"Host blank exiting script!"
 WScript.Quit
Endif
strMAC =Inputbox("Enter MAC of PC you want to WAKE" & chr(10) & chr(13) & chr(10) & chr(13) & "MAC can be obtained from DHCP Scope, Address Leases","Input Required")
If strMAC = ""Then
 WScript.Echo"MAC blank exiting script!"
 WScript.Quit
Endif
strIPComputer =Inputbox("Enter IP Address of Computer you want to WAKE","Input Required")
If strIPComputer = ""Then
 WScript.Echo"IP Blank will send request but can't check progress"
Endif

Const OverWriteFiles = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\temp\WOL\bin\wol.exe") Then
    objFSO.CopyFolder"C:\temp\WOL" , "\\" & strHostComputer & "\C$\temp\WOL" , OverWriteFiles
Else
    Wscript.Echo"Wake on Lan File C:\temp\WOL\bin\wol.exe not found. Download from http://sourceforge.net/projects/wake-on-lan"
    WScript.Quit
EndIf


strCommand = "C:\temp\WOL\bin\wol.exe " & strMAC

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strHostComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")

errReturn = objProcess.Create(strCommand, null, null, intProcessID)

If errReturn = 0Then
'WScript.Echo strHostComputer &" " & strCommand & " executed with a process ID: " & intProcessID
Else
WScript.Echo strHostComputer & " " & strCommand & " not started due to error: " & errReturn
EndIf
If strIPComputer = ""Then
 WScript.Quit
Endif
' Verify Computer Availability
Wscript.Echo"Waking Remote Computer - usually takes about 1 minute"
Count = 0
DoWhile strComputerOn <> 1
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPingedComputers = objWMIService.ExecQuery _
    ("Select * from Win32_PingStatus Where Address = '" & strIPComputer & "'")
ForEach objComputerin colPingedComputers
    If objComputer.StatusCode = 0Then
        Wscript.Echo"Remote Computer " & strIPComputer & " Powered On!!!"
        strComputerOn=1
    Else
        WScript.sleep20000
        Count = Count + 1
        If Count = 7Then
        Wscript.Echo"Can't Connect to Remote Machine WOL has failed :(" & chr(10) & chr(13) & chr(10) & chr(13) & "Or Remote Machine has new IP"
        WScript.Quit
        Endif
   EndIf
Next
Loop

VB Script to Shutdown Comptuers from a text file

The below script Shuts down Computers in a text file C:\temp\computers.txt

' Read Arguments from a Text File

Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\temp\computers.txt", ForReading)
i = 0
WScript.Echo "SHUTDOWN Computers in c:\temp\computers.txt"
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    objDictionary.Add i, strNextLine
    i = i + 1
Loop

For Each objItem in objDictionary
    Set objFSO = CreateObject("Scripting.FileSystemObject")
  If objFSO.FolderExists("\\"& objDictionary.Item(objItem) & "\Admin$") Then
      Set objFolder = objFSO.GetFolder("\\" & objDictionary.Item(objItem) & "\Admin$")
      'Reboot Desktops
      'strComputer = objDictionary.Item(objItem)
      WScript.Echo objDictionary.Item(objItem)
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate,(Shutdown)}\\" & _
           objDictionary.Item(objItem) & "\root\cimv2")

    Set colOperatingSystems = objWMIService.ExecQuery _
        ("Select * from Win32_OperatingSystem")

    For Each objOperatingSystem in colOperatingSystems
        objOperatingSystem.Win32Shutdown(1)
    Next
    
      Else
      'WScript.Echo "Can't Connect to " & objDictionary.Item(objItem) & chr(10) & chr(13) & "Please verify it is contactable via DNS and you have Admin rights"
      'strCantConnect = "1"
  End If
Next
If strCantConnect = "1" Then
WScript.Echo "Script Finished!"
Else WScript.Echo "All Desktops have been Shutdown!"
End if

VB Script to Set the Default Domain for Computers in a text file

The following script Sets the Default Domain at login for computers in C:\temp\computers.txt

' Change Registry Keys so the default domain name is BOB when  people login
Const HKEY_LOCAL_MACHINE = &H80000002

' Read Arguments from a Text File
Const ForReading = 1

Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\temp\computers.txt", ForReading)
i = 0
WScript.Echo "Set Login Domain to BOB Computers in c:\temp\computers.txt"
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    objDictionary.Add i, strNextLine
    i = i + 1
Loop

For Each objItem in objDictionary
    Set objFSO = CreateObject("Scripting.FileSystemObject")
 
      WScript.Echo objDictionary.Item(objItem)
      strComputer = objDictionary.Item(objItem)

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
strValueName = "DefaultDomainName"
strValue = "BOB"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strValueName = "CachePrimaryDomain"
strValue = "BOB"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

Next
If strCantConnect = "1" Then
WScript.Echo "Script Finished!"
Else WScript.Echo "All Desktops have had Default Domain Set!"
End if 

VB Script to Reboot Computers from a text file

The VB Script below reboots machines in C:\temp\computers.txt

' Read Arguments from a Text File

Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\temp\computers.txt", ForReading)
i = 0
WScript.Echo "Reboot Computers in c:\temp\computers.txt"
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    objDictionary.Add i, strNextLine
    i = i + 1
Loop

For Each objItem in objDictionary
    Set objFSO = CreateObject("Scripting.FileSystemObject")
  If objFSO.FolderExists("\\"& objDictionary.Item(objItem) & "\Admin$") Then
      Set objFolder = objFSO.GetFolder("\\" & objDictionary.Item(objItem) & "\Admin$")
      'Reboot Desktops
      'strComputer = objDictionary.Item(objItem)
      WScript.Echo objDictionary.Item(objItem)
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
           objDictionary.Item(objItem) & "\root\cimv2")

    Set colOperatingSystems = objWMIService.ExecQuery _
        ("Select * from Win32_OperatingSystem")

    For Each objOperatingSystem in colOperatingSystems
        objOperatingSystem.Reboot()
    Next
    
      Else
      WScript.Echo "Can't Connect to " & objDictionary.Item(objItem) & chr(10) & chr(13) & "Please verify it is contactable via DNS and you have Admin rights"
      strCantConnect = "1"
  End If
Next
If strCantConnect = "1" Then
WScript.Echo "Script Finished!"
Else WScript.Echo "All Desktops have been Rebooted!"
End if

VB Script to get IP and MAC from remote computer

The following script gets the IP and MAC address form computers in C:\temp\computers.txt and writes them to files in C:\temp\desktop

'Gathers the IP address and MAC from
'Computers in c:\temp\computers.txt
'Outputs to c:\temp\desktop

Option Explicit
Dim objDictionary, objFSO, objTextFile, strRemoteComputer
Dim strNextLine, arrServiceList, i, strCantConnect, strLogFileLocation
Dim objFile, objFolder, objTextFile1, n, objWMIService, colAdapters, objAdapter

' Read a Text File into an Array
Const ForAppending = 8
Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\temp\computers.txt", ForReading)

Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrServiceList = Split(strNextLine , ",")
    'Wscript.Echo "Server name: " & arrServiceList(0)
    For i = 1 to Ubound(arrServiceList)
        Wscript.Echo "Service: " & arrServiceList(i)
    Next

'Get Computer name via input
'strComputer =Inputbox("Get MAC Address and write to c:\Temp" & chr(10) & chr(13) & chr(10) & chr(13) & "Enter PC Number","Input Required")

 ' Verify connection to the Desktop
 strCantConnect = "0"
 Set objFSO = CreateObject("Scripting.FileSystemObject")
  If objFSO.FolderExists("\\"& arrServiceList(0) & "\Admin$") Then
      Set objFolder = objFSO.GetFolder("\\" & arrServiceList(0) & "\Admin$")
  Else
      WScript.Echo "Can't Connect to " & arrServiceList(0) & chr(10) & chr(13) & "Please verify it is contactable via DNS and you have Admin rights"
      strCantConnect = "1"
  End If
' Create the File System Object
strLogFileLocation = "C:\Temp\Desktop\" & arrServiceList(0) & ".txt"
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(strLogFileLocation) Then
 'objFSO.DeleteFile(strLogFileLocation)
 'Set objFile = objFSO.CreateTextFile(strLogFileLocation)
Else
   Set objFile = objFSO.CreateTextFile(strLogFileLocation)
End If
set objFile = nothing
set objFolder = nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
If strCantConnect = "0" Then
Set objTextFile1 = objFSO.OpenTextFile _
(strLogFileLocation, ForAppending, True)
objTextFile1.WriteLine()
objTextFile1.WriteLine("#################################################################################")
End if

'Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objFile = objFSO.CreateTextFile(strLogFileLocation)

' List IP Configuration Data
strRemoteComputer = arrServiceList(0)
If strCantConnect = "0" Then
 Set objWMIService = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate}!\\" & strRemoteComputer & "\root\cimv2")

 Set colAdapters = objWMIService.ExecQuery _
     ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 n = 1
 End If
   
 For Each objAdapter in colAdapters
If strCantConnect = "0"  Then
 '   WScript.Echo "Network Adapter " & n
 objTextFile1.WriteLine("=================")
 objTextFile1.WriteLine("Host name: " & objAdapter.DNSHostName)
 objTextFile1.WriteLine("Description: " & objAdapter.Description)
 objTextFile1.WriteLine("Physical (MAC) address: " & objAdapter.MACAddress)

  Else
  End If 
    If Not IsNull(objAdapter.IPAddress) Then
       For i = 0 To UBound(objAdapter.IPAddress)
  If strCantConnect = "0" Then
  objTextFile1.WriteLine("IP address:             " & objAdapter.IPAddress(i))
  objTextFile1.WriteLine()
  End if
       Next
    End If

    n = n + 1
  
Next
objTextFile1.Close
If strCantConnect = "0" Then
'WScript.Echo "Please review " & strLogFileLocation & " for MAC Address"
Else
End If
'

Loop
WScript.Echo "Script Finished! Please Review c:\Temp\Desktop for results"

VBScript to Set DNS Suffix, Check File, Check Registry

The below script...
  • Reads computer names from c:\temp\compters.txt
  • Sets the DNS suffix to append under Advanced TCP/IP properties 
  • Verifies a file exists C:\Temp\efs_found.txt and the file size is 0
  • Checks a registry entry

'Check Computers in c:\temp\computers.txt
'Set DNS suffix
'Check a file exists and the file size
'Check Registry setting

Option Explicit
Dim objFSO, objTextFile, strNextLine, strCantConnect, arrServiceList
Dim objFolder, strKeyPath, strValueName, strValue, oReg, i, objFile

' Read a Text File into an Array
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\temp\computers.txt", ForReading)
WScript.Echo "Setting DNS Suffix, Checking Encypted Files, Checking ODBC on C:\Temp\Computers.txt"
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrServiceList = Split(strNextLine , ",")
    'Wscript.Echo "Server name: " & arrServiceList(0)
    strCantConnect = "0"
  ' Verify connection to the Desktop
 Set objFSO = CreateObject("Scripting.FileSystemObject")
  If objFSO.FolderExists("\\" & arrServiceList(0) & "\Admin$") Then
      Set objFolder = objFSO.GetFolder("\\" & arrServiceList(0) & "\Admin$")
  Else
      WScript.Echo "Can't Connect to " & arrServiceList(0) & chr(10) & chr(13) & "Please verify it is contactable via DNS and you have Admin rights"
      strCantConnect = "1"
  End If
 
 ' Create Registry DNS Search String Value
 If  strCantConnect = "0" Then
 Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    arrServiceList(0) & "\root\default:StdRegProv")
  strKeyPath = "SYSTEM\CurrentControlSet\services\Tcpip\Parameters"
 strValueName = "SearchList"
 strValue = "contoso,contoso.local"
 oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
 'WScript.Echo "DNS Search Domains Added to "& arrServiceList(0) & " Registry"
 Else
 End If

 ' Verify that the EFS checking script
has been run
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 If objFSO.FileExists("\\" &  arrServiceList(0) & "\C$\Temp\efs_found.txt") Then
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.GetFile("\\"  & arrServiceList(0) & "\C$\Temp\efs_found.txt")
   If objFile.Size = "0" Then
   'WScript.Echo "No encypted Files Exist on "  & arrServiceList(0)
   Else
   WScript.Echo "Encypted Files Exist on "  & arrServiceList(0) & " Unencrypt before Migrating!"
   End If
 Else
 If  strCantConnect = "0" Then
    Wscript.Echo "Script for checking for Encryption Files hasn't been run."& chr(10) & chr(13) & "Login to "  & arrServiceList(0) & "and run
FindEFS.bat"& chr(10) & chr(13) & "Before continuing!"
 End If
  End If
 ' Check ODBC settings for Dataworks
 If  strCantConnect = "0" Then
  Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
     arrServiceList(0) & "\root\default:StdRegProv")
   strKeyPath = "SOFTWARE\ODBC\ODBC.INI\DataWorks"
  strValueName = "Trusted_Connection"
  oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
 If strValue = "Yes" Then
  WScript.Echo "Dataworks ODBC Settings NOT SET CORRECTLY on "  & arrServiceList(0) &"!"
  Else
     'Wscript.Echo "Dataworks ODBC Settings look OK on "  & arrServiceList(0)
     End If 
    End if
        For i = 1 to Ubound(arrServiceList)
        Wscript.Echo "Service: " & arrServiceList(i)

    Next
Loop
Wscript.Echo "Finished Checking and setting DNS!"

Sunday, April 3, 2011

VB Script for checking computers in a text file are turned on

Below is a handy script for checking Pc's in a text file are turned on and you can connect to the Admin share. 

'Check Computers in c:\temp\computers.txt are turned on
'And you can access admin share

Option Explicit
Dim objDictionary, objFSO, objTextFile, i, strNextLine
Dim objItem, objFolder, strCantConnect

' Read Arguments from a Text File
Const ForReading = 1

Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\temp\computers.txt", ForReading)
i = 0
WScript.Echo "Verify you can connect to Computers in c:\temp\computers.txt"
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    objDictionary.Add i, strNextLine
    i = i + 1
Loop

For Each objItem in objDictionary
    Set objFSO = CreateObject("Scripting.FileSystemObject")
  If objFSO.FolderExists("\\"& objDictionary.Item(objItem) & "\Admin$") Then
      Set objFolder = objFSO.GetFolder("\\" & objDictionary.Item(objItem) & "\Admin$")
  Else
      WScript.Echo "Can't Connect to " & objDictionary.Item(objItem) & chr(10) & chr(13) & "Please verify it is contactable via DNS and you have Admin rights"
      strCantConnect = "1"
  End If
Next
If strCantConnect = "1" Then
WScript.Echo "Script Finished!"
Else WScript.Echo "All Desktops are Switched on!"
End if