2018-11-06

powershell - how to send sms or text message; serial port and powershell

I tried to find code to talk to COM port. Without proper results so I wrote this simple code. Modern phones probably have modem deactivated - I must confirm it, but I tried my old, what's a funny word, HSDPA modem and it is working.
[System.IO.Ports.SerialPort]::getportnames() #list of ports

#my usb modem is connected as virtual COM8
#speed, parity, stop bits should be valid for all devices
$port= new-Object System.IO.Ports.SerialPort COM8,9600,None,8,one
$port.open()

$port.open(); Start-Sleep -Milliseconds 100
$port.Write("AT`r"); Start-Sleep -Milliseconds 100
if ($port.BytesToRead -gt 0) { $port.ReadExisting(); Start-Sleep -Milliseconds 100 } 

$msg = "AT+CMGF=1`r"; $port.Write($msg); Start-Sleep -Milliseconds 100
if ($port.BytesToRead -gt 0) { $port.ReadExisting(); Start-Sleep -Milliseconds 100 } 

#replace xxx with correct number and YY with corect country prefix
$msg = "AT+CMGS=""+YYxxxxxxxxx""`r"; $port.Write($msg); Start-Sleep -Milliseconds 100
if ($port.BytesToRead -gt 0) { $port.ReadExisting();  Start-Sleep -Milliseconds 100 } 

$msg = "something stupid"; $port.Write($msg); Start-Sleep -Milliseconds 100
if ($port.BytesToRead -gt 0) { $port.ReadExisting(); Start-Sleep -Milliseconds 100 } 

#escape character (CTRL-Z from terminal)
$port.Write([char]26); Start-Sleep -Milliseconds 100
if ($port.BytesToRead -gt 0) { $port.ReadExisting(); Start-Sleep -Milliseconds 100 } 

$port.Close()

Output is of course - optional - in my main code it will be connected with commands. 100 ms is only "just in case".

AT commands and communication

AT
OK
AT+CPIN?
+CPIN: SIM PIN

OK
AT - like EHLO in SMTP
AT+CPIN? - query - is PIN required? possible answers are:
+CPIN: SIM PIN - when You MUST enter PIN
+CPIN: SIM PIN2 - when You MUST enter PIN2
+CPIN: SIM PUK - when You MUST enter PUK
+CPIN: SIM PUK2 - when You MUST enter PUK2
+CPIN: READY - when device is not expecting any code
AT - like EHLO in SMTP
AT+CPIN-=
COMMAND NOT SUPPORT
AT+CPIN=
ERROR
AT+CPIN=0000
OK
AT+CPIN?
+CPIN: READY

OK
AT+CPIN=0000
+CME ERROR: operation not allowed
AT+CPIN-= - my mistake - and His majesty answer: COMMAND NOT SUPPORT
AT+CPIN= - my mistake - and His majesty answer: ERROR, because I didn't provide pin
AT+CPIN=0000 - yes - this of course fake pin, but answer is real OK
AT+CPIN? - yes - my device is ready +CPIN: READY, so the same command entering pin...
AT+CPIN=0000 ... will finish with +CME ERROR: operation not allowed
AT+CMGF=1
OK
AT+CMGF=1 - set device in text messages mode, with 0 it will switch in PDU mode - Protocol Descritpion Unit - also for text messages but encoded way
AT+CMGS="xxxxxxxxx"
> mamma mia

+CMGS: 109

OK
AT+CMGS="xxxxxxxxx" - I've been started message addressed to phone xxxxxxxxx
teminal is waiting for the message finished with escape character (26 ascii - Ctrl-Z)
+CMGS: 109 this and OK confirm, that message was sent

2018-11-05

prepopulated view - indexed view

Just like prepopulated reports - especially time consuming - prepared at off-hours for views we can prepopulate data using indexed view. This type of view has additional requirements:
- view must be created WITH SCHEMABINDING
- tables must be specified with database name
- view can't be created from GUI

If view is used frequently and contains aggregation functions so it is equal to great gain of speed - because data is prepopulated and calculated.

2018-11-04

TMG and Windows 2008R2 optimisation

IP Stack configuration
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters “TcpTimedWaitDelay” DWord set to 0x1e.
“StrictTimeWaitSeqCheck” DWord set to 0x1.
Forces TCP/IP stack to hold TCP ports in a TIME_WAIT state for 30 seconds. Default is 120 seconds.

Disk subsystem – Web Cache
Disable short name creation. HKLM\SYSTEM\CurrentControlSet\Control\Filesystem NtfsDiable8dot3NameCreation 0x1
Disable last access update. HKLM\SYSTEM\CurrentControlSet\Control\Filesystem NtfsDsiableLastAccessUpdate 0x1
Multiprocessor only - Bypassing I/O Counters. HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\I/O System CounterOperations 0x0
Task Manager will no longer provide per-process I/O measurements
Useful when a process generates considerable disk and network I/O on a SMP system, which an ISA server under load can easily do.

Domain Topology
NTLM Auth issues. Set HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters DWord “MaxConcurrentApi” 0x3. If still having issues walk up to 0x6.


