BlueCarbon

Useful_Scripts

Aug 13th, 2021 (edited)
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 90.58 KB | None | 0 0
  1. < ---------------------------- Microsoft Remote Assistance ------------------------------------ >
  2. If you have computer-savvy friends, use <a class="shellExecuteLink" href="shortcut:%25systemroot%25\system32\msra.exe" title="Click to open Windows Remote Assistance"><img src="mshelp://help/?id=Microsoft.Windows.Resources.ShellExecuteTopicIcon" helpImage="ShellExecute"><span class="notLocalizable">Windows</span> Remote Assistance</a>
  3. to let a friend access your computer over the Internet and help you fix a problem. You can watch what they're doing and interact with them while they're helping you.
  4.  
  5. msra.exe
  6.  
  7. < ---------------------------- Microsoft Remote Assistance ------------------------------------ >
  8.  
  9.  
  10. < ---------------------------- Microsoft Office 2013 Autocomplete ------------------------------------ >
  11.  
  12.  
  13. %localappdata%\Microsoft\Outlook\RoamCache\Stream_Autocomplete*
  14.  
  15.  
  16. < ---------------------------- Microsoft Office 2013 Autocomplete ------------------------------------ >
  17.  
  18.  
  19.  
  20. winrm invoke Create wmicimv2/Win32_Process @{CommandLine="notepad.exe";CurrentDirectory="C:\"}
  21.  
  22.  
  23. powershell [-noexit] -executionpolicy bypass -File <Filename>
  24.  
  25.  
  26. %winternals%\psexec \\HOSTNAME -s powershell Enable-PSRemoting -Force
  27.  
  28. psexec64 \\HOSTNAME -s powershell Enable-PSRemoting -Force
  29.  
  30.  
  31. wmic systemenclosure get ChassisTypes,LockPresent,Manufacturer,Name,SecurityStatus,SerialNumber,SMBIOSAssetTag,Tag /format:list
  32.  
  33.  
  34. wmic printer get Caption,Comment,Default,Description,Location,Name,PortName,ServerName,SystemName /format:csv > printers.csv
  35.  
  36. WMIC PRINTER GET CAPTION,COMMENT,DEFAULT,DEFAULTPRIORITY,DESCRIPTION,DRIVERNAME,INSTALLDATE,NAME,PORTNAME,PRINTERSTATE,PRINTERSTATUS,SHARENAME,SPOOLENABLED,STATUS,SYSTEMNAME /FORMAT:LIST
  37.  
  38.  
  39. "c:\PSTools\PsExec.exe" -accepteula \\KACE_HOST_NAME cmd /c IF EXIST "C:\program files (x86)" ("C:\program files (x86)\dell\kace\runkbot.exe" 4 0) ELSE ("C:\program files\dell\kace\runkbot.exe" 4 0)
  40.  
  41.  
  42. netsh int ip set address name = "LAN" source = dhcp
  43.  
  44. netsh advfirewall show privateprofile settings
  45.  
  46. netsh advfirewall firewall add rule name="My Application" dir=in action=allow program="C:\MyApp\MyApp.exe" enable=yes
  47.  
  48.  
  49. netsh advfirewall firewall add rule name="My Application" dir=in action=allow program="C:\MyApp\MyApp.exe" enable=yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet profile=domain
  50.  
  51.  
  52. NETSH -R HOSTNAME ADVFIREWALL FIREWALL ADD RULE NAME="VHN 11.4 - 25017" DIR=IN ACTION=ALLOW PROGRAM="C:\program files\FourJs\gdc25017\bin\gdc.exe" ENABLE=YES
  53.  
  54. NETSH -R HOSTNAME ADVFIREWALL FIREWALL ADD RULE NAME="VHN 11.4 - 25017" DIR=IN ACTION=ALLOW PROGRAM="C:\program files\FourJs\gdc25017\bin\gdc.exe" ENABLE=YES PROFILE=DOMAIN
  55.  
  56.  
  57. netsh advfirewall firewall show rule dir=in name=all
  58.  
  59. netsh advfirewall firewall show rule status=enabled name=all
  60.  
  61.  
  62. < ---------------------------------------------------------------- Powershell Firewall Command ---------------------------------------------------------------- >
  63.  
  64.  
  65. (New-object -comObject HNetCfg.FwPolicy2).rules | where {$_.Name -like '*remote*'} | select Name
  66.  
  67.  
  68. < ---------------------------------------------------------------- Powershell Firewall Command ---------------------------------------------------------------- >
  69.  
  70.  
  71. <# ---------------------------------------------------------------- [Built In Packet Capture on Win Srv 2008 and above] ---------------------------------------------------------------- #>
  72.  
  73.  
  74. Netsh trace start scenario=NetConnection capture=yes report=yes persistent=no maxsize=1024 correlation=yes traceFile=C:\Logs\NetTrace.etl
  75.  
  76. Netsh trace start scenario=NetConnection capture=yes report=yes persistent=no maxsize=4096 filemode=single correlation=yes traceFile=E:\trace\NetTrace_10-12-2018_1.etl
  77.  
  78.  
  79. netsh trace stop
  80.  
  81.  
  82. <# ---------------------------------------------------------------- [Built In Packet Capture on Win Srv 2008 and above] ---------------------------------------------------------------- #>
  83.  
  84.  
  85. [ Netsh ICMP enable IPV4 & 6 ]
  86.  
  87. netsh -r HOSTNAME advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=allow
  88.  
  89. netsh -r HOSTNAME advfirewall firewall add rule name="ICMP Allow incoming V6 echo request" protocol=icmpv6:8,any dir=in action=allow
  90.  
  91. [ Netsh ICMP enable IPV4 & 6 ]
  92.  
  93.  
  94. Command Substitute for Get-NetFirewallRule in Windows 7:
  95. $(New-object -comObject HNetCfg.FwPolicy2).rules | Format-Table -Property name, protocol, localports
  96.  
  97.  
  98. NETSH INTERFACE IP DELETE ARPCACHE
  99. ARP -D *
  100.  
  101. IPCONFIG /FLUSHDNS
  102.  
  103. NBTSTAT -R
  104.  
  105. NBTSTAT -RR
  106.  
  107.  
  108. defrag c: & sleep 300 & defrag c: /X & sleep 300 & shutdown /s /f /c "After Defrag"
  109.  
  110. %winternals%\psexec \\"HostName_IP" -u "DOMAIN\administrator" -p "Administrator_Password" -s -i wusa "c:\tech\Windows6.1-KB2819745-x64-MultiPkg.msu" /quiet /norestart
  111.  
  112. dnscmd 10.10.x.x /RecordAdd ZONE.local HOSTNAME /Aging /OpenAcl A 10.0.x.x
  113.  
  114. wmic datafile where name='C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe' get /format:list
  115.  
  116. ## File HASH - certutil -hashfile FILENAME.EXT MD5 {MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512]
  117.  
  118.  
  119. MSG USERNAME/* /SERVER:HOSTNAME "HELLO"
  120.  
  121.  
  122. ## icacls c:\ /reset /t /c
  123.  
  124. Timout /T 300 /nobreak
  125.  
  126. < ------------------------------------------ >
  127.  
  128. gpresult /Scope User /v
  129.  
  130. gpresult /Scope computer /v
  131.  
  132. < ------------------------------------------ >
  133.  
  134.  
  135. wmic diskdrive get PNPDeviceID
  136.  
  137. wmic path CIM_LogicalDevice where "Description like 'USB%'" get /value
  138.  
  139. PowerShell EQ gwmi Win32_USBControllerDevice |fl Antecedent,Dependent
  140. gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)} | Sort Description,DeviceID | ft Description,DeviceID -auto
  141.  
  142.  
  143.  
  144. < ------------------ Windows 10 - Remote Registry Disabled by default ------------------ >
  145.  
  146.  
  147. sc \\HOSTNAME config remoteregistry start= demand
  148.  
  149. sc \\HOSTNAME start remoteregistry
  150.  
  151. reg query "\\HOSTNAME\HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\DataCollection"
  152.  
  153. sc \\HOSTNAME stop remoteregistry
  154.  
  155. sc \\HOSTNAME config remoteregistry start= disabled
  156.  
  157.  
  158. < ------------------ Windows 10 - Remote Registry Disabled by default ------------------ >
  159.  
  160.  
  161.  
  162.  
  163. ---=== Change Computer Description Remotely ===---
  164.  
  165. sc \\HOSTNAME query remoteregistry
  166.  
  167. sc \\HOSTNAME start remoteregistry
  168.  
  169. reg query "\\HOSTNAME\HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
  170.  
  171. reg add "\\HOSTNAME\HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" /v srvcomment /t REG_SZ /d "Computer Description Text" /f
  172.  
  173. sc \\HOSTNAME stop remoteregistry
  174.  
  175.  
  176.  
  177. < -------------------------------------------------------------------------- [Change Description of Remote Machine] -------------------------------------------------------------------------- >
  178.  
  179. Invoke-Command -ComputerName HOSTNAME -ScriptBlock {$OSWMI=Get-WmiObject -class Win32_OperatingSystem;$OSWMI.Description=$args[0];$OSWMI.put() } -ArgumentList("DESCRIPTION")
  180.  
  181.  
  182. Set-WmiInstance -Path "\\HOSTNAME\root\cimv2:Win32_OperatingSystem=@" -Arguments @{description="Description Here"}
  183.  
  184.  
  185. < -------------------------------------------------------------------------- [Change Description of Remote Machine] -------------------------------------------------------------------------- >
  186.  
  187.  
  188.  
  189.  
  190. < -------------------------------------------------------------------------- [Original Script] -------------------------------------------------------------------------- >
  191.  
  192. ########################################################################################
  193. ##
  194. ## https://www.alexandreviot.net/2015/05/03/powershell-change-computer-description/
  195. ##
  196. ########################################################################################
  197.  
  198. $myDescription="My Server"
  199. Invoke-Command -ComputerName $lServerName -ScriptBlock {$OSWMI=Get-WmiObject -class Win32_OperatingSystem;$OSWMI.Description=$args[0];$OSWMI.put() } -ArgumentList($myDescription)
  200.  
  201. < -------------------------------------------------------------------------- [Original Script] -------------------------------------------------------------------------- >
  202.  
  203.  
  204.  
  205. ---=== Change Computer Description Remotely ===---
  206.  
  207.  
  208.  
  209. reg query \\HOSTNAME\HKLM\software\wow6432node\Microsoft\Windows\currentversion\Uninstall /f "gdc*" /s
  210. reg query \\HOSTNAME\HKLM\software\Microsoft\Windows\currentversion\Uninstall /f "gdc*" /s
  211.  
  212.  
  213. < ----------------------------------- [ Computer Description ] ------------------------------------------------------------------------------------ >
  214.  
  215. reg query \\[HOSTNAME/IP]\HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\lanmanserver\parameters /f srvcomment
  216.  
  217.  
  218. wmic /node:[HOSTNAME/IP] os set Description="Descriptive Text Here"
  219.  
  220.  
  221. REG ADD "\\[HOSTNAME/IP]\HKLM\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters /v srvcomment /t REG_SZ /d "your description here" /f
  222.  
  223.  
  224. < ----------------------------------- [ Computer Description ] ------------------------------------------------------------------------------------ >
  225.  
  226.  
  227.  
  228. ########################### UltraVNC Install & Start Service #########################################################################
  229.  
  230.  
  231. sc \\REMOTE_HOST query uvnc_service
  232.  
  233. sc \\REMOTE_HOST start uvnc_service
  234.  
  235. sc \\REMOTE_HOST query state= all | find /I "vnc"
  236.  
  237. sc \\REMOTE_HOST start remoteregistry
  238.  
  239.  
  240. %winternals%\psexec \\REMOTE_HOST "c:\Program Files\UltraVNC\winvnc.exe" -install
  241.  
  242. %winternals%\psexec \\REMOTE_HOST "c:\Program Files\UltraVNC\winvnc.exe" -startservice
  243.  
  244.  
  245. Invoke-Command -ComputerName REMOTE_HOST -ScriptBlock {& cmd /c "c:\Program files\ultravnc\winvnc.exe" -install}
  246.  
  247. Invoke-Command -ComputerName REMOTE_HOST -ScriptBlock {& cmd /c "c:\Program files\ultravnc\winvnc.exe" -startservice}
  248.  
  249.  
  250. sc \\REMOTE_HOST query uvnc_service
  251.  
  252.  
  253. ########################### UltraVNC Install & Start Service #########################################################################
  254.  
  255.  
  256. "Set-NetFirewallRule -DisplayName “File and Printer Sharing (Echo Request – ICMPv4-In)” -enabled True"
  257.  
  258.  
  259.  
  260.  
  261. < ---------------------------------------------- External/Public IP Address ---------------------------------------------- >
  262.  
  263.  
  264. Invoke-RestMethod http://ipinfo.io/json | Select -exp ip
  265.  
  266.  
  267. (Invoke-RestMethod http://ipinfo.io/json).ip
  268.  
  269. (Invoke-RestMethod http://ipinfo.io/json).hostname
  270.  
  271. (Invoke-RestMethod http://ipinfo.io/json).city
  272.  
  273. (Invoke-RestMethod http://ipinfo.io/json).region
  274.  
  275. (Invoke-RestMethod http://ipinfo.io/json).country
  276.  
  277. (Invoke-RestMethod http://ipinfo.io/json).loc
  278.  
  279. (Invoke-RestMethod http://ipinfo.io/json).org
  280.  
  281.  
  282. (Invoke-WebRequest http://ipinfo.io/ip).Content.Trim()
  283.  
  284.  
  285. Invoke-RestMethod ipecho.net/plain
  286.  
  287.  
  288. Invoke-WebRequest http://ifconfig.me/ip
  289.  
  290.  
  291. invoke-restmethod https://api.ipify.org?format=json | select -exp ip
  292.  
  293. (Invoke-WebRequest IPv4.Icanhazip.com).Content
  294.  
  295.  
  296. (Invoke-WebRequest "http://checkip.dyndns.com").ParsedHTML.body.innerHtml
  297.  
  298.  
  299.  
  300. icm -ComputerName HOSTNAME -ScriptBlock {Invoke-RestMethod http://ipinfo.io/json | Select -exp ip}
  301.  
  302. Invoke-Command -ComputerName HOSTNAME -ScriptBlock {Invoke-RestMethod http://ipinfo.io/json | Select -exp ip}
  303.  
  304.  
  305.  
  306. (new-object System.Net.WebClient).DownloadString("http://myexternalip.com/raw")
  307.  
  308. (Invoke-WebRequest -URI http://myexternalip.com/raw).content
  309.  
  310. (Invoke-WebRequest -URI http://myip.dnsomatic.com/).content
  311.  
  312.  
  313. curl ifcfg.me
  314. nslookup . ifcfg.me
  315. telnet ifcfg.me
  316. ftp ifcfg.me
  317. finger @ifcfg.me
  318.  
  319.  
  320.  
  321.  
  322. Invoke-WebRequest -Uri https://www.hackthebox.eu/api/invite/generate -Method POST
  323.  
  324.  
  325.  
  326. %winternals%\psexec \\HOSTNAME nslookup myip.opendns.com. resolver1.opendns.com
  327.  
  328.  
  329.  
  330. dig +short myip.opendns.com @resolver1.opendns.com
  331.  
  332.  
  333.  
  334. < ---------------------------------------------- External/Public IP Address ---------------------------------------------- >
  335.  
  336.  
  337. Get-WmiObject -Class "Win32_NetworkAdapterConfiguration" -ComputerName 127.0.0.1 -Filter "IpEnabled = TRUE" | foreach { write-host $_.IpAddress[0]}
  338.  
  339.  
  340. (Get-WmiObject Win32_NetworkAdapterConfiguration | where { (($_.IPEnabled -ne $null) -and ($_.DefaultIPGateway -ne $null)) } | select IPAddress -First 1).IPAddress[0]
  341.  
  342.  
  343. Get-WmiObject Win32_NetworkAdapterConfiguration
  344.  
  345. (Get-WmiObject Win32_NetworkAdapterConfiguration -EA).IpAddress[0]
  346.  
  347. (Get-WmiObject Win32_NetworkAdapterConfiguration).IpAddress[0]
  348.  
  349. (Get-WmiObject Win32_NetworkAdapterConfiguration).IpAddress[0]
  350.  
  351. (Get-WmiObject Win32_NetworkAdapterConfiguration).IpAddress
  352.  
  353. (Get-WmiObject Win32_NetworkAdapterConfiguration).IpAddress[1]
  354.  
  355. (Get-WmiObject Win32_NetworkAdapterConfiguration).IpAddress[0]
  356.  
  357. (Get-WmiObject Win32_NetworkAdapterConfiguration).IPSubnet
  358.  
  359. (Get-WmiObject Win32_NetworkAdapterConfiguration).DefaultIPGateway
  360.  
  361. (Get-WmiObject Win32_NetworkAdapterConfiguration).DNSServerSearchOrder
  362.  
  363. (Get-WmiObject Win32_NetworkAdapterConfiguration).DHCPEnables
  364.  
  365. (Get-WmiObject Win32_NetworkAdapterConfiguration).DHCPEnabled
  366.  
  367. (Get-WmiObject Win32_NetworkAdapterConfiguration).DHCPEnabled[0]
  368.  
  369. Get-WmiObject -Class Win32_Networkadapterconfiguration | ? {$_.IPEnabled -eq $true }
  370.  
  371. Get-WmiObject -Class Win32_Networkadapterconfiguration | ? {$_.DHCPEnabled -eq $true }
  372.  
  373. Get-WmiObject -Class Win32_Networkadapterconfiguration | ? {$_.IPEnabled -eq $true } ? {$_.DHCPEnabled -eq $true }
  374.  
  375. Get-WmiObject -Class Win32_Networkadapterconfiguration | ? {$_.IPEnabled -eq $true } | ? {$_.DHCPEnabled -eq $true }
  376.  
  377. Get-WmiObject -Class Win32_IP4RouteTable -ComputerName HOSTNAME | select destination,mask,nexthop, metric1
  378.  
  379. Get-WmiObject -namespace root\wmi –class MSStorageDriver_FailurePredictStatus -ErrorAction Silentlycontinue | Select InstanceName, PredictFailure, Reason | Format-Table –Autosize
  380.  
  381.  
  382. < ############################################################################## Powershell Basic Commands ############################################################################## >
  383.  
  384. < ########################################################################################### >
  385. < ############################## ############################## >
  386. < ############################## Set IP Address, Gateway, DNS ############################## >
  387. < ############################## ############################## >
  388. < ########################################################################################### >
  389.  
  390. New-NetIPAddress -InterfaceAlias Ethernet -IPAddress 172.16.0.20 -PrefixLength 24 -DefaultGateway 172.16.0.1
  391.  
  392. Set-DNSClientServerAddress -InterfaceAlias "Ethernet" -ServerAddress 172.16.0.10
  393.  
  394.  
  395. Test-NetConnection 8.8.8.8
  396. Test-NetConnection www.bing.com -traceroute
  397. Test-NetConnection smtp.com -Port 25
  398. Test-NetConnection www.bing.com -Port 80
  399.  
  400.  
  401. Restart-Service
  402.  
  403. Get-service | Out-GridService
  404.  
  405. Rename-Computer COMPUTERNAME01
  406.  
  407. Restart-Computer
  408.  
  409. Shutdown-Computer
  410.  
  411. Add-Computer -DomainName Domain.Name
  412.  
  413. Install-WindowsFeature -IncludeAllSubFeatures -INcludeManagementTools File-Services
  414.  
  415. Install-WindowsFeature Net-Framework-Core -source d:\sources\sxs
  416.  
  417. Test-ComputerSecureChannel -Credential Domain\Admin -Repair
  418.  
  419. Set-NetFirewallProfile -Profile domain,public,private -Enabled {False | True}
  420.  
  421.  
  422.  
  423.  
  424.  
  425. < ############################################################################## Powershell Basic Commands ############################################################################## >
  426.  
  427.  
  428.  
  429.  
  430.  
  431. < -------------------------------------------------------------------------- Simple List of Shared Folders -------------------------------------------------------------------------- >
  432. < ##
  433. < ## https://superuser.com/questions/769679/powershell-get-list-of-folders-shared
  434. < ##
  435. < ## ---------------------------------------------------------------------------- >
  436.  
  437. (net view \\HOSTNAME) | % { if($_.IndexOf(' Disk ') -gt 0){ $_.Split(' ')[0] } }
  438.  
  439.  
  440. $Servers = ( Get-ADComputer -Filter { DNSHostName -Like '*' } | Select -Expand Name )
  441. foreach ($Server in $Servers)
  442. {
  443. (net view $Server) | % { if($_.IndexOf(' Disk ') -gt 0){ $_.Split(' ')[0] } } | out-file C:\file_shares\$Server.txt
  444. }
  445.  
  446. < -------------------------------------------------------------------------- Simple List of Shared Folders -------------------------------------------------------------------------- >
  447.  
  448.  
  449.  
  450. ([WMI]'').ConvertToDateTime((Get-WmiObject Win32_OperatingSystem).InstallDate)
  451.  
  452. ([WMI]'').ConvertToDateTime((Get-WmiObject Win32_OperatingSystem -ComputerName HOSTNAME).InstallDate)
  453.  
  454. [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($(get-itemproperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion').InstallDate))
  455.  
  456.  
  457. < ----------------------------------------- [AD Computer LastLogon Conversion] ----------------------------------------- >
  458.  
  459. w32tm /ntte 131625959999922000
  460.  
  461. [Excel]
  462.  
  463. =IF(P15>0,P15/(8.64*10^11) - 109205,"")
  464.  
  465. =((P15/10000000/3600/24)-109205)-0.166673
  466.  
  467. [Excel]
  468.  
  469. < ----------------------------------------- [AD Computer LastLogon Conversion] ----------------------------------------- >
  470.  
  471. gwmi win32_systemenclosure | select PSComputerName,ChassisTypes,LockPresent,Manufacturer,Name,SecurityStatus,SerialNumber,SMBIOSAssetTag,Tag
  472.  
  473. GWMI WIN32_NETWORKADAPTERCONFIGURATION -COMPUTER HOSTNAME | SELECT Description,MACAddress,IPAddress
  474.  
  475. gwmi win32_physicalmemoryarray | select PSComputerName,Caption,MaxCapacity,Tag
  476.  
  477. gwmi win32_physicalmemory | select PSComputerName,Capacity,Caption,Description,DeviceLocator,FormFactor,Manufacturer,Name,OtherIdentifyingInfo,PartNumber,PositionInRow,SerialNumber,SKU,Speed,Tag,TotalWidth,TypeDetail
  478.  
  479. gwmi win32_networkadapterconfiguration -ComputerName HOSTNAME | select PSComputername,Index,Description,DHCPEnabled,DNSDomain,DNSDomainSuffixSearchOrder,DNSHostName,DNSServerSearchOrder,FullDNSRegistrationEnabled,IPAddress,IPEnabled,Caption,DefaultIPGateway,IPSubnet,MACAddress,ServiceName | where {$_.Index -eq '1'}
  480.  
  481. gwmi win32_networkadapterconfiguration -ComputerName HOSTNAME | select * | where {$_.Index -eq '1'}
  482.  
  483.  
  484. (Get-WMIObject -class Win32_PhysicalMemory -ComputerName SERVER | Measure-Object -Property capacity -Sum | % {[Math]::Round(($_.sum / 1GB),2)})
  485.  
  486.  
  487. Get-ADComputer -filter {Name -like '*08'} | Foreach-Object {[math]::Round((Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory/1GB)} | Format-Table -property * -AutoSize
  488.  
  489.  
  490. Get-ADComputer -filter {Name -like '*08'} | Foreach-Object {Get-WmiObject -Class Win32_ComputerSystem -ErrorAction SilentlyContinue -ComputerName $_.Name | Select-Object PSComputerName, @{Name="Memory"; Expression={[math]::Round($_.TotalPhysicalMemory/1GB)}}}
  491.  
  492. Get-ADComputer -filter {Name -like '*08'} | Foreach-Object {Get-WmiObject -Class Win32_ComputerSystem -ErrorAction SilentlyContinue -ComputerName $_.Name | Select-Object PSComputerName,Manufacturer,Model, @{Name="Memory"; Expression={[math]::Round($_.TotalPhysicalMemory/1GB)}}}
  493.  
  494.  
  495. Get-ADComputer -filter {Name -like '*ComputerName*'} | Foreach-Object {Get-WmiObject -ErrorAction SilentlyContinue -Class Win32_ComputerSystem -ComputerName $_.Name}
  496.  
  497. Get-ADComputer -filter {Name -like '*ComputerName*'} | Foreach-Object {Get-WmiObject -ErrorAction SilentlyContinue -Class Win32_ComputerSystem -ComputerName $_.Name | Select-Object *} | Format-Table -Property * -AutoSize | Out-String -Width 4096
  498.  
  499. Get-ADComputer -filter {Name -like '*ComputerName*'} | Foreach-Object {Get-WmiObject -ErrorAction SilentlyContinue -Class Win32_ComputerSystem -ComputerName $_.Name | Select-Object PSComputerName,Status,Name,BootROMSupported,BootStatus,Caption,CurrentTimeZone,DaylightInEffect,mDNSHostNamem,Domain,DomainRole,EnableDaylightSavingsTime,HypervisorPresent,InstallDate,LastLoadInfo,Manufacturer,Model,NumberOfLogicalProcessors,NumberOfProcessors,PartOfDomain,PauseAfterReset,PrimaryOwnerContact,PrimaryOwnerName,Roles,SystemFamily,SystemSKUNumber,SystemType,TotalPhysicalMemory,UserName} | Format-List -Property * | Out-String -Width 4096
  500.  
  501. Get-ADComputer -filter {Name -like '*ComputerName*'} | Foreach-Object {Get-WmiObject -ErrorAction SilentlyContinue -Class Win32_ComputerSystem -ComputerName $_.Name | Select-Object PSComputerName,Status,Name,BootROMSupported,BootStatus,Caption,CurrentTimeZone,DaylightInEffect,mDNSHostNamem,Domain,DomainRole,EnableDaylightSavingsTime,HypervisorPresent,InstallDate,LastLoadInfo,Manufacturer,Model,NumberOfLogicalProcessors,NumberOfProcessors,PartOfDomain,PauseAfterReset,PrimaryOwnerContact,PrimaryOwnerName,Roles,SystemFamily,SystemSKUNumber,SystemType,TotalPhysicalMemory,UserName} | ConvertTo-Csv -UseCulture
  502.  
  503. Get-ADComputer -filter * -SearchBase "OU=ORG_UNIT_1,DC=DOMAIN,DC=local" | Foreach-Object {Test-Connection -ErrorAction SilentlyContinue -ComputerName $_.Name}
  504.  
  505.  
  506. gwmi win32_diskdrive | select PSComputerName,Status,DeviceID,Partitions,BytesPerSector,InstallDate,InterfaceType,SectorsPerTrack,Size,TotalCylinders,TotalHeads,TotalSectors,TotalTracks,TracksPerCylinder,Capabilities,CapabilityDescriptions,Caption,Description,FirmwareRevision,Manufacturer,MediaLoaded,MediaType,Model,Name,PNPDeviceID,SerialNumber,Signature,SystemName
  507.  
  508. gwmi -ComputerName HOSTNAME WIN32_COMPUTERSYSTEM | SELECT PSComputerName,PowerSupplyState,PowerState,Name,BootROMSupported,Caption,DaylightInEffect,DNSHostName,Domain,HypervisorPresent,InstallDate,Manufacturer,Model,SystemType,TotalPhysicalMemory,Username
  509.  
  510. Get-ADComputer -filter * | Foreach-Object {Get-WmiObject -Class Win32_BIOS -ComputerName $_.Name -erroraction silentlycontinue | Select-Object PSComputerName, Serialnumber | FT * -AutoSize}
  511.  
  512.  
  513. cat "C:\Test\Filename.txt" | where {$_.Contains("Error")} | Write-Host -ForegroundColor Red
  514.  
  515. cat "C:\Test\Filename.txt" | where {$_.Contains("Information")} | Write-Host -ForegroundColor Yellow
  516.  
  517. Get-Content 'C:\Test\Filename.txt' | ? { $_ -match "Error" -and $_ -match "PM"} | Write-Host -ForegroundColor Yellow
  518.  
  519.  
  520.  
  521. (Get-ADDomain).PDCEmulator
  522.  
  523.  
  524. Get-ADUser -filter * -SearchBase "OU=ORG_UNIT_1,DC=DOMAIN,DC=local" -Properties MemberOf
  525.  
  526. (Get-ADUser -filter * -SearchBase "OU=ORG_UNIT_1,DC=DOMAIN,DC=local" -Properties MemberOf).memberof
  527.  
  528. Get-ADUser -filter * -SearchBase "OU=ORG_UNIT_1,DC=DOMAIN,DC=local" -Properties MemberOf
  529.  
  530. Get-ADUser -filter * -SearchBase "OU=ORG_UNIT_1,DC=DOMAIN,DC=local" -Properties *
  531.  
  532. Get-ADUser -filter * -SearchBase "OU=CONTOSO,DC=DOMAIN,DC=local" -Properties DisplayName,Enabled,Lockedout,ProtectedFromAccidentalDeletion
  533.  
  534. Get-ADUser -filter * -SearchBase "OU=ORG_UNIT_1,DC=DOMAIN,DC=local" -Properties * | select DisplayName,Enabled,Lockedout,ProtectedFromAccidentalDeletion
  535.  
  536. Get-ADUser -filter * -SearchBase "DC=DOMAIN,DC=local" -Properties * | select DisplayName,Enabled,Lockedout,ProtectedFromAccidentalDeletion
  537.  
  538. Get-ADUser -filter * -SearchBase "DC=DOMAIN,DC=local" -Properties * | select DisplayName,Enabled,Lockedout,ProtectedFromAccidentalDeletion | where { $_.DisplayName -like 'Connie*'} | Format-Table -AutoSize *
  539.  
  540. Get-ADUser -filter * -SearchBase "DC=DOMAIN,DC=local" -Properties * | select DisplayName,Enabled,Lockedout,ProtectedFromAccidentalDeletion | where { $_.DisplayName -like '*WIC*'} | Format-Table -AutoSize *
  541.  
  542. Get-ADUser -filter * -SearchBase "DC=DOMAIN,DC=local" -Properties * | select DisplayName,Enabled,Lockedout,ProtectedFromAccidentalDeletion | where { $_.DisplayName -like '*WIC'} | Format-Table -AutoSize *
  543.  
  544. Get-ADUser -filter * -SearchBase "DC=DOMAIN,DC=local" -Properties * | select DisplayName,Enabled,Lockedout,ProtectedFromAccidentalDeletion | where { $_.DisplayName -like 'Scott'} | Format-Table -AutoSize *
  545.  
  546. Get-ADUser -filter * -SearchBase "DC=DOMAIN,DC=local" -Properties * | select DisplayName,Enabled,Lockedout,ProtectedFromAccidentalDeletion | where { $_.DisplayName -like 'Scott*'} | Format-Table -AutoSize *
  547.  
  548. Get-ADUser -filter * -SearchBase "DC=DOMAIN,DC=local" -Properties * | select DisplayName,Enabled,Lockedout,ProtectedFromAccidentalDeletion | where { $_.DisplayName -like '*Bo*'} | Format-Table -AutoSize *
  549.  
  550. Get-ADUser -filter * -SearchBase "DC=DOMAIN,DC=local" -Properties * | select DisplayName,SamAccountName,Title,Enabled,Lockedout,PasswordExpired,ProtectedFromAccidentalDeletion | where { $_.SamAccountName -like 'Username'}
  551.  
  552. Get-ADUser -filter * -SearchBase "DC=CONTOSO,DC=local" -Properties * | select DisplayName,SamAccountName,Title,Enabled,Lockedout,ProtectedFromAccidentalDeletion | where { $_.DisplayName -like 'Name*'}
  553.  
  554. Get-ADUser -filter * -SearchBase "DC=CONTOSO,DC=local" -Properties * | select DisplayName,SamAccountName,Title,Enabled,Lockedout,ProtectedFromAccidentalDeletion | where { $_.SamAccountName -eq 'Username'}
  555.  
  556. Get-ADUser -filter * -SearchBase "DC=CONTOSO,DC=local" -Properties * | select DisplayName,SamAccountName,Title,Enabled,Lockedout,PasswordExpired,ProtectedFromAccidentalDeletion | where { $_.SamAccountName -like 'Username'}
  557.  
  558. Get-ADUser -filter * -SearchBase "OU=ITDept,OU=DO/DEPARTMENT,DC=CONTOSO,DC=local" -Properties * | select DisplayName,SamAccountName,Title,Enabled,Lockedout,ProtectedFromAccidentalDeletion
  559.  
  560. Get-ADUser -filter * -SearchBase "OU=ITDept,OU=DO/DEPARTMENT,DC=CONTOSO,DC=local" -Properties * | select DisplayName,SamAccountName,Title,Enabled,Lockedout,ProtectedFromAccidentalDeletion,Company,Department,Name,Title
  561.  
  562. Get-ADUser -filter * -SearchBase "OU=ITDept,OU=DO/DEPARTMENT,DC=CONTOSO,DC=local" -Properties * | select DisplayName,SamAccountName,Title,Enabled,Lockedout,ProtectedFromAccidentalDeletion,Company,Department,Name
  563.  
  564. Get-ADUser -filter * -SearchBase "OU=ITDept,OU=DO/DEPARTMENT,DC=CONTOSO,DC=local" -Properties * | select DisplayName,SamAccountName,Title,Enabled,Lockedout,ProtectedFromAccidentalDeletion,Company,Department,Name | where {$_.Enabled -eq 'True'}
  565.  
  566. Get-ADUser -filter * -SearchBase "OU=ITDept,OU=DO/DEPARTMENT,DC=CONTOSO,DC=local" -Properties * | select DisplayName,SamAccountName,Title,Enabled,Lockedout,ProtectedFromAccidentalDeletion,Company,Department,Name | where {$_.Enabled -eq 'True'}
  567.  
  568. Get-ADUser -filter * -SearchBase "OU=ITDept,OU=DO/DEPARTMENT,DC=CONTOSO,DC=local" -Properties * | select DisplayName,SamAccountName,Title,Enabled,Lockedout,ProtectedFromAccidentalDeletion,Company,Department,Name,OfficePhone | where {$_.Enabled -eq 'True'}
  569.  
  570. Get-ADUser -filter * -SearchBase "OU=ITDept,OU=DO/DEPARTMENT,DC=CONTOSO,DC=local" -Properties * | select DisplayName,SamAccountName,Title,Enabled,Lockedout,ProtectedFromAccidentalDeletion,Company,Department,Name,OfficePhone | where {$_.Enabled -eq 'True'} | where {$_.SamAccountName -eq 'Username'}
  571.  
  572. Get-ADUser -filter * -SearchBase "OU=ITDept,OU=DO/DEPARTMENT,DC=CONTOSO,DC=local" -Properties * | where {$_.Enabled -eq 'True'} | where {$_.SamAccountName -eq 'Username'}
  573.  
  574. Get-ADUser -filter * -SearchBase "OU=ITDept,OU=DO/DEPARTMENT,DC=CONTOSO,DC=local" -Properties * | where {$_.Enabled -eq 'True'} | where {$_.SamAccountName -eq 'Username'} | Set-ADUser -PasswordNeverExpires:$True
  575.  
  576. Get-ADUser -Filter {(ObjectClass -eq "user")} -SearchBase "OU=Offices,DC=Contoso,DC=com" | Set-ADUser -PasswordNeverExpires:$FALSE
  577.  
  578. Get-ADUser -filter * -SearchBase "OU=ITDept,OU=DO/DEPARTMENT,DC=CONTOSO,DC=local" -Properties * | where {$_.Enabled -eq 'True'} | where {$_.SamAccountName -eq 'Username'}
  579.  
  580. Get-ADUser -filter * -SearchBase "DC=CONTOSO,DC=local" -Properties * | where {$_.Enabled -eq 'True'} | where {$_.SamAccountName -eq 'Username'}
  581.  
  582. Get-ADUser -filter * -SearchBase "DC=CONTOSO,DC=local" -Properties * | where {$_.SamAccountName -eq 'Username'}
  583.  
  584. Get-ADUser -filter * -SearchBase "DC=CONTOSO,DC=local" -Properties * | where {($_.PasswordNeverExpires -eq 'True') -or ($_.CannotChangePassword -eq 'True') -and ($_.DisplayName -notlike '*Terminated*') -and ($_.Description -notlike '*terminated*')} | select DisplayName,SamAccountName,Title,Description,Enabled,Lockedout,PasswordNeverExpires,CannotChangePassword | ConvertTo-Csv | Filename.csv
  585.  
  586. Get-AdUser -Filter 'PasswordNeverExpires -eq $false' -SearchBase "OU=users,DC=domain,DC=com" -Properties Name, Manager, Title, AccountExpirationDate, LastLogonDate | Select-Object Name, SamAccountName, Manager, Title, AccountExpirationDate, LastLogonDate | Export-CSV c:\Test\Testusers_expirationdate.csv -NoTypeInformation
  587.  
  588. Get-ADUser -filter * -properties passwordlastset, passwordneverexpires | sort-object name | select-object Name, passwordlastset, passwordneverexpire
  589.  
  590. Get-ADUser -filter {name -like 'Administrator'} -properties passwordlastset, passwordneverexpires | sort-object name | select-object Name, passwordlastset, passwordneverexpire
  591.  
  592. Get-ADUser -filter * -properties passwordlastset, passwordneverexpires | sort-object name | select-object Name, passwordlastset, passwordneverexpires | Export-csv -path c:\yaniv.csv
  593.  
  594. Get-ADUser -Filter * -SearchBase "DC=CONTOSO,DC=local" -ResultPageSize 0 -Property CN, Description, LastLogonTimestamp | Select-Object -Property CN, Description, @{ n = "LastLogonDate"; e = { [datetime]::FromFileTime( $_.lastLogonTimestamp ) } } | Sort-Object -Property CN, Description, LastLogonDate | Export-CSV -NoTypeInformation "C:\test\lastlogon.csv"
  595.  
  596. Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" |Select-Object -Property "Displayname",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}} | out-gridview
  597.  
  598. Get-ADUser Username -Properties * | Select Name,Enabled,PasswordExpired,PasswordNeverExpires,SamAccountName,Title,Description,EmailAddress,OfficePhpone,TelephoneNumber,Department,Company,City,State
  599.  
  600.  
  601.  
  602. get-adcomputer -filter {operatingsystem -like "*2008*" -or operatingsystem -like "*2012*"} -Properties operatingsystem | Select Name,OperatingSystem
  603.  
  604. get-adcomputer -filter {operatingsystem -like "*2003*"} -Properties operatingsystem | Select Name,OperatingSystem
  605.  
  606. get-adcomputer -filter {operatingsystem -like "*server*"} -Properties operatingsystem | Select Name,OperatingSystem
  607.  
  608. get-adcomputer -filter {operatingsystem -like "*2003*"} -Properties operatingsystem | Select Name,OperatingSystem
  609.  
  610. get-adcomputer -filter {operatingsystem -like "*2008*"} -Properties operatingsystem | Select Name,OperatingSystem
  611.  
  612. get-adcomputer -filter {operatingsystem -like "*2012*"} -Properties operatingsystem | Select Name,OperatingSystem
  613.  
  614. get-adcomputer -filter {operatingsystem -ne "*Windows Server*"} -Properties operatingsystem | Select Name,OperatingSystem
  615.  
  616. get-adcomputer -filter {operatingsystem -ne "*Windows Server*"} -Properties Description | Select Description,Enabled,Name,ObjectClass
  617.  
  618. get-adcomputer -filter {operatingsystem -ne "*Windows Server*" -and Enabled -eq "False"} -Properties Description | Select Description,Enabled,Name,ObjectClass
  619.  
  620. get-adcomputer -filter {operatingsystem -ne "*Windows*"} -Properties operatingsystem | Select Name,OperatingSystem
  621.  
  622. get-adcomputer -filter {operatingsystem -like "*Windows XP*"} -Properties operatingsystem | Select Name,OperatingSystem
  623.  
  624. get-adcomputer -filter {operatingsystem -like "*2008*" -or operatingsystem -like "*2012*"} -Properties BadLogonCount,badPwdCount,CanonicalName,Created,Description,DNSHostName,Enabled,IPv4Address,isDeleted,LastBadPasswordAttempt,LastLogonDate,LockedOut,LogonCount,Name,ObjectClass,OperatingSystem,OperatingSystemHotFix,OperatingSystemServicePack,OperatingSystemVersion,ProtectedFromAccidentalDeletion
  625.  
  626. get-adcomputer -filter {operatingsystem -like "*2008*" -or operatingsystem -like "*2012*"} -Properties BadLogonCount,badPwdCount,CanonicalName,Created,Description,DNSHostName,Enabled,IPv4Address,isDeleted,LastBadPasswordAttempt,LastLogonDate,LockedOut,LogonCount,Name,ObjectClass,OperatingSystem,OperatingSystemHotFix,OperatingSystemServicePack,OperatingSystemVersion,ProtectedFromAccidentalDeletion | ConvertTo-Csv > FileName.csv
  627.  
  628. Get-ADComputer -Filter 'Name -like "HOSTNAME"' -Properties * | Select CannotChangePassword,BadPwdCount,CanonicalName,CN,Created,Deleted,Description,DisplayName,DistinguishedName,DNSHostName,Enabled,IPv4Address,IPv6Address,isCriticalSystemObject,isDeleted,lastLogoff,lastLogon,LockedOut,logonCount,Name,OperatingSystem,OperatingSystemHotfix,OperatingSystemServicePack,OperatingSystemVersion,ProtectedFromAccidentalDeletion | ConvertTo-Csv
  629.  
  630. Get-ADComputer -Filter {Name -like "HOSTNAME" -or Name -like "HOSTNAME2"} -Properties * | Select Name,DNSHostName,CanonicalName,DistinguishedName,CannotChangePassword,BadPwdCount,CN,Created,Deleted,Description,DisplayName,Enabled,IPv4Address,IPv6Address,isCriticalSystemObject,isDeleted,lastLogoff,lastLogon,LockedOut,logonCount,OperatingSystem,OperatingSystemHotfix,OperatingSystemServicePack,OperatingSystemVersion,ProtectedFromAccidentalDeletion | ConvertTo-Csv
  631.  
  632. get-adcomputer -filter {Description -like "*ENTRY*"} -Properties * | Select Name,Description,OperatingSystem,OperatingSystemVersion,Created,LastLogonDate,Modified,whenChanged | FL
  633.  
  634.  
  635. Get-ADComputer -Filter * -Properties Name,OperatingSystem ,lastlogontimestamp | Select Name,OperatingSystem ,@{N='lastlogontimestamp'; E={[DateTime]::FromFileTime($_.lastlogontimestamp)}}
  636.  
  637.  
  638. Get-ADComputer -Filter {operatingsystem -like "*windows 7*"} -Properties * | Select CanonicalName,CN,Created,Deleted,Description,DisplayName,DNSHostName,Enabled,IPv4Address,isDeleted,LockedOut,Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion,ProtectedFromAccidentalDeletion | ConvertTo-Csv -UseCulture > WIn-7_AD_PCs_6-28-2017_1.csv
  639.  
  640.  
  641. Get-ADComputer -Filter * -Properties ipv4Address, OperatingSystem | Format-List Name, ipv4*, oper* > c:\users\username\desktop\computers.txt
  642.  
  643. Found on Spiceworks: https://community.spiceworks.com/topic/2081162-powershell-script-to-get-computer-name-ip-last-logon-and-name-of-last-logon?utm_source=copy_paste&utm_campaign=growth
  644.  
  645.  
  646. Search-ADAccount -Accountinactive -TimeSpan 60 -Usersonly | Select name,lastlogondate
  647.  
  648.  
  649. <# ---------------------------------------------------------------------------- Ping color coded UP/Down for IPs pulled from GET-ADComputer ------------------------------------------- #>
  650.  
  651.  
  652. Get-ADComputer -Filter {Name -like '*HOSTNAMES*'} | ForEach {
  653.  
  654. If (Test-Connection -ComputerName $_.Name -Count 1 -Quiet) {
  655.  
  656. Write-Host "$($_.Name) is up" -ForegroundColor Green
  657.  
  658. } Else {
  659.  
  660. Write-Host "$($_.Name) is down" -ForegroundColor Red
  661.  
  662. }
  663.  
  664. }
  665.  
  666. <# ---------------------------------------------------------------------------- Ping color coded UP/Down for IPs pulled from GET-ADComputer ------------------------------------------- #>
  667.  
  668. ##
  669. ## https://social.technet.microsoft.com/Forums/lync/en-US/737b2322-e51c-48a4-9cfe-63ebef9d120a/getadcomputer-to-query-organizational-unit-for-active-computers?forum=winserverpowershell
  670. ##
  671.  
  672. <# ---------------------------------------------------------------------------- CSV Export of IPs pulled from GET-ADComputer to Test-Connection ------------------------------------------- #>
  673.  
  674.  
  675. Get-ADComputer -Filter {Name -like '154*'} | ForEach {
  676.  
  677. $computerName = $_.Name
  678.  
  679. $props = @{
  680. ComputerName = $computerName
  681. Status = ''
  682. }
  683.  
  684. If (Test-Connection -ComputerName $computerName -Count 1 -Quiet) {
  685.  
  686. $props.Status = 'UP'
  687.  
  688. } Else {
  689.  
  690. $props.Status = 'DOWN'
  691.  
  692. }
  693.  
  694. New-Object PsObject -Property $props
  695.  
  696. } | Select ComputerName,Status | Export-Csv .\pingResults.csv -NoTypeInformation
  697.  
  698.  
  699.  
  700. <# ---------------------------------------------------------------------------- CSV Export of IPs pulled from GET-ADComputer to Test-Connection ------------------------------------------- #>
  701.  
  702.  
  703. Get-GPO -All | Sort-Object displayname | Where-Object { If ( $_ | Get-GPOReport -ReportType XML | Select-String -NotMatch "<LinksTo>" ) {$_.DisplayName } }
  704.  
  705.  
  706.  
  707. < --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- >
  708. ## https://social.technet.microsoft.com/Forums/en-US/ff2f5ca5-91d7-43d7-9f45-e9d758dc1257/how-to-filter-multiple-conditions-with-getadcomputer?forum=winserverpowershell
  709. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  710.  
  711. $DaysInactive = 30
  712. $time = (Get-Date).Adddays(-($DaysInactive))
  713.  
  714. Get-ADComputer
  715. -Filter {(Enabled -eq $TRUE -and LastLogonTimeStamp -gt $time)}
  716. -Property *
  717. | ? OperatingSystem -NotLike "*Server*"
  718. |
  719.  
  720. < --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- >
  721.  
  722.  
  723. Invoke-CimMethod -InputObject (Get-CimInstance Win32_Process -Filter "name = 'notepad.exe'") -MethodName GetOwner
  724.  
  725.  
  726. Get-WmiObject win32_process -Filter "Name='PowerShell.exe'" | fl Caption,Name,ProcessName,Handles,CommandLine,CSName,Description,OSName,WindowsVersion,Priority,ProcessID,ThreadCount
  727.  
  728.  
  729. Get-WmiObject Win32_UserProfile | select LocalPath, SID,@{LABEL="last used";EXPRESSION={$_.ConvertToDateTime($_.lastusetime)}}| ft
  730.  
  731.  
  732. get-ciminstance win32_userprofile | ? lastusetime | select lastusetime, localpath,@{LABEL='user';EXPRESSION={(gwmi win32_useraccount -filter "SID = '$($_.sid)'").caption}}
  733.  
  734. gwmi -NS root\cimv2\power -Class win32_PowerPlan | select ElementName, IsActive | ft -a
  735.  
  736.  
  737.  
  738.  
  739. -------------------------------------------------------------------------------------------------
  740.  
  741. $ServicePID = (get-wmiobject win32_service | where { $_.name -eq 'service name'}).processID
  742.  
  743. Stop-Process $ServicePID -Force
  744.  
  745. < ----------------------------------------------------------------------------- >
  746.  
  747. gci | % name
  748.  
  749.  
  750. But it's important to remember that PS isn't all about speed, but functionality.
  751.  
  752. Powershell
  753. gci | ? LastWriteTime -lt (Get-Date).AddDays(-15) | % Name
  754.  
  755.  
  756.  
  757. -------------------------------------------------------------------------------------------------
  758.  
  759.  
  760.  
  761. [ Rename Files ]
  762.  
  763. Get-ChildItem -Filter "*.wav" -Recurse | Rename-Item -NewName {$_.name -replace 'wav','flac' } -whatif
  764.  
  765.  
  766. get-childitem -path "hklm:\software\microsoft\windows\currentversion\uninstall" | Get-ItemProperty | ? {$_.DisplayName -like "paint.net"}
  767.  
  768. gci -path "hklm:\software\microsoft\windows\currentversion\uninstall" | Get-ItemProperty | ? {$_.DisplayName -like "paint.net"}
  769.  
  770. get-childitem -path "hklm:\software\microsoft\windows\currentversion\uninstall" | Get-ItemProperty | Where-Objectd {$_.DisplayName -like "paint.net"}
  771.  
  772.  
  773. Get-ChildItem "hklm:\software\microsoft\windows\currentversion\uninstall" | ForEach-Object {Get-ItemProperty $_.pspath} | where-object {$_.DisplayName} | Foreach-Object {$_.DisplayName}
  774.  
  775. Get-ChildItem "hklm:\software\microsoft\windows\currentversion\uninstall" | ForEach-Object {Get-ItemProperty $_.pspath} | Foreach-Object {$_.DisplayName}
  776.  
  777.  
  778. $files = Get-ChildItem -Path C:\Temp
  779. foreach ($file in $files)
  780. {
  781. $newFileName=$file.Name.Replace("c11","c12")
  782. Rename-Item $file $newFileName
  783. }
  784.  
  785. [ Rename Files ]
  786.  
  787.  
  788.  
  789.  
  790. Get-WmiObject Win32_MappedLogicalDisk -computer <computername> | select name, providername (Mapped Drive)
  791.  
  792.  
  793. Test-Connection -count 1 -computer (Get-Content names.txt) | ForEach { # do something with $_.Address }_
  794.  
  795. 1..254 | ForEach-Object {Test-Connection -ComputerName "192.168.0.$_" -Count 1 -ErrorAction SilentlyContinue}
  796.  
  797. Test-Connection -Count ([Int32]::MaxValue) outlook.office365.com
  798.  
  799. Test-Connection -ErrorAction Silentlycontinue -Count ([Int32]::MaxValue) outlook.office365.com
  800.  
  801.  
  802. < ---###########################################################################################################--- >
  803.  
  804.  
  805.  
  806. while ($true)
  807. {
  808. "$(Get-Date);$(Test-Connection -ComputerName outlook.office365.com -Quiet)"
  809. }
  810.  
  811.  
  812. while ($true)
  813. {
  814. "$(Get-Date);$(Test-Connection -ComputerName outlook.office365.com)"
  815. }
  816.  
  817.  
  818. while ($true){"$(Get-Date);$(Test-Connection -ComputerName outlook.office365.com)"}
  819.  
  820.  
  821. < ---###########################################################################################################--- >
  822.  
  823.  
  824.  
  825. < ################################### Compare Folder Hashes ################################### >
  826.  
  827. $LeftFolder = "C:\Users\Username\Downloads\Dell\Skylake\Win7_x64_Dell_OEM"
  828. $RightFolder = "E:\Scott\ISO\Win7_x64_Dell_OEM"
  829. $LeftSideHash = Get-ChildItem $LeftFolder -Recurse | Get-FileHash | select @{Label="Path";Expression={$_.Path.Replace($LeftFolder,"")}},Hash
  830. $RightSideHash = Get-ChildItem $RightFolder -Recurse | Get-FileHash | select @{Label="Path";Expression={$_.Path.Replace($RightFolder,"")}},Hash
  831. Compare-Object $LeftSideHash $RightSideHash -Property Path,Hash
  832.  
  833. < ################################### Compare Folder Hashes ################################### >
  834.  
  835.  
  836.  
  837. Get-Service | select *
  838.  
  839. Get-Service -Name 'PRTG*' | select *
  840.  
  841. Get-Service | select Name,Status,RequiredServices,StartType
  842.  
  843. Get-Service -Name 'PRTG*' | select Name,Status,RequiredServices,StartType
  844.  
  845. get-service -ComputerName HOSTNAME winrm -requiredServices
  846.  
  847. get-service -name winrm -computername localhost, Server01, Server02 | format-table -property MachineName, Status, Name, DisplayName -auto
  848.  
  849. get-service s* | sort-object status -descending
  850.  
  851. get-service | where-object {$_.DependentServices} | format-list -property Name, DependentServices, @{Label="NoOfDependentServices"; Expression={$_.dependentservices.count}}
  852.  
  853. get-service -ComputerName HOSTNAME | where-object {$_.Status -eq "Running"}
  854.  
  855. get-service -ComputerName HOSTNAME | where {$_.Name -like "Mps*"}
  856.  
  857. get-Service -Name mpssvc -ComputerName HOSTNAME | start-service
  858.  
  859. set-service -name lanmanworkstation -DisplayName "LanMan Workstation"
  860.  
  861. Get-Service
  862. New-Service
  863.  
  864. Restart-Service
  865.  
  866. Get-Service -Name "net*" | Where-Object {$_.Status -eq "Stopped"} | Restart-Service
  867.  
  868.  
  869. Resume-Service
  870. Start-Service
  871. Stop-Service
  872. Suspend-Service
  873.  
  874.  
  875. (Get-WmiObject -Class Win32_Service -Filter "name='WinRM'" -ComputerName Server01)
  876.  
  877. (get-wmiobject win32_process -filter "name='ampagent.exe'" -computername hart08)
  878.  
  879. Get-CimInstance Win32_Service -Filter "name = 'AMPWatchDog'" -ComputerName HOSTNAME | ConvertTo-Csv
  880.  
  881. Get-CimInstance Win32_Service -Filter "name = 'AMPWatchDog'" | ConvertTo-Csv
  882.  
  883.  
  884. Get-Service -name "adws","dns","kdc","netlogon" -ComputerName (Get-ADDomain).ReplicaDirectoryServers | Sort Machinename | Format-Table -group @{Name="Computername";Expression={$_.Machinename.toUpper()}} -Property Name,Displayname,Status
  885.  
  886.  
  887.  
  888. Add-Computer –DomainName mylab.local –Credential (Get-Credential)
  889.  
  890.  
  891. Get-ADComputer -filter * -SearchBase "OU=ORG_UNIT_2,OU=ORG_UNIT_1,DC=DOMAIN,DC=local" | Select-Object -expand name
  892.  
  893. Get-ADGroup -Filter * | Select-Object Name,GroupCategory,GroupScope,DistinguishedName
  894.  
  895. Get-ADGroup -Filter * | Select-Object Name,DistinguishedName
  896.  
  897.  
  898.  
  899. powershell.exe -executionpolicy bypass -command "C:\Users\gas\Desktop\Update-Sysinternals.ps1"
  900.  
  901.  
  902. dism.exe /online /enable-feature /featurename:NetFX3 /Source:D:\sources\sxs /all
  903.  
  904. dism /online /enable-feature /featurename:netfx3 /all /LimitAccess /source:\\share_name\sources\sxs
  905.  
  906.  
  907. <# ------------------------- [Add Telnet CMD Line / PowerShell] ------------------------- #>
  908.  
  909.  
  910. Import-Module servermanager
  911.  
  912. Add-WindowsFeature telnet-client
  913.  
  914.  
  915. dism /online /Enable-Feature /FeatureName:TelnetClient
  916.  
  917.  
  918. <# ------------------------- [Add Telnet CMD Line / PowerShell] ------------------------- #>
  919.  
  920.  
  921.  
  922.  
  923. ## PowerShell History - get-history | Format-Table -Property < *|CommandLine > -AutoSize | Out-String -Width 4096 | clip
  924.  
  925.  
  926. < ------------------------------------------- Windows / PowerShell Version ------------------------------------------- >
  927.  
  928.  
  929. get-item "C:\Windows\System32\qmgr.dll" | Select-Object -ExpandProperty VersionInfo
  930.  
  931. [System.Environment]::OSVersion.Version
  932.  
  933. (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ReleaseId).ReleaseId
  934.  
  935. [Environment]::OSVersion.Version -ge (new-object 'Version' 6,1)
  936.  
  937.  
  938. < ------------------------------------------- Windows / PowerShell Version ------------------------------------------- >
  939.  
  940.  
  941. ## GET DOT NET VERSION - Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name Version -EA 0 | Where { $_.PSChildName -Match '^(?!S)\p{L}'} | Format-Table PSChildName, Version -AutoSize
  942.  
  943. [System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\Windows\system32\notepad.exe").FileVersion
  944.  
  945. Invoke-Command -ComputerName COMPUTERNAME -ScriptBlock {& cmd /c "c:\Program Files (x86)\Symantec\Symantec Endpoint Protection\smc.exe" -p gooberpea -stop}
  946.  
  947. Invoke-Command -ComputerName HOSTNAME -ScriptBlock {(Get-ItemProperty 'hklm:software\symantec\Symantec Endpoint Protection\CurrentVersion').ProductVersion}
  948.  
  949. Invoke-Command -ComputerName HOSTNAME -ScriptBlock {(Get-ItemProperty 'hklm:software\symantec\Symantec Endpoint Protection\CurrentVersion').ProductName}
  950.  
  951.  
  952. Invoke-Command -ComputerName HOSTNAME {Get-PSDrive D} | Select-Object PSComputerName,Used,Free | ForEach-Object {$_.free / 1GB}
  953.  
  954. Invoke-Command -ComputerName HOSTNAME {Get-PSDrive D} | Select-Object PSComputerName,Used,Free | ForEach-Object {$_.used / 1GB}
  955.  
  956.  
  957. powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file "uninstallScript.ps1" "Java"
  958.  
  959. gwmi win32_product | where-object { $_.name -match "" }
  960.  
  961. &START /WAIT msiexec `/qn `/x `{$stringer`}
  962.  
  963. (Get-WmiObject Win32_Process | ?{ $_.ProcessName -match "paintdotnet" }).Terminate()
  964.  
  965.  
  966. Get-WmiObject Win32_Service | Where {$_.name -eq "uvnc_serivce"}
  967.  
  968. Get-WmiObject Win32_Service | Where {$_.name -eq "spooler"}
  969.  
  970. Get-WmiObject Win32_Service | Where {$_.name -like "*vnc*"}
  971.  
  972. gwmi win32_service | where {$_.StartMode -ne “Disabled”} | select name,startname | format-list
  973.  
  974. gwmi win32_service | where {$_.StartMode -ne “Disabled”} | select name,startname | format-Wide
  975.  
  976. gwmi win32_service | where {$_.StartMode -ne “Disabled”} | select name,startname | format-Table
  977.  
  978. gwmi win32_service | where {$_.StartMode -ne “Disabled”} | select name,startname | export-csv c:\services.csv
  979.  
  980. gwmi win32_service | where {$_.StartMode -ne “Disabled”} | select name,startname | convertto-html
  981.  
  982. gwmi win32_service | where {$_.StartMode -ne “Disabled”} | select name,startname | convertto-html | out-file c:\services.html
  983.  
  984. (Get-WmiObject Win32_OperatingSystem -ComputerName ).OSArchitecture
  985.  
  986. (Get-WmiObject Win32_OperatingSystem -ComputerName ).Description
  987.  
  988. gwmi -ComputerName HOSTNAME Win32_OperatingSystem | Select-Object PSComputerName,CSName,Caption,CSDVersion,Version,ServicePackMajorVersion,ServicePackMinorVersion,OSType,LastBootUpTime,ProductType,Organization,OSArchitecture,EncryptionLevel,BuildNumber,BuildType,Description,InstallDate,RegisteredUser,SerialNumber
  989.  
  990. (gwmi -ComputerName HOSTNAME Win32_OperatingSystem).caption
  991.  
  992.  
  993. gwmi win32_operatingsystem -ComputerName HOSTNAME | select PSComputerName,BuildNumber,Caption,Description,EncryptionLevel,InstallDate,LastBootUpTime,LocalDateTime,OperatingSystemSKU,Organization,OSArchitecture,Version | Export-Csv -Path c:\test\WMI_OS_Property.csv
  994.  
  995.  
  996. Get-WmiObject win32_operatingsystem | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
  997.  
  998.  
  999. Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration
  1000.  
  1001.  
  1002. Get-ItemProperty -path "hkcu:\Software\Microsoft\Office\15.0\Outlook\Security"
  1003.  
  1004. Get-ItemProperty -path "hkcu:\Software\Microsoft\Office\16.0\Outlook\Security"
  1005.  
  1006.  
  1007. (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
  1008.  
  1009. Reg Query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ReleaseId
  1010.  
  1011.  
  1012. (gwmi -ComputerName HOSTNAME Win32_OperatingSystem).caption
  1013.  
  1014.  
  1015.  
  1016. Get-ItemProperty -path HKLM:\SYSTEM\CurrentControlSet\Enum\USBSTOR\*\* | Select FriendlyName
  1017.  
  1018. Get-ItemProperty -path HKLM:\SYSTEM\CurrentControlSet\Enum\USBSTOR\*\* | Select FriendlyName,HardwareID
  1019.  
  1020. Get-ItemProperty -path HKLM:\SYSTEM\CurrentControlSet\Enum\USBSTOR\*\* | Select FriendlyName,MFG,Service
  1021.  
  1022. ICM -ComputerName HOSTNAME -ScriptBlock {Get-ItemProperty -path HKLM:\SYSTEM\CurrentControlSet\Enum\USBSTOR\*\* | Select FriendlyName}
  1023.  
  1024. ICM -ComputerName HOSTNAME -ScriptBlock {Get-ItemProperty -path HKLM:\SYSTEM\CurrentControlSet\Enum\USBSTOR\*\* | Select FriendlyName,Service}
  1025.  
  1026.  
  1027. (invoke-command -ComputerName mymachine -ScriptBlock {Get-ItemProperty HKLM:\SOFTWARE\VanDyke\VShell\License -Name Version }).version
  1028.  
  1029.  
  1030. Get-WmiObject -class Win32_OperatingSystem | Select-Object __SERVER,@{label='Install Date';expression={$_.ConvertToDateTime($_.InstallDate)}}
  1031.  
  1032. Get-WmiObject -class Win32_OperatingSystem | Select-Object __SERVER,@{label='Last Restart';expression={$_.ConvertToDateTime($_.LastBootUpTime)}}
  1033.  
  1034. Get-WmiObject -class Win32_OperatingSystem | Select-Object __SERVER,@{label='Local Date Time';expression={$_.ConvertToDateTime($_.LocalDateTime)}}
  1035.  
  1036.  
  1037. gwmi win32_computersystem -ComputerName HOSTNAME | select PSComputerName,Name,Caption,ChassisSkuNumber,DaylightInEffect,DNSHostName,Domain,DomainRole,HypervisorPresent,Manufacturer,Model,NetworkServerModeEnabled,NumberOfLogicalProcessors,NumberOfProcessors,PartOfDomain,PrimaryOwnerContact,PrimaryOwnerName,SystemFamily,SystemSKUNumber,SystemType,TotalPhysicalMemory,Username
  1038.  
  1039.  
  1040. gwmi win32_volume | select PSComputerName,AutoMount,BlockSize,Capacity,Caption,Compressed,DirtyBitSet,FileSystem,FreeSpace,IndexingEnabled,Label,PageFilePresent,QuotasEnabled,SerialNumber,SystemVolume,DriveLetter,DriveType,Name
  1041.  
  1042. gwmi win32_volume | select PSComputer,Name,DriveLetter,DriveType,AutoMount,Caption,Index,FreeSpace,PageFilePresent,IndexingEnabled,DirtyBitSet,FileSystem,Compressed,Capacity,BlockSize,BootVolume
  1043.  
  1044. gwmi win32_volume -ComputerName HOSTNAME | select DriveLetter,Compressed,FileSystem,SerialNumber,SystemVolume, @{Name="Capacity"; Expression={[math]::Round($_.Capacity/1GB)}},@{Name="FreeSpace"; Expression={[math]::Round($_.FreeSpace/1GB)}} | sort -Property DriveLetter | FT
  1045.  
  1046.  
  1047. Get-CimInstance Win32_DiskDrive | Select-Object Model,SerialNumber
  1048.  
  1049. < ----------------------- Win 8 + ------------------------ >
  1050.  
  1051. Get-PhysicalDisk | Select-Object FriendlyName,SerialNumber
  1052.  
  1053. < ----------------------- Win 8 + ------------------------ >
  1054.  
  1055.  
  1056.  
  1057. (Get-WmiObject Win32_LogicalDisk -ComputerName HOSTNAME -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace).size/1GB
  1058.  
  1059. (Get-WmiObject Win32_LogicalDisk -ComputerName HOSTNAME -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace).freespace/1GB
  1060.  
  1061.  
  1062. Get-WMIObject Win32_Logicaldisk -filter "deviceid='C:'" -ComputerName HOSTNAME | Select PSComputername,DeviceID,@{Name="SizeGB";Expression={$_.Size/1GB -as [int]}},@{Name="FreeGB";Expression={[math]::Round($_.Freespace/1GB,2)}}
  1063.  
  1064.  
  1065.  
  1066. $OS = Get-WMiobject -Class Win32_operatingsystem -ComputerName chi-core01
  1067. $OS.SystemDrive
  1068.  
  1069. Get-WMIObject Win32_Logicaldisk -filter "deviceid='$($os.systemdrive)'" -ComputerName HOSTNAME | Select PSComputername,DeviceID,@{Name="SizeGB";Expression={$_.Size/1GB -as [int]}},@{Name="FreeGB";Expression={[math]::Round($_.Freespace/1GB,2)}}
  1070.  
  1071.  
  1072.  
  1073. Get-WMIObject Win32_Logicaldisk -filter "deviceid='$((Get-WMiobject -Class Win32_operatingsystem).systemdrive)'" -ComputerName HOSTNAME | Select PSComputername,DeviceID,@{Name="SizeGB";Expression={$_.Size/1GB -as [int]}},@{Name="FreeGB";Expression={[math]::Round($_.Freespace/1GB,2)}}
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080. < --------------------------------------------------------- Last Boot Up Time --------------------------------------------------------- >
  1081.  
  1082.  
  1083. GWMI -class Win32_Share -computer HOSTNAME
  1084.  
  1085. (net view \\enetsqnap01) | % { if($_.IndexOf(' Disk ') -gt 0){ $_.Split(' ')[0] } }
  1086.  
  1087.  
  1088. Get-WmiObject -class Win32_OperatingSystem | Select-Object __SERVER,@{label='LastRestart';expression={$_.ConvertToDateTime($_.LastBootUpTime)}}
  1089.  
  1090.  
  1091. Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime
  1092.  
  1093. Get-WmiObject win32_operatingsystem | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
  1094.  
  1095. systeminfo /FO CSV | ConvertFrom-CSV
  1096.  
  1097.  
  1098. net statistics workstation
  1099.  
  1100. < --------------------------------------------------------- Last Boot Up Time --------------------------------------------------------- >
  1101.  
  1102.  
  1103. < --------------------------------------------------------- IMPORT PCS FROM AD INTO COMMAND --------------------------------------------------------- >
  1104.  
  1105. Get-WmiObject -class Win32_BIOS -comp (
  1106. Get-ADComputer -filter * -SearchBase "OU=ORG_UNIT2, OU=ORG_UNIT1, DC=DOMAIN, DC=local" | Select-Object -expand name
  1107. ) | SELECT SERIALNUMBER,PSComputername
  1108.  
  1109.  
  1110. Get-WmiObject -class Win32_computersystem -comp (
  1111. Get-ADComputer -filter * -SearchBase "OU=ORG_UNIT2, OU=ORG_UNIT1, DC=DOMAIN, DC=local" | Select-Object -expand name
  1112. ) | SELECT PSComputerName,Username,Manufacturer,Model,Domain,SystemType
  1113.  
  1114.  
  1115. Get-WmiObject -class Win32_networkadapterconfiguration -comp (
  1116. Get-ADComputer -filter * -SearchBase "OU=ORG_UNIT2, OU=ORG_UNIT1, DC=DOMAIN, DC=local" | Select-Object -expand name
  1117. ) | SELECT PSComputerName,ipaddress,macaddress,description
  1118.  
  1119.  
  1120. Invoke-command -comp (
  1121. Get-ADComputer -filter * -SearchBase "OU=ORG_UNIT2, OU=ORG_UNIT1, DC=DOMAIN, DC=local" | Select-Object -expand name
  1122. ) {Get-PSDrive C} | Select-Object PSComputerName,Used,Free | ForEach-Object {$_.used / 1GB}
  1123.  
  1124. < --------------------------------------------------------- IMPORT PCS FROM AD INTO COMMAND --------------------------------------------------------- >
  1125.  
  1126.  
  1127.  
  1128. Get-HotFix | where InstalledOn -ge ([datetime]”11/1/2013″)
  1129.  
  1130. get-hotfix -id KB974332
  1131.  
  1132. get-hotfix -id KB974332 -computername HOSTNAME
  1133.  
  1134. if (!(get-hotfix -id KB974332 -computername HOSTNAME)) \{ add-content $_ -path Missing-KB974332.txt \}
  1135.  
  1136. get-content computers.txt | foreach \{ if (!(get-hotfix -id KB974332 -computername $_)) \{ add-content $_ -path Missing-KB974332.txt \}\}
  1137.  
  1138. Get-HotFix : This command cannot find hot-fix on the machine 'savdaldc11'. Verify the input and Run your command again. At line:1 char:55 + get-content computers.txt | foreach \{ if (!(get-hotfix <<<< -id KB974332 -computername $_)) \{ add-content $_ -path Missing-KB974332.txt \}\}
  1139.  
  1140. get-hotfix | Where-Object {$_.installedon -gt (get-date).addmonths(-6)} | Sort-Object -property installedOn -Descending
  1141.  
  1142. Get-Hotfix | where {$_.HotFixId -like "KB000000"}
  1143.  
  1144.  
  1145.  
  1146. Get-CimInstance Win32_StartupCommand | Select-Object Name, command, Location, User | Format-List
  1147.  
  1148.  
  1149. ($result.IPV6Address).IPAddressToString
  1150.  
  1151.  
  1152. < ---------- Clean Shutdown ------------------------------------------------------------------------------------------------------------------------------ >
  1153.  
  1154. Get-Process | Where-Object MainWindowTitle | Out-GridView -Title 'Select Program To Kill' -PassThru | ForEach-Object { $_.CloseMainWindow() }
  1155.  
  1156.  
  1157. Get-Process | Where-Object MainWindowTitle | Out-GridView -Title 'Select Program To Kill' -PassThru | Stop-Process
  1158.  
  1159. < ---------- Foreced Shutdown ---------------------------------------------------------------------------------------------------------------------------- >
  1160.  
  1161.  
  1162. Get-Process | Where-Object { $_.MainWindowTitle } | Select-Object -Property Name, Company, Description, CPU | Out-Excel
  1163.  
  1164. Get-Process | Where-Object { $_.MainWindowTitle } | Select-Object -Property Name, Company, Description, CPU
  1165.  
  1166.  
  1167. Get-Process | Where-Object { $_.MainWindowTitle } | Select-Object -Property Name,Company,Description,CPU,ID,FileVersion,ProductVersion,StartTime,Path
  1168.  
  1169.  
  1170.  
  1171. Get-Process -ComputerName HOSTNAME | Select-Object name,fileversion,productversion,company
  1172.  
  1173. Get-Process -id (get-process ProtectionUtilSurrogate*).id -FileVersionInfo
  1174.  
  1175. (Get-Process -id (get-process PfuSsMon*).id -module).count
  1176.  
  1177. (get-process explorer).id
  1178.  
  1179.  
  1180. Get-Process -Name prt* | select Name,ID,PriorityClass,FileVersion,HandleCount,TotalProcessorTime,Handles,Company,CPU,ProductVersion,Description,Product,ExitCode,HasExited,ExitTime,Handle,PriorityBoostEnabled,ProcessName,ProcessorAffinity,Responding,SessionID,StartTime,EnableRaisingEvents,Site,Container
  1181.  
  1182.  
  1183. get-process | select -Property Name,ID,handlecount,PagedMemorySize,Handles,Path,Company,CPU,ProductVersion,Description,Product | Out-GridView
  1184.  
  1185.  
  1186.  
  1187. Get-FileHash "C:\Users\Username\Downloads\ImgBurn\SetupImgBurn_2.5.8.0.exe" -Algorithm md5
  1188.  
  1189. -Algorithm <String> {SHA1 | SHA256 | SHA384 | SHA512 | MACTripleDES | MD5 | RIPEMD160}
  1190.  
  1191.  
  1192.  
  1193. dir "DIRECOTRY PATH" -Recurse | Where-Object {!$_.psiscontainer } | get-filehash | ? {$_.hashstring -match ‘f64a28eaa82a657e16044ca85b5f0571’}
  1194. dir "DIRECTORY PATH" -Recurse | Where-Object {!$_.psiscontainer } | get-filehash | ? {$_.hashstring -match ‘6798240DCFECA09BCD6AE21AC7F5E573’}
  1195.  
  1196.  
  1197. if ( $($(CertUtil -hashfile C:\TEMP\MyDataFile.img MD5)[1] -replace " ","") -eq "your_hash" ) { echo "ok" }
  1198.  
  1199.  
  1200.  
  1201. ipconfig | Where-Object { $_ -like "*Address*"}
  1202.  
  1203. ipconfig | Where-Object { $_ -like "*IPv4 Address*"}
  1204.  
  1205. dir -Recurse | Where-Object { $_ -like "*Google*"}
  1206.  
  1207.  
  1208.  
  1209. gwmi -Class win32_process -computername HOSTNAME | select name, kernelmodetime, usermodetime
  1210.  
  1211. Get-WmiObject Win32_Process | select Name, @{Name="CPU_Time";Expression={$_.kernelmodetime + $_.usermodetime}} | sort CPU_Time -Descending
  1212.  
  1213. ps -ComputerName HOSTNAME | sort cpu -Descending
  1214.  
  1215. Invoke-Command -ScriptBlock {get-process} -ComputerName HOSTNAME
  1216.  
  1217.  
  1218. get-WmiObject -list | where {$_.name -match “Printer”}
  1219.  
  1220. GWMI WIN32_PRINTER | SELECT CAPTION,COMMENT,DEFAULT,DEFAULTPRIORITY,DESCRIPTION,DRIVERNAME,INSTALLDATE,NAME,PORTNAME,PRINTERSTATE,PRINTERSTATUS,SHARENAME,SPOOLENABLED,STATUS,SYSTEMNAME | ConvertTo-Csv -UseCulture > $env:computername"_PRINTERS.CSV"
  1221.  
  1222. GWMI WIN32_PRINTER | SELECT CAPTION,COMMENT,DEFAULT,DEFAULTPRIORITY,DESCRIPTION,DRIVERNAME,INSTALLDATE,NAME,PORTNAME,PRINTERSTATE,PRINTERSTATUS,SHARENAME,SPOOLENABLED,STATUS,SYSTEMNAME | ConvertTo-Csv -UseCulture > $env:computername"_$(get-date -f MM-dd-yyyy-HH-mm)".csv
  1223.  
  1224.  
  1225.  
  1226.  
  1227. Get-WMiObject Win32_USBControllerDevice -computername HOSTNAME | fl Antecedent,Dependent
  1228.  
  1229. gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)} | Sort Description,DeviceID | ft Description,DeviceID -auto
  1230.  
  1231.  
  1232.  
  1233. Get-WMIObject -class Win32_ComputerSystem | select username
  1234.  
  1235.  
  1236. Get-WmiObject -Class __Namespace -Namespace root ` -Filter "name='WMI'"
  1237.  
  1238.  
  1239. (Get-WSManInstance -Enumerate wmicimv2/* -filter "select * from win32_computersystemproduct").uuid
  1240.  
  1241. Get-WmiObject Win32_NetworkAdapter -Filter "netenabled = true" | Select Guid
  1242.  
  1243. Get-WmiObject Win32_NetworkAdapter -Filter "netenabled = true" | Select Guid,macaddress,description
  1244.  
  1245.  
  1246. wmic csproduct get uuid
  1247.  
  1248.  
  1249.  
  1250. get-history | Format-Table -Property * -AutoSize | Out-String -Width 4096 | clip
  1251.  
  1252. get-history | Format-Table -Property CommandLine -AutoSize | Out-String -Width 4096 | clip
  1253.  
  1254.  
  1255.  
  1256. Test-Connection IPADDRESS | Format-list -Property PSComputerName,IPV4Address,ResponseTimeToLive,ReplySize
  1257.  
  1258. Test-Connection IPADDRESS | Out-GridView -Title 'PING Reply Table'
  1259.  
  1260. Test-Connection IPADDRESS | Out-GridView -PassThru | Export-Csv -Path .\IPScan.csv
  1261.  
  1262.  
  1263. Invoke-Command -ComputerName S1, S2 -ScriptBlock {Get-Process PowerShell} -HideComputerName
  1264.  
  1265. Invoke-Command -ComputerName HOSTNAME -ScriptBlock {Get-Process vm*}
  1266.  
  1267. Invoke-Command -ComputerName HOSTNAME -ScriptBlock {Get-Process win*}
  1268.  
  1269.  
  1270.  
  1271. Get-CimClass Win32*Disk*
  1272.  
  1273. Get-CimInstance -ClassName Win32_DiskDrive | Select Status,InterfaceType,Size,Caption,Description,Name,SystemName,FirmwareRevision,Manufacturer,Model,SerialNumber,Signature
  1274.  
  1275. Get-CimInstance -ClassName Win32_DiskDrive -Property Status, InterfaceType, Size, Caption, Description, Name, SystemName, FirmwareRevision, Manufacturer, Model, SerialNumber, Signature
  1276.  
  1277.  
  1278.  
  1279. Get-ChildItem -Path C:\TECH -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName
  1280.  
  1281. Get-Childitem -Path C:\Users -Include *HSG* -Exclude *.JPG,*.MP3,*.TMP -File -Recurse -ErrorAction SilentlyContinue
  1282.  
  1283.  
  1284. [ Look for String in files ]
  1285. ls -r c:\ -file | % {select-string -path $_ -pattern mypassword}
  1286.  
  1287. [ Look for file name ]
  1288. ls -r -file -filter *secret*
  1289.  
  1290.  
  1291.  
  1292. < ------ [ GWMI is alias for Get-WMIObject ] ------ >
  1293.  
  1294. (Get-WmiObject win32_bios).serialnumber
  1295.  
  1296. Gwmi Win32_SystemEnclosure | Select Serialnumber
  1297.  
  1298. Get-WMIObject Win32_SystemEnclosure | Select Serialnumber
  1299.  
  1300. Gwmi Win32_BIOS | Select Serialnumber
  1301.  
  1302. Get-WMIObject Win32_BIOS | Select Serialnumber
  1303.  
  1304.  
  1305.  
  1306. ((Get-CimInstance win32_processor).Name | select -First 1)
  1307.  
  1308. (Get-CimInstance win32_processor).Name
  1309.  
  1310. (Get-CimInstance win32_processor)
  1311.  
  1312. (Get-CimInstance win32_processor).Caption
  1313.  
  1314. (Get-CimInstance win32_processor).DeviceID
  1315.  
  1316. (Get-CimInstance win32_processor).MaxClockSpeed
  1317.  
  1318. (Get-CimInstance win32_processor).SocketDesignation
  1319.  
  1320. (Get-ADComputer -Filter {OperatingSystem -Like "*Server*"} -Properties OperatingSystem)
  1321.  
  1322. (Get-WmiObject Win32_OperatingSystem).Version
  1323.  
  1324. (Get-WmiObject Win32_OperatingSystem)
  1325.  
  1326. (Get-WmiObject Win32_OperatingSystem) | select *
  1327.  
  1328. (Get-WmiObject Win32_OperatingSystem).Caption
  1329.  
  1330. (Get-WmiObject Win32_OperatingSystem).RegisteredUser
  1331.  
  1332. (Get-WmiObject Win32_OperatingSystem).RegisteredUser.OSArchitecture
  1333.  
  1334. (Get-WmiObject Win32_OperatingSystem).OSArchitecture
  1335.  
  1336. (Get-WmiObject Win32_OperatingSystem).Description
  1337.  
  1338.  
  1339.  
  1340. < ------ [ GWMI is alias for Get-WMIObject ] ------ >
  1341.  
  1342.  
  1343.  
  1344. Get-CimInstance -ClassName win32_bios | Select SMBIOSBIOSVersion, Manufacturer, Name, SerialNumber, Version
  1345.  
  1346. Get-CimInstance -ClassName CIM_ComputerSystem | select Name,Caption,PrimaryOwnerName,DayLightInEffectd,DNSHostName,Domain,DomainRole,EnableDayLightSavingsTime,HypervisorPresent,Manufacturer,Model,NumberOfLogicalProcessors,NumberOfProcessors,PartOfDomain,SystemSKUNumber,SystemType,TotalPhysicalMemeory,UserName,WorkGroup
  1347.  
  1348. Get-CimInstance -ClassName CIM_DiskDrive | select *
  1349.  
  1350. Get-CimInstance -ClassName CIM_Chip | select *
  1351.  
  1352. Get-CimInstance -ClassName CIM_PhysicalMemory
  1353.  
  1354. Get-CimInstance -ClassName CIM_Printer | select Name,Status,Caption,Description,DeviceID,SystemName,Comment,Default,Direct,DriverName,Local,Network,PortName,ServerName,ShareName
  1355.  
  1356. Get-CimInstance -ClassName CIM_Process
  1357.  
  1358. Get-CimInstance -ClassName CIM_Processor
  1359.  
  1360. Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property BuildNumber,BuildType,OSType,ServicePackMajorVersion,ServicePackMinorVersion
  1361.  
  1362. Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property NumberOfLicensedUsers,NumberOfUsers,RegisteredUser
  1363.  
  1364. Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3"
  1365.  
  1366. Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | Measure-Object -Property FreeSpace,Size -Sum | Select-Object -Property Property,Sum
  1367.  
  1368. Get-CimInstance -ClassName Win32_LogonSession
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374. < ------------------------------------------------------------------ Invoke-RestMethod ------------------------------------------------------------------ >
  1375.  
  1376.  
  1377. $Data = Invoke-RestMethod -Uri 'https://gis.iowadot.gov/public/rest/services/Traffic_Safety/Crash_Data/MapServer/0?f=pjson'
  1378.  
  1379. $Data.fields|Select-Object -Property Name, alias, Domain
  1380.  
  1381.  
  1382. (Invoke-RestMethod -Uri 'https://gis.iowadot.gov/public/rest/services/Traffic_Safety/Crash_Data/MapServer/0?f=pjson').fields | Select Name,Alias,Domain
  1383.  
  1384. ((Invoke-RestMethod -Uri 'https://gis.iowadot.gov/public/rest/services/Traffic_Safety/Crash_Data/MapServer/0?f=pjson').fields | Where-Object {$_.name -eq 'weather'}).Domain.CodedValues
  1385.  
  1386. Invoke-RestMethod -Uri 'https://gis.iowadot.gov/public/rest/services/Traffic_Safety/Crash_Data/MapServer/0?f=pjson' | select -Property Name,CurrentVersion,supportsStatistics,supportedQueryFormats,ownershipBasedAccessControlForFeatures,useStandardizedQueries
  1387.  
  1388.  
  1389.  
  1390.  
  1391. < ------------------------------------------------------------------ Invoke-RestMethod ------------------------------------------------------------------ >
  1392.  
  1393.  
  1394.  
  1395.  
  1396.  
  1397. gwmi -ComputerName HOSTNAME -ClassName CIM_Chip
  1398.  
  1399.  
  1400.  
  1401.  
  1402.  
  1403. Get-PnpDevice -PresentOnly
  1404.  
  1405.  
  1406. (whoami /all | select-string S-1-16-12288) -ne $null
  1407.  
  1408.  
  1409. Last Bootup Time - [System.Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime)
  1410.  
  1411.  
  1412. Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select Average
  1413.  
  1414. Get-WmiObject -Computername HOSTNAME win32_processor | Measure-Object -property LoadPercentage -Average | Select Average
  1415.  
  1416.  
  1417. Get-WmiObject -Class win32_Volume | select Name,FileSystem,BlockSize,Capacity,Label,PSComputername | Format-Table
  1418.  
  1419. Get-WmiObject -Computername HOSTNAME -Class win32_Volume | select Name,FileSystem,BlockSize,Capacity,Label,PSComputername | Format-Table
  1420.  
  1421.  
  1422. Get-WMIObject Win32_OperatingSystem | select-object caption
  1423.  
  1424. Get-WMIObject Win32_OperatingSystem
  1425.  
  1426. Get-WMIObject Win32_OperatingSystem -Computername HOSTNAME | select-object caption
  1427.  
  1428.  
  1429. (Get-ADDomain).PDCEmulator
  1430.  
  1431. Get-ADUser -Identity Username -Properties memberof | Select-Object -ExpandProperty memberof
  1432.  
  1433. (Get-ADUser -Identity Username -Properties memberof).memberof
  1434.  
  1435. Get-SmbServerConfiguration | Select EnableSMB1Protocol, EnableSMB2Protocol
  1436.  
  1437.  
  1438. Write-Host (2,4,6,8,10,12) -Separator ", -> " -ForegroundColor Green -BackgroundColor RED
  1439.  
  1440. Write-Host (2,4,6,8,10,12) -Separator ", -> " -ForegroundColor DarkGreen -BackgroundColor white
  1441.  
  1442.  
  1443. CommandLine
  1444. -----------
  1445. Get-WinEvent -LogName Microsoft-Windows-TaskScheduler/Operational
  1446. Get-WinEvent -LogName security
  1447. Get-WinEvent -LogName Microsoft-Windows-Security-Audit-Configuration-Client/Operational
  1448. Get-WinEvent -LogName Microsoft-Windows-Winlogon/Operational
  1449. Get-WinEvent -LogName Microsoft-Windows-Winlogon
  1450. Get-WinEvent -LogName Microsoft*
  1451.  
  1452. Get-EventLog -list | Where-Object {$_.logdisplayname -eq "Security"}
  1453. Get-EventLog "Security" | Where-Object {$_.EventID -eq 4672}
  1454. Get-EventLog "Security" -ComputerName HOSTNAME | Where-Object {$_.EventID -eq 428 -or }
  1455. Get-Eventlog -logname Security -ComputerName HOSTNAME | Where EventID -EQ “4740” | Format-Table
  1456.  
  1457. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672; level=2} -MaxEvents 10
  1458. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672; UserID=Username} -MaxEvents 10
  1459. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672; UserID=CONTOSO\Username} -MaxEvents 10
  1460. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672; UserID=Administratro} -MaxEvents 10
  1461. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672; UserID=Administrator} -MaxEvents 10
  1462. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672} -MaxEvents 10
  1463. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672} -MaxEvents 10 | Group-Object eventid | Sort-Object Name
  1464. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672} | Group-Object eventid | Sort-Object Name -MaxEvents 10
  1465. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672} | Group-Object eventid | Sort-Object Name
  1466. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672} | Group-Object id | Sort-Object Message
  1467. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672} | Group-Object id | Sort-Object Message -MaxEvents 10
  1468. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672} | Group-Object id -MaxEvents 10
  1469. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672} | Group-Object Id -MaxEvents 10
  1470. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672} | Format-Table -Property * -AutoSize | Out-String -Width 4096
  1471. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672} -MaxEvents 10 | Format-Table -Property * -AutoSize | Out-String -Width 4096
  1472. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672} -MaxEvents 10 | Format-Table -Property * -AutoSize | Out-String -Width 4096 | clip
  1473. Get-WinEvent -FilterHashtable @{logname='Security'; id=4672} -MaxEvents 10 | Format-Table -Property * -AutoSize | clip
  1474. Get-EventLog -ComputerName SERVER -LogName Security ?{$_.EventID -eq 538 -or $_.Event -eq 540}
  1475.  
  1476. Get-EventLog -LogName Security ?{$_.EventID -eq 4907 -or $_.Event -eq 4672}
  1477. Get-EventLog -LogName Security ?{$_.EventID -eq 4907 -or $_.Event -eq 4672}
  1478. Get-EventLog -LogName Security ?{$_.EventID -eq 4907 -or $_.Event -eq 4672}
  1479. Get-EventLog -LogName Security | ?{$_.EventID -eq 4907 -or $_.Event -eq 4672}
  1480. Get-EventLog -ComputerName SERVER -LogName Security | ?{$_.EventID -eq 4907 -or $_.Event -eq 4672}
  1481. Get-EventLog -ComputerName SERVER -LogName Security | ?{$_.EventID -eq 538 -or $_.Event -eq 540}
  1482. Get-EventLog -ComputerName SERVER -LogName Security | ?{$_.EventID -eq 538 -or $_.Event -eq 540}
  1483. Get-EventLog -ComputerName SERVER -LogName Security | ?{$_.EventID -eq 538 -or $_.Event -eq 540} | Format-Table -Property * -AutoSize | Out-String -Width 4096
  1484.  
  1485. get-history | Format-Table -Property * -AutoSize | Out-String -Width 4096 | clip
  1486.  
  1487. Get-WinEvent -FilterHashtable @{logname='application'} | where-object { $_.Message -like '*konea*' }
  1488. Get-WinEvent -FilterHashtable @{logname='application'} | where-object { $_.Message -like '*outlook*' }
  1489. Get-WinEvent -FilterHashtable @{logname='application'} | where-object { $_.Message -like '*outlook*' }
  1490. Get-WinEvent -FilterHashtable @{logname='application'} | where-object { $_.Message -like '*outlook*' } | clip
  1491. Get-WinEvent -FilterHashtable @{logname='application'} | where-object { $_.Message -like '*outlook*' } | Format-Table -AutoSize *
  1492. Get-WinEvent -FilterHashtable @{logname='application'} | where-object { $_.Message -like '*outlook*' } | Format-Table -AutoSize
  1493. Get-WinEvent -FilterHashtable @{logname='application'} | where-object { $_.Message -like '*outlook*' } | select message
  1494.  
  1495. Get-WinEvent -FilterHashtable @{logname='application'; id=4107; StartTime="1/17/11"}
  1496.  
  1497.  
  1498. Invoke-Command -Computername Computer01 -ScirptBlock {Get-Eventlog -Logname Security | Select-Object -First 10}
  1499.  
  1500. Invoke-Command -Computername Computer01 -ScirptBlock {Get-Process} | gm
  1501.  
  1502. Invoke-Command -Computername Computer01 -ScirptBlock {Get-Process} | where {_.name -eq "notepad"}
  1503.  
  1504. Measure-Command {Invoke-Command -Computername Computer01 -ScirptBlock {Get-Process} | where {_.name -eq "notepad"} }
  1505.  
  1506. Measure-Command {Invoke-Command -Computername Computer01 -ScirptBlock {Get-Process | where {_.name -eq "notepad"}} }
  1507.  
  1508. Invoke-Command -Computername Computer01 -ScirptBlock {Get-Process | where {_.name -eq "notepad"} | Stop-Process}
  1509.  
  1510.  
  1511.  
  1512.  
  1513. Event Log Archive - Get-WinEvent -FilterHashtable @{logname='security'; id=1105; StartTime="12/12/17"}
  1514.  
  1515. Event Log Pass Change - Get-WinEvent -FilterHashtable @{logname='security'; id=628; StartTime="12/12/17"}
  1516.  
  1517. Get-WinEvent -FilterHashtable @{logname='application';id=4107;StartTime="1/15/11";EndTime="1
  1518.  
  1519. Get-EventLog "Application" | Where-Object {$_.EventID -eq 1003 -or $_.EventID -eq 62 -or $_.EvendID -eq 902} | select EventID,TimeGenerated,EntryType,Source
  1520.  
  1521. Get-EventLog "System" | Where-Object {$_.EventID -eq 7 -or $_.EventID -eq 11 -or $_.EventID -eq 51 -or $_.EvendID -eq 52 -or $_.EventID -eq 13150} | select EventID,TimeGenerated,EntryType,Source,Message
  1522.  
  1523. Get-EventLog "System" | Where-Object {$_.EventID -eq 7 -or $_.EventID -eq 11 -or $_.EventID -eq 51 -or $_.EvendID -eq 52 -or $_.EventID -eq 13150} | select * | ConvertTo-Csv > C:\Test\EvntLog_HD_Failure.csv
  1524.  
  1525. Get-EventLog "System" | Where-Object {$_.EventID -eq 7 -or $_.EventID -eq 9 -or $_.EventID -eq 11 -or $_.EventID -eq 15 -or $_.EventID -eq 51 -or $_.EvendID -eq 52 -or $_.EventID -eq 13150} | select EventID,TimeGenerated,EntryType,Source,Message
  1526.  
  1527. Get-EventLog "System" | Where-Object {$_.EventID -eq 7 -or $_.EventID -eq 9 -or $_.EventID -eq 11 -or $_.EventID -eq 15 -or $_.EventID -eq 51 -or $_.EvendID -eq 52 -or $_.EventID -eq 13150} | select * | ConvertTo-Csv > C:\Test\EvntLog_HD_Failure.csv
  1528.  
  1529.  
  1530. Get-EventLog Security -ComputerName Computer -Source Microsoft-Windows-Security-Auditing | Where {$_.InstanceID -like "4624"} | Select $UserProperty | where {$_.Username -Like "username"} | Export-Csv D:\Logon.csv -NoTypeInformation
  1531.  
  1532. - Make sure Service "RemoteRegistry" running
  1533.  
  1534. Get-EventLog Security -ComputerName Computer -Source Microsoft-Windows-Security-Auditing | Where {$_.InstanceID -like "4624"} | Select $UserProperty | where {$_.Username -Like "*blalock"} | Export-Csv D:\Logon.csv -NoTypeInformation
  1535.  
  1536.  
  1537. Get-EventLog "System" | Where-Object {$_.EntryType -eq 'Error'} | select EventID,TimeGenerated,EntryType,Source
  1538.  
  1539.  
  1540. Get-EventLog "System" | Where-Object {$_.EntryType -ne "Information"} | select * | more
  1541.  
  1542. Get-EventLog "System" | Where-Object {$_.EntryType -eq "Error"} | select * | more
  1543.  
  1544.  
  1545.  
  1546. $date = (Get-Date).AddDays(-1)
  1547.  
  1548. Get-WinEvent -FilterHashTable @{ LogName = "System"; StartTime = $date; ID = "12" }
  1549.  
  1550.  
  1551.  
  1552. $formatEnumerationLimit = -1
  1553.  
  1554. $formatenumerationlimit
  1555.  
  1556.  
  1557. Get-WinEvent -FilterHashtable @{logname='application'; ProviderName='MSSQLSERVER'} | where-object { $_.Message -like '*error*' }
  1558.  
  1559.  
  1560.  
  1561. Get-WinEvent -path "C:\temp\*Security*.evtx" -max 10 -FilterHashtable @{Providername="Microsoft-Windows-Security-Auditing"; id=4740; StartTime='1/7/2013'; EndTime='1/8/2013'}
  1562.  
  1563.  
  1564.  
  1565. Get-WinEvent -FilterHashtable @{logname='application'; providername='.Net Runtime' }
  1566.  
  1567. Get-WinEvent -FilterHashtable @{logname='system'; providername='Disk' }
  1568.  
  1569. Get-WinEvent -FilterHashtable @{logname='system'; level='2'}
  1570.  
  1571.  
  1572. Get-EventLog Security -Source Microsoft-Windows-Security-Auditing -After ((Get-Date).Date.AddDays(-30)) | Where ($_.EventID -eq 4624)
  1573.  
  1574. Get-WinEvent -FilterHashTable @{LogName="System"; StartTime=(get-date).AddDays(-13); EndTime=(get-date).AddHours(-1): level='2'}
  1575.  
  1576. Write-Eventlog -Logname "Operations Manager" -Source 'HealthService' -EventID 100 -EntryType Warning -Message "String `"$string`" has not been found in URL `"$url`" authenticated with username `"$user`" and password `"$password`"."
  1577.  
  1578.  
  1579.  
  1580. Get-EventLog System | Where-Object {$_.EventID -eq "1074" -or $_.EventID -eq "6008" -or $_.EventID -eq "1076"} | ft Machinename, TimeWritten, UserName, EventID, Message -AutoSize -Wrap | More
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586. ##############################################################################################################################################################
  1587. ##
  1588. ## https://4sysops.com/archives/search-the-event-log-with-the-get-winevent-powershell-cmdlet/
  1589. ##
  1590. ###############################################################################################
  1591.  
  1592. Events with a specific information level
  1593.  
  1594. You must provide the information level with Level as the key and a Number as the value. Here is a list of levels associated with their respective numbers:
  1595. •LogAlways 0
  1596. •Critical 1
  1597. •Error 2
  1598. •Warning 3
  1599. •Informational 4
  1600. •Verbose 5
  1601.  
  1602. The following command displays all error events from the System log:
  1603.  
  1604. Get-WinEvent -FilterHashTable @{LogName='System';Level='2'}
  1605.  
  1606. Unfortunately, you can only specify one level at a time through a hash table.
  1607. However, we can circumvent this problem by using the Where-Object cmdlet instead of the Level key from the hash table.
  1608.  
  1609. ##############################################################################################################################################################
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615. < ************************************* https://social.technet.microsoft.com/Forums/ie/en-US/c8330f58-f2e5-4681-beb2-b2b6a185f818/how-to-geteventlog-for-offline-evtx-files?forum=winserverpowershell ************** >
  1616.  
  1617. If you want to export out only some column, then please run below command first to select out one object and get those column:
  1618.  
  1619. $EventLogonIDs="4624","4634"
  1620. Get-WinEvent -FilterHashtable @{Path="C:\temp\Security*.evtx";id= @($EventLogonIDs);StartTime="1/7/2013";EndTime="1/8/2013"} | select-object -first 2
  1621.  
  1622. OR we also could use get-member command to get all properties of the result, and then choose what you want to export:
  1623.  
  1624. $EventLogonIDs="4624","4634"
  1625. Get-WinEvent -FilterHashtable @{Path="C:\temp\Security*.evtx";id= @($EventLogonIDs);StartTime="1/7/2013";EndTime="1/8/2013"} | select-object -first 1 | get-member
  1626.  
  1627. < ************************************* https://social.technet.microsoft.com/Forums/ie/en-US/c8330f58-f2e5-4681-beb2-b2b6a185f818/how-to-geteventlog-for-offline-evtx-files?forum=winserverpowershell **************
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633. < ---------------------------------- https://www.makeuseof.com/tag/15-advanced-tasks-powershell-can-handle-windows-10/
  1634.  
  1635.  
  1636. Set-Date -date "12/25/2016 7:30 AM"
  1637.  
  1638. Set-Date (Get-Date).AddDays(2)
  1639.  
  1640. Test-Path c:\Users\Brad\Documents\PowerShell.xls
  1641.  
  1642. Rename-Item c:\Users\Brad\Documents\PowerShellisDifficult.xls PowerShellisEasy.xls
  1643.  
  1644. Move-Item c:\Users\Brad\Documents\PowerShellisEasy.xls c:\Users\Brad\Important Documents
  1645.  
  1646. Move-Item c:\Users\Brad\Documents\*.xls c:\Users\Brad\Important Documents
  1647.  
  1648. Invoke-Item c:\Windows\System32\notepad.exe
  1649.  
  1650. Invoke-Item c:\MakeUseOf\Hello.txt
  1651.  
  1652. Invoke-Item c:\MakeUseOf\*.txt
  1653.  
  1654. Get-Content c:\MakeUseOf\Hello.txt
  1655.  
  1656. Get-Content c:\MakeUseOf\Hello.txt -totalcount 5
  1657.  
  1658. Add-Content c:\MakeUseOf\Hello.txt "written by Brad Jones"
  1659.  
  1660. Add-Content c:\MakeUseOf\Hello.txt "`nwritten by Brad Jones"
  1661.  
  1662. Get-Content c:\MakeUseOf\Hello.txt | Measure Object
  1663.  
  1664. Get-Service
  1665.  
  1666. Get-Service | Where-Object {$_.status -eq "stopped"}
  1667.  
  1668. Restart-Service dbupdate
  1669.  
  1670. Restart-Service -displayname "Dropbox Update Service"
  1671.  
  1672. Set-Service dbupdate -startuptype "manual"
  1673.  
  1674. Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  1675.  
  1676.  
  1677. powershell -NoExit -Command "Set-Location c:\\"
  1678.  
  1679. If your path contains spaces, you can wrap it in single-quotes, like so:
  1680. powershell -NoExit -Command "Set-Location 'c:\\program files'"
  1681.  
  1682.  
  1683. 'powershell -NoExit -Command "Set-Location ' + path1 + '"'
  1684.  
  1685. 'start C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command '; s2 = '"Select-Location ' + "'" + path1 + "'" + '"', and command = s1 + s2
  1686.  
  1687.  
  1688. < ---------------------------------- https://www.makeuseof.com/tag/15-advanced-tasks-powershell-can-handle-windows-10/
  1689.  
  1690.  
  1691.  
  1692.  
  1693. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1694. ## Show addins for Outlook
  1695. -------------------------------------------------------------
  1696.  
  1697.  
  1698. $searchScopes = "HKCU:\SOFTWARE\Microsoft\Office\Outlook\Addins","HKLM:\SOFTWARE\Wow6432Node\Microsoft\Office\Outlook\Addins"
  1699. $searchScopes | % {Get-ChildItem -Path $_ | % {Get-ItemProperty -Path $_.PSPath} | Select-Object @{n="Name";e={Split-Path $_.PSPath -leaf}},FriendlyName,Description} | Sort-Object -Unique -Property name
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1706.  
  1707. if(test-path "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe"){(ls "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe").VersionInfo | Format-List}
  1708. if(test-path "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe"){(ls "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe").VersionInfo | select ProductVersion}
  1709.  
  1710. $path= "\\remote\C$\windows\System32\WindowsPowerShell\v1.0\powershell.exe"
  1711. if(test-path $path){(ls $path).VersionInfo}
  1712.  
  1713. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1714.  
  1715.  
  1716.  
  1717. < ======================================================= Command Used Excel Formulas ======================================================= >
  1718.  
  1719. =IF(D1>1024*1024*1024,TRUNC(D1/1024/1024/1024,2)&" GB", IF(D1>1024*1024, ROUND(D1/1024/1024,0)&" MB", ROUND(D1/1024,0)&" KB"))
  1720.  
  1721.  
  1722.  
  1723.  
  1724. < ======================================================= Command Used Excel Formulas ======================================================= >
  1725.  
  1726.  
  1727.  
  1728.  
  1729. Powershell.exe -ExecutionPolicy Bypass -File "\\sccm\clienthealth$\ConfigMgrClientHealth.ps1" -Config "\\sccm\clienthealth$\config.xml"
  1730.  
  1731.  
  1732. < ---------------------------- [ Powershell Versioning ] ---------------------------- >
  1733.  
  1734.  
  1735. Get-Host | Select-Object Version
  1736.  
  1737.  
  1738. Invoke-Command -Computername HOSTNAME -Scriptblock {$PSVersionTable.psversion}
  1739.  
  1740. REG QUERY \\HOSTNAME\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine
  1741.  
  1742. REG QUERY \\HOSTNAME\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine /V "PowerShellVersion"
  1743.  
  1744. REG QUERY \\HOSTNAME\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine /V "PowerShellVersion"
  1745.  
  1746. REG QUERY \\HOSTNAME\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\
  1747.  
  1748. REG QUERY \\HOSTNAME\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3
  1749.  
  1750.  
  1751. < ---------------------------- [ Powershell Versioning ] ---------------------------- >
  1752.  
  1753.  
  1754.  
  1755.  
  1756. < ---------------------------- [ Check if Server needs rebooting ] ---------------------------- >
  1757.  
  1758.  
  1759.  
  1760. reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired
  1761. reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired"
  1762. reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"
  1763. reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" /s
  1764. reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending"
  1765. reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing"
  1766. reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending"
  1767.  
  1768.  
  1769.  
  1770.  
  1771. < ---------------------------- [ Check if Server needs rebooting ] ---------------------------- >
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781. < ---------------------------- [ Powershell 5.1 Quient Install/Uninstall ] ---------------------------- >
  1782.  
  1783.  
  1784. wusa.exe Win7AndW2K8R2-KB3191566x64.msu /quiet /norestart
  1785.  
  1786.  
  1787. wusa.exe /KB3191566 /uninstall /quiet /norestart
  1788.  
  1789.  
  1790. < ---------------------------- [ Powershell 5.1 Quient Install/Uninstall ] ---------------------------- >
  1791.  
  1792.  
  1793.  
  1794. function Get-SystemUptime
  1795. {
  1796. $operatingSystem = Get-WmiObject Win32_OperatingSystem
  1797. [Management.ManagementDateTimeConverter]::ToDateTime($operatingSystem.LastBootUpTime)
  1798. }
  1799.  
  1800.  
  1801.  
  1802.  
  1803. ##########################################################################################################################################
  1804. ##
  1805. ## http://windowsitpro.com/blog/four-ways-get-computer-names-computername-parameter
  1806. ##
  1807. ##########################################################################################################################################
  1808.  
  1809. I'm teaching a class forSAPIEN Technologies in Chicago this week. Actually, everyone's doing a lab on WMI, watching me enter this. Don't you wish you were here? Anyway, we needed to look at various ways to feed computer names to any cmdlet that has a -computerName parameter. Here's what I cam up with:
  1810.  
  1811.  
  1812.  
  1813. # get names from a file, one name per line
  1814. Get-WmiObject -class Win32_Whatever -computer (Get-Content names.txt)
  1815.  
  1816.  
  1817. # get names from Active Directory
  1818. Import-Module ActiveDirectory
  1819. Get-WmiObject -class Win32_Something -comp (
  1820. Get-ADComputer -filter * | Select-Object -expand name
  1821. )
  1822.  
  1823.  
  1824. # specify one computer
  1825. Get-WmiObject -class Win32_This -computer SERVER-R2
  1826.  
  1827.  
  1828. # specify many computers
  1829. Get-WmiObject -class Win32_That -computer WESTDC4,EASTDC5
  1830.  
  1831.  
  1832. # get names from a CSV file that has a "host" column
  1833. Get-WmiObject -class Win32_Those -computer (
  1834. Import-CSV computerlist.csv | Select-Object -expand host
  1835. )
  1836. I used Get-WmiObject for all of the examples, but you can obviously use this with any cmdlet that supports -computerName. Enjoy!
  1837.  
  1838.  
  1839.  
  1840. ##########################################################################################################################################
  1841.  
  1842.  
  1843. ##############################################################################################################################################################################
  1844. ##
  1845. ## WINDOWS 7 AND ABOVE - NIC ADAPTER REPAIR EQUIVALENT
  1846. ##
  1847. ## http://windowsitpro.com/windows-xp/what-actions-occur-when-i-click-repair-network-connection-windows-xp-and-later
  1848. ##
  1849. ##############################################################################################################################################################################
  1850.  
  1851.  
  1852. If you right-click a network connection and select Status, Windows displays information about the connection's speed, duration of connection, and packet activity.
  1853. For XP and later, a Repair option appears on the Support tab. When you click Repair, Windows attempts to resolve a range of problems.
  1854. Specifically, the OS attempts to renew the DHCP lease, if the connection obtains its IP address through DHCP, using a broadcast message.
  1855.  
  1856. •Flushes the Address Resolution Protocol (ARP) cache using the command
  1857. arp -d *
  1858.  
  1859. •Flushes the NetBIOS cache using the command
  1860. nbtstat -R
  1861.  
  1862. •Flushes the DNS cache using the command
  1863. ipconfig /flushdns
  1864.  
  1865. •Reregisters the NetBIOS name and IP address with WINS using the command
  1866. nbtstat -RR
  1867.  
  1868. •Reregisters the computer name and IP address with DNS using the command
  1869. ipconfig /registerdns
  1870.  
  1871. arp -d *
  1872. nbtstat -R
  1873. ipconfig /flushdns
  1874. nbtstat -RR
  1875. ipconfig /registerdns
  1876.  
  1877.  
  1878. ##############################################################################################################################################################################
  1879.  
  1880.  
  1881. nmap -sV -script=banner IP / HOSTNAME
  1882.  
  1883. nmap -p "Port Number" -oA "Base File Name" IP/RANGE - No quotes
  1884.  
  1885.  
  1886.  
  1887. ##############################################################################################################################################################################
  1888. ## SERVER ONLY COMMANDS FOR NOW
  1889. ##############################################################################################################################################################################
  1890.  
  1891. Get-DhcpServerv4Lease -ScopeId "NETWORK_ID" | select IPAddress,ClientID,HostName
  1892.  
  1893.  
  1894.  
  1895. ##############################################################################################################################################################################
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902. icacls "C:\Program Files (x86)\FourJs" /grant "Users":(OI)(CI)F /inheritance:r
  1903.  
  1904. icacls DemoOCX.lnk /grant users:F (Topaz signature pad, give full access to local USERS group in %PUBLIC%\DESKTOP\DemoOCX.lnk link file)
  1905.  
  1906.  
  1907. invoke-command -ComputerName SERVER -ScriptBlock {Test-Connection -ComputerName 10.0.1.4,10.0.2.4,10.0.3.4,10.0.4.4,10.0.5.4,10.0.6.4,10.0.7.1,10.0.8.4,10.0.9.4,10.0.10.4,10.0.11.4,10.0.12.4,10.0.53.4,10.0.61.1 -Count 2 | format-table -autosize}
  1908.  
  1909.  
  1910. < ##################################################### - ESXi CLI -- Command - ######################################################################################### >
  1911.  
  1912. ESXi History Log - https://ESXiHostnameOrIP/host/shell.log
  1913. https://kb.vmware.com/s/article/2004810
  1914.  
  1915.  
  1916. [root]: esxcli network ip connection list
  1917. [root]: vim-cmd vmsvc/getallvms
  1918. [root]: vim-cmd vmsvc/power.on vcsa
  1919. [root]: vim-cmd vmsvc/getallvms
  1920. [root]: vim-cmd vmsvc/power.on 47
  1921. [root]: vim-cmd vmsvc/getallvms |grep hall
  1922. [root]: vim-cmd vmsvc/getallvms |grep HALL
  1923. [root]: vim-cmd vmsvc/getallvms |grep vcsa
  1924. [root]: vim-cmd vmsvc/power.on 47
  1925. [root]: esxcli vm process list
  1926. [root]: history
  1927.  
  1928.  
  1929. < ##################################################### - ESXi CLI -- Command - ######################################################################################### >
  1930.  
  1931.  
  1932.  
  1933. < ##################################################### - PowerShell Sessions - ######################################################################################### >
  1934.  
  1935. < ##################################################### >
  1936. < #### ####
  1937. < #### https://youtu.be/PMRkM9jlMMw ####
  1938. < #### ####
  1939. < ##################################################### >
  1940.  
  1941. $sess = New-PSSession -ComputerName Computer01
  1942.  
  1943. Get-PSSession
  1944.  
  1945. Process - wsmprovhost.exe - Check username it is running under
  1946.  
  1947. Invoke-Command -Session $sess {var=10} (remains due to estabilshed session)
  1948.  
  1949. $sess | Remove-PSSession
  1950.  
  1951. For domain controllers must be in "Built In" "Administrators"
  1952.  
  1953.  
  1954. $sess | Remove-PSSession
  1955.  
  1956. $dcs = "DC01", "DC02"
  1957. $dcs (should show list of previously added DCs)
  1958.  
  1959. Invoke-Command -ComputerName $dcs -ScriptBlock {$env:computername}
  1960.  
  1961. $sess = NewPSSession -ComputerName $dcs
  1962.  
  1963. Invoke-Command -Session $sess -ScriptBlock {$env:computername}
  1964.  
  1965. Enter-PSSession -Session $sess [0]
  1966. gps
  1967. Get-Service
  1968. exit
  1969.  
  1970.  
  1971. Remove-PSSession | remove
  1972. $sess | Remove
  1973.  
  1974. [Implicit Remoting is importing modules from remote session]
  1975.  
  1976. $adsess = NewPSSession -ComputerName DC01
  1977. Import-Module -Name ActiveDirectory -PSSession $adsess
  1978. Get-Module
  1979. Get-Command -Module ActiveDirectory
  1980.  
  1981. $c = Get-Command Get-ADUser
  1982. $c.definition
  1983.  
  1984. Get-ADUser -filter * | gm
  1985. (Deserialized)
  1986.  
  1987. $comm = "Get-Command"
  1988. & $comm
  1989.  
  1990.  
  1991. Remove-Module ActiveDirectory
  1992. Import-Module -Name ActiveDirectory -PSSession $adsess -Prefix OnDC
  1993. Get-Module
  1994.  
  1995.  
  1996. $sess = New-PSSession -Name DC1Sess -ComputerName DC01
  1997. Get-PSSession
  1998.  
  1999. Invoke-Command -Session $sess {$var=50}
  2000. Disconnect-PSSession -ID 2
  2001.  
  2002. Connect-PSSession -ID2
  2003.  
  2004. Invoke-Command -Session $sess {$var}
  2005.  
  2006. Try telnet "node" 5985
  2007.  
  2008. Import-Module PSDiagnostics
  2009. Get-Command -Module PSDiagnostics
  2010. Enable-PSWSManCombinedTrace
  2011.  
  2012. Invoke-Command -ComputerName Computer01 -ScriptBlock {Get-Process}
  2013. Disable-PSWSMANCombinedTrace
  2014.  
  2015.  
  2016.  
  2017. cd .\\LocalMachine\my
  2018. ls
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026. < ##################################################### - PowerShell Sessions - ######################################################################################### >
  2027.  
  2028.  
  2029.  
  2030.  
  2031. < ##################################################### - Wireshark Filtering - ######################################################################################### >
  2032.  
  2033.  
  2034. http.request.uri matches "^....$"
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042. < ##################################################### - Wireshark Filtering - ######################################################################################### >
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050. < ##################################################### - Powershell JSON to XML Conversion - ##################################################### >
  2051.  
  2052.  
  2053. Get-Content -Path "PATH\FILE-NAME.json" | ConvertFrom-Json | ConvertTo-Xml -As Document -Depth 3 | Out-File -FilePath "PATH\FILE-NAME.xml"
  2054.  
  2055.  
  2056.  
  2057. < ##################################################### - Powershell JSON to XML Conversion - ##################################################### >
  2058.  
  2059.  
  2060.  
Add Comment
Please, Sign In to add comment