Archive for the ‘Windows’ Category

Determine SQL Version and Edition using Powershell and WMI

Monday, December 8th, 2014

This small Powershell script prompts for a computername and tries to determine the installed version and edition of SQL using WMI.

$comp = Read-Host "Enter Computername:"
Get-WmiObject -ComputerName $comp -Namespace root\Microsoft\SqlServer\ComputerManagement -Class SqlServiceAdvancedProperty | Where-Object {($_.PropertyName -eq 'VERSION') -or ($_.PropertyName -eq 'SKUNAME')} | Format-Table ServiceName, PropertyName, PropertyStrValue -AutoSize
Get-WmiObject -ComputerName $comp -Namespace root\Microsoft\SqlServer\ComputerManagement10 -Class SqlServiceAdvancedProperty | Where-Object {($_.PropertyName -eq 'VERSION') -or ($_.PropertyName -eq 'SKUNAME')} | Format-Table ServiceName, PropertyName, PropertyStrValue -AutoSize
Get-WmiObject -ComputerName $comp -Namespace root\Microsoft\SqlServer\ComputerManagement12 -Class SqlServiceAdvancedProperty | Where-Object {($_.PropertyName -eq 'VERSION') -or ($_.PropertyName -eq 'SKUNAME')} | Format-Table ServiceName, PropertyName, PropertyStrValue -AutoSize
Get-WmiObject -ComputerName $comp -Namespace root\Microsoft\SqlServer\ComputerManagement14 -Class SqlServiceAdvancedProperty | Where-Object {($_.PropertyName -eq 'VERSION') -or ($_.PropertyName -eq 'SKUNAME')} | Format-Table ServiceName, PropertyName, PropertyStrValue -AutoSize

Batch script to detect CD/DVD-rom drive

Friday, May 2nd, 2014

Batch script to detect CD/DVD-rom drive

REM Check if we have a CDROM drive
Setlocal EnableDelayedExpansion

