Study powershell step by step.
CMD#01. Retrieve only items in the PSDrive that are not directories.
GCI C:\ | where {!$_.psiscontainer}
CMD#02. List all of the WMI Namespace
$wmi = Get-WmiObject -class __Namespace -namespace root
$wmi | format-table name
write-host -foregroundcolor green "There are " $wmi.length `
" namespaces on this machine `n"
CMD#03. Browse WMI classes on a computer
$objLocator = New-Object -ComObject "Wbemscripting.swbemlocator"
$objWMIService = $objLocator.ConnectServer(".", "\root\cimv2", "", "", "", "", "0")
$colItems = $objWMIService.SubclassesOf()
foreach ($objItem In $colItems)
{
$objItem.path_.class
}
CMD#04. Query with WMI
$strComputer = "."
$wmiNS = "root\cimv2"
$wmiQuery = "select name from win32_share"
$objWMIServices = get-wmiobject -computer $strComputer -namespace $wmiNS -query $wmiQuery
$objWMIServices | sort -property name | format-table -property name
CMD#05. Retrieve a listing of all commands typed during a Windows PowerShell session
get-history, or h
CMD#06. select-string, examines all files in the subdirectories of C:\Windows\System32 with the .txt file name extension and searches for the string "Microsoft".
get-childitem c:\windows\system32\* -include *.txt -recurse | select-string -pattern "Microsoft" -casesensitive