dos commands and windows commands

Hi, My name is Jimmy Sam. If you need DBA help, please email to jimmy_sam001@yahoo.com for further discussion. Thanks.
get process  du:folder size  df:disk space  find filename  email_powwershell  last_boot_time  users_and_groups  rdp:remote_desktop  7za  outlook  loop_and_sleep 

Shortcut Key Combination

Press WindowKey, in search box type cmd, and then press CTRL+SHIFT+ENTER: open command prompt in administrator mode
shift + right mouse click --> open command prompt here, Open command promot in current folder
Windows Key: bring up Start Menu 
ctrl+shift+esc --> open task manager
Windows Logo+Break: System Properties dialog box
Windows Logo+C: Opens Control Panel

Windows Logo+D: Minimizes all open windows and displays the desktop
Windows Logo+M: Minimize all
SHIFT+Windows Logo+M: Undo minimize all

Windows Logo+L: Lock the computer (without using CTRL+ALT+DELETE)

Windows Logo+R: Run dialog box

ESC: Equivalent to clicking the Cancel button, Especially useful in Excel

CTRL+ESC: Open Start menu
ALT+TAB: Switch between open programs
ALT+F4: Quit program
SHIFT+DELETE: Delete item permanently

CTRL+Z: Undo
CTRL+B: Bold
CTRL+U: Underline
CTRL+I: Italic
top

dos programming

The caret (^) symbol is the cmd.exe line-continuation character 
that allows you to continue a command on multiple lines

eg:
echo This is a line ^
    and this is more ^
    and this is still more stuff to echo.
top

7za

 
7za -?
7za a -tzip -v1g myfile.zip myfile.dmp -mx0 -pmypassword
7za a -tzip -v1g myfile.zip myfile.dmp -mx4 -pmypassword
7za a -tzip -v25m MYSERVER_MYDB_FULL_20170710_13826.bak.zip MYSERVER_MYDB_FULL_20170710_13826.bak -mx4

# in unix or lunix
ls *.DMP|awk '{print "7za a -tzip " $1".zip " $1 " -mx0 -pmypassword"}'
ls *.DMP|awk '{print "7za a -tzip " $1".zip " $1 " -mx4 -pmypassword"}'

a: add files
d: Delete Files from archive
e: Extract file from archive
x: eXtract files with full paths
l: List contents of archive

-tzip: type is zip, -t7z, -tiso or -tudf 
-v1g: split file for 1GB, -v1024m
-mx0: level 0, no compression
-p{password}
-r: Recursive to subdirectories
-ssc: case-insensitive matching for wildcard search

7-zip 

rem extract, unzip, untar
7za x MYSERVER_MYDB_FULL_20170710_13826.bak.zip.001
7z x archive.zip -oC:\Doc
-oC:\Doc:    extract all files to the Doc folder on the C: drive


top

dos

ipconfig /registerdns

net use

rem remote desktop
mstsc /v:myservername
mstsc /admin /v:myservername

msconfig.msc
services.msc
rem services: services.msc
%windir%\system32\services.msc

rem task scheduler: taskschd.msc
%windir%\system32\taskschd.msc /s

rem Disk Management
diskmgmt.msc
diskmgmt.msc -- disk management, change drive letter for VM(Virtual Machine)
compmgmt.msc -- Computer Management

local security policy
secpol.msc

eventvwr -- Event Viewer

Firewall:
WIndows Firewall: firewall.cpl
Windows Firewall with Advanced Security: wf.msc wf.msc and neighbor content

netsh advfirewall show currentprofile netsh 

top

Powershell

$PSVersionTable.PSVersion

Find Files: Powershell

find drive script:
Get-ChildItem -Path . -Filter drive*.sql -Recurse

powershell -Command "dir p:/2014*/*/*/*%1*"
top

Get Processes

get-process
get-process|gm
get-process|gm -View Extended
Get-Process | Where-Object {$_.name -eq 'conHost'}
Get-Process | Where-Object {$_.name -eq 'conHost'}|Format-Table -Property handles,name,Path

top

Get current folder size: Powershell

Get-ChildItem . -recurse| Measure-Object -property length -sum 
Get-ChildItem . -recurse| Measure-Object -property length -sum| Select-Object sum|format-list
Get-ChildItem . -recurse| Measure-Object -property length -sum| Select-Object sum|format-wide

Get-ChildItem . -recurse| Measure-Object -property length -sum|select @{LABEL='sum(mb)';EXPRESSION={"{0:N2}" -f ($_.sum/1MB)}}|format-list

# -- -----------------------------------------------------------------------

# sub folders size
$mySubDir = (Get-ChildItem | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)
foreach ($i in $mySubDir)
{
$v = (Get-ChildItem $i -recurse| Measure-Object -property length -sum)
$i.FullName + "     " + "{0:N2}" -f ($v.sum / 1MB) + " MB"
} 

