Skip to main content

Posts

Showing posts from November, 2017

how to find out who login to a PC

A lot of time I need to know who owns a PC that connecting to database etc. I used to use nbtstat but it's not always tell me the answer. now I use wmic. C:\windows\system32>wmic.exe /node:pcname computersystem get username UserName domainname\jsun thanks to this link: https://community.spiceworks.com/how_to/40336-use-cmd-to-return-the-logged-in-user-of-a-remote-computer

powershell select field

I got a file with two fields delimitered by various length of space in between. CA    CADevserver1 CA      CADevserver1 CA        CADevserver1 ... I need to get the second field only, this is the powershell command I use: PS C:\> gc "c:\dropit\\tmp.txt" |foreach {($_ -split '\s+',2)[1]} > temp.txt The idea come from this link, thanks for that: https://stackoverflow.com/questions/2503010/extracting-columns-from-text-file-using-powershell Though the second field content are saved in temp.txt, the lines in the file cannot be processed properly by the following code: " @echo off for /F "tokens=*" %%A in (temp.txt) do call :processline %%A pause goto :eof :processline set pcpserver=%1 echo "pcpserver name is :"%pcpserver% goto :eof :eof " The above script suppose to loop each line but it did not, I do not have time to troubleshoot, the workaround is to copy the lines from temp.txt and paste to new file an

powershell to find out which rdp session do I login

My PC sometime is rebooted overnight by patching process without noticing me, I do not remember which windows servers I remote control login to, I need to logoff those otherwise when my windows password change next time then my account will be locked because those orphaned login. I saved the remote desktop connection manager configuration in a few groups, for example, one group name is others.rdg. I use this power shell command to query the login session on the servers: PS C:\dropit\remotedesktop> findstr "<name>" others.rdg|foreach-object { $_ -replace "<name>","query session /server:"}|foreach-object { $_ -replace "</name>", ""}         query session /server:servername1         query session /server:servername2 ... copy and paste the output and run it either in powershell or in dos command, I will have the list of sessions who logon to those windows server, then I can logoff from there. PS C:\dropit\

BAT script to run plsql script on multiple oracle databases

@echo off set passwd=mypassword for /F "tokens=*" %%A in (pcpserverlist.txt) do call :processline %%A pause goto :eof :processline set pcpserver=%1 sqlplus myusername/%passwd%@"(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(Host = %pcpserver%.company.com)(Port = port)))(CONNECT_DATA =(sid = sidname)))" < plsqlscript.sql > %pcpserver%.txt goto :eof :eof all the server name need to be saved in the file  pcpserverlist.txt, each server take 1 line