Firewall & Web Proxy service DNS Cache (in-process)
Services hold the last 3000 DNS records, regardless of actual TTL, for 6 hours.
Keys
Web Proxy: HKLM\SOFTWARE\Microsoft\Fpc\Arrays\{Array GUID}\ArrayPolicy\WebProxy "msFPCDnsCacheSize“ Default is 0xBB8 & "msFPCDnsCacheTtl" Default is 0x5460
Firewall: HKLM\SOFTWARE\Microsoft\Fpc\Arrays\{Array GUID}\ArrayPolicy\Proxy-WSP "msFPCDnsCacheSize“ Default is 0xBB8 & "msFPCDnsCacheTtl“ Default is 0x5460

to use AD LDS (previously ADAM) or not?

Why to use (in 2018/2019) LDS service if we have ADFS, Active Directory and clouds? From my experience in IT:
  • it is much easier (mentally) to extend schema in dedicated directory service nor in Active Directory
  • there are many older applications or they want just use LDAP not ADFS and You want do it more secure than giving access to production directory service
  • you can have multiple instances of the same data or with different settings and scopes of attributes, for example You can give only login names and phone numbers for company A and the same data with group membership for company B without access to not needed data
  • it is very lightweight - of course - if You will create application with wrong long queries You can kill every server - I saw it at one company - they didn't use group membership info and they try to find membership by browsing groups - one by one to find in which groups user is a member of. They have 20-40k users and 25k groups so please, imagine, how can it work. After my review I pointed them, that memberof property is available in OpenLDAP, AD LDS and almost in every modern directory service.
  • it can be fully separated from main domain in scenario with publishing data in not secure environment - passwords can be sychronized as well

to extend a schema or not? cons and pros

To extend a schema or - that is the question... Yes, what are the positive and negative aspects of this process:
  • positive - You will have just custom - prepared for Your environment classes and properties
  • positive - You will avoid some unexpected behaviors like - You hid some attribute - because it is sensitive an after some patch or fix it is now - again - visible for everyone
  • negative - it is irreversible - you couldn't fully remove it from You schema
  • negative - it is not standard property or class - somebody will ask You - how it is possible, that You have some custom attributes, but You don't use standard attributes?
  • negative - it is dangerous - just kidding - it is just quite normal operation so it is neutral for every environment of course You should sit on Your hands before the change, test and rethink names, but it is quite normal operation - of course as long as You don't have a plan to add attribute called "DisplayName"...

NetBIOS - suffixes and other info

NetBIOS (in Microsoft version) defines some suffixes. By design NetBIOS name is limited to 16 characters (single byte characters), but the last, 16th, character is the suffixes which has special meaning:
  • unique names:
  • 0x00 - workstation service - registered with name of workstation account name
  • 0x00 - IIS
  • 0x01 - messenger service - registered with name of user account name - on samba
  • 0x03 - messenger service - registered with name of user account name - on windows
  • 0x06 - remote access service - server
  • 0x1b - domain master browser - PDC role for the domain
  • 0x1d - master browser
  • 0x1f - NetDDE service
  • 0x20 - file server - by default is registered by all servers (if server service is running)
  • 0x20 - DCA IrmaLan Gateway Server Service ('Forte_$ND800ZA')
  • 0x21 - remote access service - client
  • 0x22 - Microsoft Exchange Interchange - MsMail Connector
  • 0x23 - Microsoft Exchange Store
  • 0x24 - Microsoft Exchange Directory
  • 0x2B - Lotus Notes Server Service
  • 0x30 - modem sharing service - server
  • 0x31 - modem sharing service - client
  • 0x42 - McAfee anti-virus
  • 0x43 - SMS clients remote control - SMS is a predecessor of SCCM
  • 0x44 - SMS administrators remote control tool
  • 0x45 - SMS clients remote chat
  • 0x46 - SMS clients remote transfer
  • 0x4c - DEC pathworks tcpip service
  • 0x52 - DEC pathworks tcpip service
  • 0x6a - Microsoft Exchange IMC - IMC was before Exchange 5.5 - it was acronym from Internet Mail Connector, on exchange 5.5 it was called IMS - Internet Mail Service
  • 0x87 - Microsoft Exchange MTA - Mail Transfer Agent
  • 0xbe - network monitor agent
  • 0xbf - network monitor application
  • group names
  • 0x00 - workstation service - workgroup or domain name
  • 0x1c - list of all domain controllers - at first position it should be PDC - when manually registering in WINS PDC should be registered at the end, so it will be the most recent and on the first place. 1C record can return up to 25 entries
  • 0x1c - IIS ('INet~Services')
  • 0x1e - for browser elections purpose
  • 0x20 - internet group - introduced in Windows 2000 - can return up to 25 entries
  • 0x2f - Lotus Notes ('IRISMULTICAST')
  • 0x33 - Lotus Notes ('IRISNAMESERVER')

2018-10-30

ports required between client and domain controller

Between client and domain controller (is always initiated from client side):
  • Kerberos - 88 TCP/UDP
  • RPC mapper - 135 TCP
  • NetBIOS - nothing - it is not required since 2000!
  • SMB/NetBT - 445 TCP/UDP
  • Kerberos Password Change - 464 TCP/UDP
  • LDAP - 389 TCP/UDP
  • LDAP SSL - 636 TCP
  • LDAP GC - 3268 TCP
  • LDAP SSL GC - 3269 TCP
  • DNS - 53 TCP/UDP
  • RPC ports - 49152-65535 since Vista/2008, for older clients (legacy? I hate this word) 1025-5000
  • (optional) DHCP - 67 DHCP