Active Directory Logon Script

for some time now we used batch script to log user logon to theirs domain computers. What we collected via this script was something like this:

Mon 02.01.2017., 7:55:06,64,user1,AD-PC1,Windows 7 or Server 2008R2,32 Bit
Mon 02.01.2017., 7:55:42,90,user2,AD-PC2,Windows 7 or Server 2008R2,64 Bit
Mon 02.01.2017., 7:55:46,51,user3,AD-PC3,Windows 7 or Server 2008R2,32 Bit
Mon 02.01.2017., 7:55:50,94,user4,AD-PC4,Windows 7 or Server 2008R2,64 Bit

But now (well not now, but some time ago) Powershell started to improve IT life.
So logon script that I use now on my domain is as follows:

$ipV4 = Test-Connection -ComputerName $env:ComputerName -Count 1  | Select -ExpandProperty IPV4Address

$Date = Get-Date -format “dd.MM.yyyy HH:mm”

$OutputFile = ‘UNC Path\logon.txt’

$TotalMemory = (Get-WMIObject -class Win32_PhysicalMemory |Measure-Object -Property capacity -Sum | % {[Math]::Round(($_.sum / 1GB),2)})
$String = $Date +”, “
$String += $env:UserName +”, “
$string += $env:ComputerName  +”, “
$string += $ipV4.IPAddressToString +”, “
$string += (Get-WmiObject -class Win32_OperatingSystem).Caption +”, “
$string += (Get-WmiObject -class Win32_OperatingSystem).OSArchitecture +”, “
$string += (Get-WmiObject CIM_ComputerSystem).Model+ ” (” + (Get-WmiObject CIM_ComputerSystem).SystemFamily + “) sn:” +(Get-WmiObject Win32_Bios).Serialnumber +”, “
$String += [string]$TotalMemory +”GB RAM, “
$String += “IE: ” + (Get-ItemProperty ‘HKLM:\Software\Microsoft\Internet Explorer’).SvcVersion
$string | Out-File $OutputFile –Append

And now we get full information who logged on, at what time, from what IP address and from what particular PC
Now collection looks like this:
29.09.2017 18:21, user1, AD-PC1,, Microsoft Windows 7 Professional , 32-bit, Model1 (Lenovo X230) sn:1111111, 4GB RAM, IE: 11.0.9600.18762
29.09.2017 18:36, user2, AD-PC2,, Microsoft Windows 7 Professional , 32-bit, Model2 (HP370 AIO) sn:11111112, 4GB RAM, IE: 11.0.9600.18762
29.09.2017 18:39, user1, AD-PC3,, Microsoft Windows 7 Enterprise , 64-bit, Model3 (XXXXXX) sn:1123141, 4GB RAM, IE: 11.0.9600.18762
I suggest you open the txt file with Notepad++ because it does not lock file for further write.

Good Luck!

Working with batch procedure–going back to roots

Couple of years ago, we had a problem with custom software. The problem was, how to install new version of software (size around 60MB+), only on main computers in our branch offices, which are over 60 locations. Since we don’t have in house programmer, we needed a solution. Solution by now, was connecting to remote computers (our VPN is on ADSL) over ADSL modem, configured to port-forward PcAnywhere. Then copy new version to that computer, unpack, change config file, and deploy. Three men, have been doing this for 5 days.
We (meaning I) needed a solution, to make this less time consuming and less repetitive.

I sat down, and came up with the solution. Semi-automated batch script. The only thing that the person in office would do is, start batch, and press corresponding number (1-proceed,2-Cancel).

So, here is a little demo.
You start by using echo command like this, but must disable “echo” to print with “@echo off”
Then we needed a blank Main Screen. CLS is command to ClearScreen.


Click on picture to open SkyDrive with this file.

So we have small sample of batch file. Now we have to crate a shared folder, somewhere on the VPN, where all users can reach this batch.
And in the end, set shortcuts (you can do that via logon script) to users desktop.

This is simple batch file for copy numerous things to computers around you. But there is one more thing I needed to do.
How to change config file, insert new parameters or change the existing ones.
Prepare to be amazed  🙂

Changing a string in config file:
For this I came across a little exe called change.exe (file is here).
Lets say you need to change PARAM1=OFF to PARAM1=ON.
The syntax is
CHANGE.EXE [filename] “what to change” “change to”

Problem with CHANGE.EXE is that this file does not work in 64bit environment.

Adding or removing text from config file:
Config file:

Lets say you have to put another parameter  PARAM4=OFF (or multiple) into end of config file.
Create a file PARAM4.txt

Make a batch with statement:
find /v “[EOF]” < config.ini> config.ini.temp
//find [EOF] in config.ini and everything above it save to config.ini.temp
copy/b config.ini.temp+param4.txt
//now combine config.ini.temp and pram4.txt into new file
copy/b config.ini
//now overrun config.ini with

Lets say you have to remove PARAM2=OFF, then you need only two lines from above:

find /v “PARAM2=OFF” < config.ini> config.ini.temp
//find PARAM2 in config.ini and everything else save to config.ini.temp
copy/b config.ini.temp config.ini
//now overrun config.ini with config.ini.temp

So, this should cover small portion of batch procedures.
Till next time…