top

disk space: Powershell


# current disk drive space info
gwmi win32_volume|`
select driveletter, label,`
@{LABEL='GBTotalSpace';EXPRESSION={"{0:N2}" -f ($_.Capacity/1GB)}},`
@{LABEL='GBfreeSpace';EXPRESSION={"{0:N2}" -f ($_.freespace/1GB)}}|`
sort-object -property driveletter


# current disk drive space info
gwmi win32_volume | select driveletter, label, @{LABEL='GBfreespace';EXPRESSION={"{0:N2}" -f ($_.freespace/1GB)}}|sort-object -property driveletter

gwmi win32_volume -Filter 'drivetype = 3' | select driveletter, label, @{LABEL='GBfreespace';EXPRESSION={"{0:N2}" -f ($_.freespace/1GB)} }|sort-object -property driveletter

$dA=Get-WmiObject -Class Win32_LogicalDisk -ComputerName MYSERVERNAME

foreach ($d in $dA ) {
if ( $d.Size) {
"$($d.deviceid) $([math]::Round($($($d.FreeSpace)/(1024*1024*1024)),2)) $([math]::Round($($($d.Size)/(1024*1024*1024)))) $($d.volumeName) "
}
}
top

find filename in sub directory

search sub directory:
dir /s *myfilename_substring*
output: X:\...\mydirectory_name\
output: myfilename_fullname
top

Test Email: Powershell

send-mailmessage -to "myemailname@abc.com" -from "oracle user <oracle@abc.com>" -subject "Test mail"  -smtpServer 'forwarder.subdomain.abc.com'
top

Last Boot Time: Powershell

# powershell
Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime

rem dos and windows
wmic OS GET LastBootUpTime

rem take long time to get
systeminfo | find /i "Boot Time"

net stats srv

net statistics workstation
net statistics workstation | findstr /i since
net statistics workstation | find "Statistics since"
top
top

Remote Desktop

Remote Desktop shortcut key  2 
CTRL+ALT+BREAK   full-screen or window mode
CTRL+ALT+END     similar to CTRL+ALT+DELETE
ALT+INSERT       similar to ALT+TAB

mstsc 

enable rdp 

mstsc /v:192.168.1.101 /w:1024 /h:768
mstsc /v:192.168.1.101 /w:1600

mstsc /f: full screen mode
mstsc /v:192.168.1.101 /f: full screen mode


-- span dual monitor
mstsc /span
mstsc /v:192.168.1.101 /span

-- fixing "exceed the maximum number of allowed connections"
mstsc /admin

top
Windows Temp Files:
C:\Documents and Settings\username\Local Settings\Temp
C:\WINDOWS\Temp
top

dos loop and sleep

-- sleep command in dos is timeout: eg: timeout 10
rem monitor_01_loop.bat

:BEGIN
call monitor_01.bat
timeout 3
goto :BEGIN
1):
rem cut in dos command
rem set MY_HOSTNAME=MYSERVERNAME\MYDBNAME
set str=%MY_HOSTNAME%
rem (in_batch) for /f "delims=\\\" %%a in ("%str%") do set MY_HOST=%%a
rem (in_cmd) for /f "delims=\\\" %a in ("%str%") do set MY_HOST=%a
echo %MY_HOST%

2):
rem String or substring Manipulation in dos command
https://www.dostips.com/DtTipsStringManipulation.php

3):
FINDSTR and FIND exit codes

ErrorLevel is not %ERRORLEVEL%
rem findstr with exit ERRORLEVEL

IF ERRORLEVEL 5 ... 	IF E = 5 OR E > 5 THEN ...

IF NOT ERRORLEVEL 6 	IF E < 6 THEN

The following list shows each exit code and a brief description of its meaning:
0: The search was completed successfully and at least one match was found.
1: The search was completed successfully, but no matches were found.
2: The search was not completed successfully. In this case, an error
   occurred during the search, and FIND cannot report whether any matches were found.

You can use the ERRORLEVEL parameter on the <If> command line in a batch
program to process exit codes returned by FIND

will set %ERRORLEVEL% as follows:
0 (False) a match is found in at least one line of at least one file.
1 (True)  if a match is not found in any line of any file, (or if the file is not found at all)
2 (Wrong) syntax: An invalid switch will only print an error message in error stream.

findstr -sip Failed log.txt > NULL
IF NOT ERRORLEVEL 1 ( 
    echo Found.
) else (
    echo Not Found.
)

4):
:loop
(type "File" | findstr Idle) > nul 2>&1
set err=%errorlevel%
timeout 1
if %err% == 0 goto loop