echo list vol > diskpart.txt
diskpart /s diskpart.txt > dp_volumes.txt
set hascdrom=0
FOR /F "delims=," %%v in (dp_volumes.txt) do (
rem echo %%v
set str1=%%v
rem echo Line is !str1!
rem echo "x!str1:ROM=!"
rem echo "x!str1!"
if not "x!str1:ROM=!"=="x!str1!" set hascdrom=1
rem echo !hascdrom!
if "!hascdrom!"=="0" GOTO nocdrom

echo We have a CD/DVD-rom
goto :EOF

echo No CD/DVD-rom drive available
goto: EOF

Domain Join using Powershell

Tuesday, November 13th, 2012

Example of how to join a computer (Windows 8) to a domain using PowerShell.

$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @('ALTIRIS\srv_altiris', (ConvertTo-SecureString -AsPlainText -Force 'P@ssw0rd' ))
Add-Computer -DomainName altiris.local -OUPath 'OU=CORPORATE_COMPUTERS,OU=BELGIUM,DC=altiris,DC=local' -PassThru -Verbose -Credential $credential

Outlook VBA – remove reminders

Friday, August 27th, 2010

I synchronize my Windows Mobile Device with my corporate-exchange account. This way my calendar stays nicely up to date and gives me reminders for the tasks I have to do.

However I find it rather a hassle that I receive reminders for certain activities like holidays. Therefore I have written a small macro that disables the reminders for all future calendar entries with a certain subject.

Private Sub RemoveReminders(sProject As String)
Dim fldMailbox As MAPIFolder
Dim fldCalendar As MAPIFolder
Dim objItem As AppointmentItem
Dim iCntr As Integer
iCntr = 0
Set fldMailbox = Session.Folders(sMailboxName)
Set fldCalendar = fldMailbox.Folders("Calendar")
Set mcolCalItems = fldCalendar.Items
For Each objItem In mcolCalItems
If objItem.start > Now() Then
If objItem.ReminderSet = True Then
    If InStr(objItem.Body, sProject) > 0 Then
    iCntr = iCntr + 1
With objItem
.ReminderSet = False
End With
End If
End If
End If
MsgBox "Modified " & iCntr & " calendar entries"
End Sub
Public Sub RemoveHolidayReminders()
RemoveReminders ("Holiday")
End Sub

ESXi 3.5 and Server 2003 dualboot

Sunday, January 31st, 2010

After some testing I managed to create a dualboot setup with ESXi 3.5 and Windows Server 2003.

  1. Install ESXi to harddisk 1
  2. Install Windows Server 2003 to harddisk 2. Delete the existing partition on harddisk 2 if ESXi has created one.
    On the first reboot during the installation you should get an error “NTLDR is missing”
  3. Boot with a live linux cd-rom, eg KNOPPIX
  4. (Re-)install syslinux bootloader to boot partition (Hypervisor0)
    sudo syslinux /dev/hda1
    file is read only. overwrite anyway (y/n)? y
    sudo mkdir /mnt/Hypervisor0
    sudo mount /dev/hda1 /mnt/Hypervisor0
    vi /mnt/Hypervisor0/syslinux.cfg


    default safeboot.c32


    default menu.c32
    menu title Dual boot
    timeout 100
    label esx
    menu label ESXi 3.5
    COM32 safeboot.c32
    LABEL win
    MENU LABEL MS Windows Server 2003
    COM32 chain.c32
    APPEND boot ntldr=/NTLDR
  5. Copy syslinux modules menu.c32 and chain.c32 to boot partition (Hypervisor0)
    Use locate to find the folder on the live cd that contains the modules, eg locate menu.c32

    cp /usr/lib/syslinux/menu.c32 /mnt/Hypervisor0
    cp /usr/lib/syslinux/chain.c32 /mnt/Hypervisor0
  6. Reboot

Using Debian as domain controller in a Windows network

Thursday, October 12th, 2006

Using Debian as domain controller in a Windows network
I didn’t find the for the moment to comment the commands used, but for the moment these are the steps I used.

apt-get install vim
apt-get install apache2
apt-get install libapache2-mod-php4
FQDN error
vi /etc/hosts server.legacycode.lan server localhost
apt-get install slapd
DNS domain: legacycode.lan
Name of organization: legacycode.lan
tar zxf mkntpwd.tar.gz
cd mkntpwd
cp mkntpwd /usr/local/bin
apt-get install samba samba-doc
cd /usr/share/doc/samba-doc/examples/LDAP
gunzip samba.schema.gz
cp samba.schema /etc/ldap/schema/
vi /etc/ldap/slapd.conf
include         /etc/ldap/schema/samba.schema
/etc/init.d/slapd restart
apt-get install db4.2-util
apt-get install phpldapadmin
Authentication type: session
Configure webserver: apache2
Restart: yes
cd /usr/share/doc/samba-doc/examples/LDAP/smbldap-tools-0.8.7
gunzip smbldap.conf.gz
mkdir /etc/smbldap-tools/
cp smbldap.conf /etc/smbldap-tools/
cp smbldap_bind.conf /etc/smbldap-tools/
net getlocalsid
(copy SID (S-1-5-21-1646905445-4160608177-2293427999))
vi /etc/smbldap-tools/smbldap.conf
*replace sid
apt-get install libnet-ldap-perl
apt-get install libcrypt-smbhash-perl
vi /etc/smbldap-tools/smbldap_bind.conf
delete sambaDomainName!
vi /etc/samba/smb.conf
passdb backend = ldapsam:ldap://
ldap suffix = dc=legacycode,dc=lan
ldap machine suffix = ou=machines
ldap user suffix = ou=users
ldap group suffix = ou=groups
ldap admin dn = cn=admin,dc=legacycode,dc=lan
ldap delete dn = no
# be a PDC
domain logons = yes
# allow user privileges
enable privileges = yes
smbpasswd -w password
/etc/init.d/samba restart
vi /usr/share/phpldapadmin/templates/template_config.php
// uncomment to set the base dn of posix groups
// default is set to the base dn of the server
$samba3_domains []  =
array(  'name'   => 'nomis52',
        'sid' => 'S-1-5-21-1646905445-4160608177-2293427999' );
// The base dn of samba group. (CUSTOMIZE)
$samba_base_groups = "ou=groups,dc=legacycode,dc=lan";
apt-get install libnss-ldap
LDAP Server Host:
DN of Search Base: dc=legacycode,dc=lan
LDAP Version: 3
Database requires login: no
Make config readable by owner only: yes
vi /etc/nsswitch.conf
passwd:         compat ldap
group:          compat ldap
shadow:         compat ldap
getent group
apt-get install libpam-ldap
Make local root db admin: yes
Database requires logging in : no
Root login account : cn=admin,dc=legacycode,dc=lan
Root password : password
Crypt : MD5
# Comment out the next line
#account required
# and add these two
account sufficient
account required try_first_pass
# comment out the next line
#auth required nullok_secure
# and add these two
auth sufficient
auth required nullok_secure use_first_pass
# comment out the next line
#password required nullok obscure min=4 max=8 md5
# and add these two
password sufficient
password required nullok obscure min=4 max=8 md5 use_first_pass 
apt-get install nscd
samba afconfigureren
netbios name = server
add user script = /usr/sbin/smbldap-useradd -m "%u"
delete user script = /usr/sbin/smbldap-userdel "%u"
add machine script = /usr/sbin/smbldap-useradd -w "%m"
add group script = /usr/sbin/smbldap-groupadd -p "%g"
add user to group script = /usr/sbin/smbldap-groupmod -m "%u" "%g"
delete user from group script = /usr/sbin/smbldap-groupmod -x "%u" "%g"
set primary group script = /usr/sbin/smbldap-usermod -g "%g" "%u"
ldap password sync = yes
   comment = Home
   valid users = %S
   read only = no
   browsable = no
   comment = All Printers
   path = /var/spool/samba
   printable = yes
   guest ok = yes
   browsable = no
   comment = Network Logon Service
   path = /home/samba/netlogon
   admin users = Administrator
   valid users = %U
   read only = no
   comment = User profiles
   path = /home/samba/profiles
   valid users = %U
   create mode = 0600
   directory mode = 0700
   writable = yes
   browsable = no
mkdir /home/samba
mkdir /home/samba/netlogon
mkdir /home/samba/profiles
mkdir /var/spool/samba
chmod 777 /var/spool/samba/
chown -R root:users /home/samba/
chmod -R 771 /home/samba/
smbpasswd -a domadmin1
use phpldapadmin to add user to the Domain Admins <img src="/web/20120304212301im_/" alt=";)" class="wp-smiley">
net rpc -Udomadmin1 rights grant "Domain Admins" SeMachineAccountPrivilege
apt-get install bind9 bind9-doc dnsutils
vi /etc/bind/named.conf.options
 forwarders {
 allow-transfer { none; };
vi /etc/bind/named.conf.local
zone "legacycode" {
    type master;
    file "/etc/bind/zone.legacycode.lan";
zone ""{
    type master;
    file "/etc/bind/";
@    IN SOA server.legacycode.lan. support.legacycode.lan. (
@    IN    NS server.legacycode.lan.
server    IN    A
@ IN SOA server.legacycode.lan. support.legacycode.lan. (
@    IN    NS server.legacycode.lan.
190    IN    PTR server.legacycode.lan.
Add WindowsXP Client
domadmin1 (= Domain Administrator account)
apt-get install squid
acl mynetwork src
http_access allow mynetwork
apt-get install ntpdate
 smbldap-useradd -a -d /home/user1 -k /etc/skel user1
smbldap-passwd user1
if  [ ! -e /home/$1 ] ; then
   echo "Creating home dir for $1" >>/var/log/smbldap-adduser.log
   mkdir -p /home/$1
   cp /etc/skel/* /home/$1
   cp /etc/skel/.* /home/$1
mkdir -p /home/$1/profile
smbldap-useradd -a -d /home/$1 $1
smbldap-usermod -C "" $1
smbldap-usermod -D "" $1
smbldap-usermod -E "" $1
smbldap-usermod -F "" $1
chown -R "$1":"Domain Users" /home/$1
chmod -R 750 /home/$1
smbldap-passwd $1
exit 0
chown -R "Administrator":"Domain Users" /home/samba/netlogon/
chown -R "Administrator":"Domain Users" /home/samba/profiles/
chmod 740 /home/samba/netlogon/<user>.cmd