5):
echo.
echo Looking for Methuselah....
set %ERRORLEVEL%=3
findstr /C:"Methuselah" temp.log 
echo ERRORLEVEL = %ERRORLEVEL%
echo.
echo Looking for Headerversion....
set %ERRORLEVEL%=6
findstr /C:"HeaderVersion: 0x00000001" temp.log 
echo ERRORLEVEL = %ERRORLEVEL%
echo.

6): random number in dos
echo %random%
32565
echo %random%
21727
echo %random%
6322
echo %random%
10742
echo %random%
7779
top

Users And Groups

dsa.msc "Active Directory Users and Computers"

Installing RSAT ( Remote Server Administration Tools )


http://setspn.blogspot.com/ 
dos command list 

Identify members of a local group 

Managing local groups from the command line 

set MYUSERNAME=myusername
net user %MYUSERNAME% /domain
rem not working: dsquery user -name  *%MYUSERNAME%*

net user myusername /domain
dsquery user -name  *myusername*

# list member of localgroup
net localgroup administrators
# net localgroup administrators mydomainname\myusername /add

# sometimes worked
net localgroup mydomaingroupname /domain

# list domain group member in current domain
net group mydomaingroupname /domain
net group "my domain group name" /domain
net group "my domain group name" /domain|find /I /C "%USERNAME%"

#
# dsget group "CN=GroupName,DC=domain,DC=name,DC=com" -members

dsget group "CN=mydomaingroupname,DC=subdomain,DC=microsoft,DC=com" -members
dsget group "CN=mydomaingroupname,DC=subdomain,DC=microsoft,DC=com" -members -expand

dsquery group -name  mydomaingroupname
dsquery group -samid  mydomaingroupname
dsquery group -name  *mydomaingroupname*
dsget group "CN=mydomaingroupname,OU=Groups,DC=subdomain,DC=microsoft,DC=com" -members
dsget group "CN=mydomaingroupname,OU=Groups,DC=subdomain,DC=microsoft,DC=com" -members -expand

dsquery group -samid "Group_SAM_Account_Name" | dsget group -members -expand
dsquery group -name "Group Account Name" | dsget group -members -expand
dsquery group -name mydomaingroupname | dsget group -members | dsget user -display

# Powershell
# Import-Module ActiveDirectory
Get-ADGroupMember "mydomaingroupname" -recursive
Get-ADGroupMember "mydomaingroupname" -recursive | Select-Object name
Get-ADGroupMember "mydomaingroupname" -recursive | Select-Object name,SamAccountName

Find A user's Windows Groups

rem Find A user's Windows Groups
rem In DOS
net user myusername /domain
net user myusername /domain|findstr /i password|findstr /i expires

dsquery user -name  *myusername*


# In Powershell
Get-ADUser myusername -Properties MemberOf | Select -ExpandProperty memberof|sort
Get-ADPrincipalGroupMembership myusername | select name
Get-ADPrincipalGroupMembership myusername | select name | sort name

List All Of the Users In A Windows Group

rem List All Of the Users In A Windows Group
rem In DOS
net user localgroup Administrators

# powershell

$GroupName="Unix_DBA_GRP"
Get-ADGroupMember -Identity $GroupName -Recursive | `
Where {$_.ObjectClass -eq 'user'} | `
Get-ADUser -Properties Title,Department | `
Select SamAccountName,Name,Title,Department 
# List ALL Groups In the Current Domain
Get-ADGroup -filter * -properties GroupCategory | ft name,groupcategory 
top top

outlook

To recall or replace a message, follow these steps:
1):Locate the Sent Items folder. 
2):Open the message that you want to recall or replace. 
3):Click Actions on the ribbon or menu, and then click Recall This Message. 
4):Enable the Delete unread copies of this message option to recall the message. 
Or, enable the Delete unread copies and replace with a new message to replace the message with a new one.
5):To receive a notification about the success of the recall or replacement, 
enable the Tell me if recall succeeds or fails for each recipient option.
6):Click OK. If you chose the replace option, type your new message and send it.
top
1): Add Another Mailbox in Outlook 2016
Add Mailbox 

2):
File tab --> click Info tab --> Account Settings --> Change ---> more settings --> Advanced --> (Mailboxes) Add ...

(Type mailbox name ) then Click OK. Click Apply

Finish out the wizard by clicking Next, and then Finish on he Change Account screen.
top
outlook: ctrl-a ctrl-q: market all email as read
top
outlook: View HTML content in Web Browser
         Action Panel -- View In Browser
excel: data--> Refresh All
top
IF NOT EXIST V: net use V: \\myserver\myfileshare

IF NOT EXIST V: net use V: \\myserver\myfileshare  /PERSISTENT:YES

IF EXIST V: net use V: /delete