{"id":1289,"date":"2018-12-13T10:49:04","date_gmt":"2018-12-13T02:49:04","guid":{"rendered":"http:\/\/jrblog.pentaidea.com\/john\/2018\/12\/13\/powershell-windows-commands-updating\/"},"modified":"2018-12-13T10:49:04","modified_gmt":"2018-12-13T02:49:04","slug":"powershell-windows-commands-updating","status":"publish","type":"post","link":"https:\/\/john.pentaidea.com\/?p=1289","title":{"rendered":"PowerShell\/Windows commands (updating)"},"content":{"rendered":"<p><b><span style=\"font-size: 14pt;\"><span style=\"color:rgb(30, 204, 255);\">PowerShell\u00a0<\/span><\/span><\/b><\/p>\n<ul>\n<li>\n<p>Check computer info<\/p>\n<\/li>\n<\/ul>\n<pre><code>Get-ComputerInfo\n<\/code><\/pre>\n<ul>\n<li>\n<p>Check account info<\/p>\n<\/li>\n<\/ul>\n<pre><code># windows detail\nnet config workstation\n\nnet users\nnet users administrator\n<\/code><\/pre>\n<ul>\n<li>\n<p>Multiple lines command. by &#8220;. `&#8221;<\/p>\n<\/li>\n<\/ul>\n<pre><code>$yourString = \"HELLO world! POWERSHELL!\". `\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Replace(\"HELLO\", \"Hello\"). `\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Replace(\"POWERSHELL\", \"Powershell\")\n<\/code><\/pre>\n<ul>\n<li>\n<p>Zip for powershell<\/p>\n<\/li>\n<\/ul>\n<pre><code>Compress-Archive -Path C:\\Invoices -DestinationPath C:\\Archives\\Invoices\n\n# Or \nCompress-Archive\n#Path[0]:{{xxx}}\n#Path[1]:{{xxx}}\n#DestinationPath:{{filename}}\n<\/code><\/pre>\n<ul>\n<li>\n<p>Print file name as datetime<\/p>\n<\/li>\n<\/ul>\n<pre><code>echo \"HI\" &gt;&gt; logfile$(get-date -f yyyy-MM-dd).log\n<\/code><\/pre>\n<ul>\n<li>\n<p>Setting proxy<\/p>\n<\/li>\n<\/ul>\n<pre><code>[Environment]::SetEnvironmentVariable(\"HTTP_PROXY\",\u00a0 \"http:\/\/adcproxy.trendmicro.com:8080\/\",\u00a0 [EnvironmentVariableTarget]::Machine)\n[Environment]::SetEnvironmentVariable(\"HTTPS_PROXY\",\u00a0 \"http:\/\/adcproxy.trendmicro.com:8080\/\",\u00a0 [EnvironmentVariableTarget]::Machine)\n[Environment]::SetEnvironmentVariable(\"NO_PROXY\",\u00a0 \"127.0.0.1,localhost,*.trendnet.org,*.trendmicro.com,10.0.0.0\/8,172.16.30.0\/16,172.16.31.0\/16,\\.\\pipe\\docker_engine\", \"Machine\")\n\n# PS. EnvironmentVariableTarget: Machine(2)\/Process(0)\/User(1)\n<\/code><\/pre>\n<ul>\n<li>\n<p>Get env variables<\/p>\n<\/li>\n<\/ul>\n<pre><code>[Environment]::GetEnvironmentVariable(\"HTTP_PROXY\",\u00a0 [EnvironmentVariableTarget]::Machine)\n[Environment]::GetEnvironmentVariable(\"HTTP_PROXY\",\u00a0 [EnvironmentVariableTarget]::Process)\n[Environment]::GetEnvironmentVariable(\"HTTP_PROXY\",\u00a0 [EnvironmentVariableTarget]::User)\n<\/code><\/pre>\n<ul>\n<li>\n<p>Calculate the esplase time\u00a0<\/p>\n<\/li>\n<\/ul>\n<pre><code>$StartTime = $(get-date)\n\n$elapsedTime = $(get-date) - $StartTime\n$totalTime = \"{0:HH:mm:ss.fff}\" -f ([datetime]$elapsedTime.Ticks)\nWrite-Host $totalTime\n<\/code><\/pre>\n<ul>\n<li>\n<p>Enable remote scripting, &#8220;.ps1 is not digitally signed. The script will not execute on the system.&#8221;<\/p>\n<\/li>\n<\/ul>\n<pre><code>Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass\n\n=================\nGet-ExecutionPolicy\u00a0 # Get current\n<\/code><\/pre>\n<ul>\n<li>\n<p>Check IIS version<\/p>\n<\/li>\n<\/ul>\n<pre><code>get-itemproperty HKLM:\\SOFTWARE\\Microsoft\\InetStp\\\u00a0 | select setupstring,versionstring\n<\/code><\/pre>\n<ul>\n<li>\n<p>Get CPU Memory usage<\/p>\n<\/li>\n<\/ul>\n<pre><code># CPU\n(Get-Counter '\\Processor(_Total)\\% Processor Time').CounterSamples.CookedValue\n\n# Memory (MB)\n(Get-Counter '\\Memory\\Available MBytes').CounterSamples.CookedValue\n<\/code><\/pre>\n<ul>\n<li>\n<p>Test SQL connect\u00a0<\/p>\n<\/li>\n<\/ul>\n<pre><code>$connectionString = \"Server={{Server}};Database={{database}};uid={{user}}; pwd={{pwd}};Integrated Security=False;\"\n$connectionString = \"data source={{Server}};Initial Catalog={{database}};Integrated Security=True;\"\u00a0 # For windows auth\n$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $connectionString\n$sqlConnection.Open()\u00a0 \u00a0 # stop here, if just for connection test\n\n# With query\n$Command = New-Object System.Data.SQLClient.SQLCommand\n$Command.Connection = $sqlConnection\n$Command.CommandText = \"SELECT 1\"\n$Reader = $Command.ExecuteReader()\n\n# With response\n$Datatable = New-Object System.Data.DataTable\n$Datatable.Load($Reader)\nforeach($row in $Datatable)\n{\n\u00a0 \u00a0 Write-Host $row.Item(0)\n}\n\n$sqlConnection.Close()\n<\/code><\/pre>\n<ul>\n<li>\n<p>Download zip and unzip<\/p>\n<\/li>\n<\/ul>\n<pre><code>Invoke-WebRequest -Uri \"https:\/\/download...zip\" -OutFile \"{path}\" | Extract-Archive -DestinationPath \"{path}\"\n(Invoke-WebRequest https:\/\/your\/url\/...).Content | Extract-Archive -DestinationPath C:\\Kellekek\\Microsoft\\PowerShell\\6.0.0-beta.8\n<\/code><\/pre>\n<ul>\n<li>\n<p>Get date string<\/p>\n<\/li>\n<\/ul>\n<pre><code>$(Get-Date -Format \"yyyyMMddTHHmmssZ\")\n\n# UTC\n$(((get-date).ToUniversalTime()).ToString(\"yyyyMMddTHHmmssZ\"))\n<\/code><\/pre>\n<ul>\n<li>\n<p>Get server name<\/p>\n<\/li>\n<\/ul>\n<pre><code>PS C:\\app&gt; [System.Net.Dns]::GetHostName()\n<\/code><\/pre>\n<ul>\n<li>\n<p>One line command to find and replace string<\/p>\n<\/li>\n<\/ul>\n<pre><code>$file='c:\\app\\xxx.config'; (Get-Content $file).replace('Encryption enable=\"true\"', 'Encryption enable=\"false\"') | Set-Content $file\n<\/code><\/pre>\n<ul>\n<li>\n<p>Loop execute each line-by-line<\/p>\n<\/li>\n<\/ul>\n<pre><code>kubectl get pods --no-headers -o custom-columns=\":metadata.name\" | %{ echo '-------' $_ $(kubectl top pod $_) }\n\n\n# %{} ------ loop all lines\n# $_ ------ get var\n<\/code><\/pre>\n<ul>\n<li>\n<p>Curl url without GUI\u00a0<\/p>\n<\/li>\n<\/ul>\n<pre><code>curl $url -UseBasicParsing\nInvoke-WebRequest -Uri $url -UseBasicParsing\n<\/code><\/pre>\n<ul>\n<ul>\n<li>\n<p>error msg:\u00a0The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer&#8217;s first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.<\/p>\n<\/li>\n<\/ul>\n<li>\n<p>Get Virtual memory setting<\/p>\n<\/li>\n<\/ul>\n<pre><code>wmic computersystem get AutomaticManagedPagefile\n<\/code><\/pre>\n<ul>\n<li>\n<p>Get Virtual memory<\/p>\n<\/li>\n<\/ul>\n<pre><code>systeminfo | find \"Virtual Memory\"\n<\/code><\/pre>\n<ul>\n<li>\n<p>Get drive usage<\/p>\n<\/li>\n<\/ul>\n<pre><code>Get-PSDrive\n<\/code><\/pre>\n<ul>\n<li>\n<p>Check powershell version<\/p>\n<\/li>\n<\/ul>\n<pre><code>$Host.Version\n<\/code><\/pre>\n<ul>\n<li>\n<p>Search specific word in EventLog<\/p>\n<\/li>\n<\/ul>\n<pre><code>(Get-EventLog -LogName system -after (Get-Date).AddDays(-10) |\nSelect-Object -Property TimeGenerated,EntryType,Source,Message) -match \"nxlog\" |\nFormat-Table -wrap\n<\/code><\/pre>\n<ul>\n<li>\n<p>Grant permission<\/p>\n<\/li>\n<\/ul>\n<pre><code>C:\\&gt;icacls \"D:\\test\" \/grant John:(OI)(CI)F \/T\nAccording do MS documentation:\n* F = Full Control\n* CI = Container Inherit - This flag indicates that subordinate containers will inherit this ACE.\n* OI = Object Inherit - This flag indicates that subordinate files will inherit the ACE.\n* \/T = Apply recursively to existing files and sub-folders. (OI and CI only apply to new files and sub-folders). Credit: comment by @AlexSpence.\n\n\n========== Detail =========\nicacls \"&lt;root folder&gt;\" \/grant:r \"Domain Admins\":F \/t\n\n\n\nFull Control (F)\nModify (M)\nRead &amp; Execute (RX)\nList Folder Contents (X,RD,RA,REA,RC)\nRead (R)\nWrite (W)\nTraverse folder \/ execute file (X)\nList folder \/ read data (RD)\nRead attributes (RA)\nRead extended attributes (REA)\nCreate file \/ write data (WD)\nCreate folders \/ append data (AD)\nWrite attributes (WA)\nWrite extended attributes (WEA)\nDelete subfolders and files (DC)\nDelete (D)\nRead permissions (RC)\nChange permissions (WDAC)\nTake ownership (WO)\n\nYou can also specify the inheritance for the folders:\nThis folder only\nThis folder, subfolders and files (OI)(CI)\nThis folder and subfolders (CI)\nThis folder and files (OI)\nSubfolders and files only (OI)(CI)(NP)(IO)\nSubfolders only (CI)(IO)\nFiles only (OI)(IO)\n<\/code><\/pre>\n<ul>\n<li>\n<p>Get full column message<\/p>\n<\/li>\n<\/ul>\n<pre><code>| format-table -wrap (-auto)\n<\/code><\/pre>\n<ul>\n<li>\n<p>Check OS version<\/p>\n<\/li>\n<\/ul>\n<pre><code>systeminfo | findstr \/B \/C:\"OS Name\" \/C:\"OS Version\"\n\n\n# Version 1709\nver\n# By registry key:\nreg query \"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\" \/v BuildLabEx\n\n# Ref:\nhttps:\/\/docs.microsoft.com\/en-us\/virtualization\/windowscontainers\/deploy-containers\/version-compatibility?tabs=windows-server-1909%2Cwindows-10-1809#querying-version\n<\/code><\/pre>\n<ul>\n<li>\n<p>Check shared folder connection<\/p>\n<\/li>\n<\/ul>\n<pre><code>net use \\\\server\\share \/user:&lt;domain\\username&gt; &lt;password&gt;\n<\/code><\/pre>\n<ul>\n<li>\n<p>Check permission to file\/folder<\/p>\n<\/li>\n<li>\n<p>Get folder permission<\/p>\n<\/li>\n<\/ul>\n<pre><code>(get-acl &lt;folder name&gt;).access | ft IdentityReference,FileSystemRights,AccessControlType,IsInherited,InheritanceFlags -auto\n<\/code><\/pre>\n<ul>\n<li>\n<p>Get Disk usage<\/p>\n<\/li>\n<\/ul>\n<pre><code>Get-PSDrive\n<\/code><\/pre>\n<ul>\n<li>\n<p>Keep command updated (watch as linux)<\/p>\n<\/li>\n<\/ul>\n<pre><code>while (1) {your_command; sleep 5}\n<\/code><\/pre>\n<ul>\n<li>\n<p>Combine parameters with colon<\/p>\n<\/li>\n<\/ul>\n<pre><code>echo ${aa}:$bb\n<\/code><\/pre>\n<ul>\n<li>\n<p>Find command location<\/p>\n<\/li>\n<\/ul>\n<pre><code>(get-command notepad.exe).Path\n<\/code><\/pre>\n<ul>\n<li>\n<p>Connect and query to SQL\u00a0<\/p>\n<\/li>\n<\/ul>\n<pre><code>$SqlConnection = New-Object System.Data.SqlClient.SqlConnection\n$SqlConnection.ConnectionString = \"server=XXX;database=XXX;uid=XXX;pwd=XXX;\"\n\n$SqlCmd = New-Object System.Data.SqlClient.SqlCommand\n$SqlCmd.CommandText = \"SELECT TOP 1 * FROM XXX\"\n$SqlCmd.Connection = $SqlConnection\n\n$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter\n$SqlAdapter.SelectCommand = $SqlCmd\n$DataSet = New-Object System.Data.DataSet\n$SqlAdapter.Fill($DataSet)\n$DataSet.Tables[0]\n<\/code><\/pre>\n<ul>\n<li>\n<p>Get the latest file in folder<\/p>\n<\/li>\n<\/ul>\n<pre><code>$a = Dir | Sort CreationTime -Descending | Select Name -First 1\ncd $a.name\n<\/code><\/pre>\n<ul>\n<li>\n<p>Select string by regex pattern<\/p>\n<\/li>\n<\/ul>\n<pre><code>Select-String -Path {name} -Pattern '^.*\\\"fail\\\"\\:([0-9]+)\\,\\\"label\\\"\\:\\\"Critical Tests\\\"\\,\\\"pass\\\"\\:([0-9]+?)\\}'\n<\/code><\/pre>\n<ul>\n<li>\n<p>Get domain name by IP<\/p>\n<\/li>\n<\/ul>\n<pre><code>nslookup {IP}\n<\/code><\/pre>\n<ul>\n<li>\n<p>Connect to Network sharing \u7db2\u8def\u4e0a\u7684\u82b3\u9130<\/p>\n<\/li>\n<\/ul>\n<pre><code>New-PSDrive -Name P -PSProvider FileSystem -Root \\\\{{folderPath}} -Credential domain\\{{userName}}\n<\/code><\/pre>\n<p>Notice: can&#8217;t have the back slash at the end.<\/p>\n<ul>\n<li>\n<p>Get current folder path<\/p>\n<\/li>\n<\/ul>\n<pre><code>$pwd\n<\/code><\/pre>\n<ul>\n<li>\n<p>Disable firewall<\/p>\n<\/li>\n<\/ul>\n<pre><code>Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False\n<\/code><\/pre>\n<ul>\n<li>\n<p>Get AD user by identity<\/p>\n<\/li>\n<\/ul>\n<pre><code>Get-ADUser -Identity {{userName}} -Properties *\n<\/code><\/pre>\n<ul>\n<li>\n<p>Set\/Update AD password<\/p>\n<\/li>\n<\/ul>\n<pre><code>Set-ADAccountPassword -Identity john_jang -OldPassword (ConvertTo-SecureString -AsPlainText \"{{password}}\" -Force) -NewPassword (ConvertTo-SecureString -AsPlainText \"{{password}}\" -Force)\n<\/code><\/pre>\n<ul>\n<li>\n<p>Install HyperV on Windows Server<\/p>\n<\/li>\n<\/ul>\n<pre><code>Install-WindowsFeature Hyper-v\n<\/code><\/pre>\n<ul>\n<li>\n<p>Enable hypervisor<\/p>\n<\/li>\n<\/ul>\n<pre><code>bcdedit \/set hypervisorlaunchtype Auto\n<\/code><\/pre>\n<ul>\n<li>\n<p>Enable Nested HyperV &#8211; enable HyperV guest feature inside HyperV host.\u00a0 <a href=\"https:\/\/docs.microsoft.com\/zh-tw\/virtualization\/hyper-v-on-windows\/user-guide\/nested-virtualization\" rev=\"en_rl_none\">ref<\/a><\/p>\n<\/li>\n<\/ul>\n<pre><code>Set-VMProcessor -VMName WinS_2019_rs5 -ExposeVirtualizationExtensions $true\n<\/code><\/pre>\n<ul>\n<li>\n<p>Get current PowerShell version<\/p>\n<\/li>\n<\/ul>\n<pre><code>$PSVersionTable.PSVersion\n<\/code><\/pre>\n<ul>\n<li>\n<p><b>Remote<\/b> scripting<\/p>\n<\/li>\n<\/ul>\n<pre><code>Enter-PSSession -ComputerName {ServerName}\u00a0 -Credential {domain\\name}\n<\/code><\/pre>\n<ul>\n<li>\n<p>Start windows service<\/p>\n<\/li>\n<\/ul>\n<pre><code>get-service *partOfServiceName*\nstart-service serviceName\nstop-service serviceName\n<\/code><\/pre>\n<ul>\n<li>\n<p>Operating windows service<\/p>\n<\/li>\n<\/ul>\n<pre><code>Get-Service *keyword*\u00a0 \u00a0 # Search by keyword\n\n\n# for PowerShellv5 and older version\n$service = Get-WmiObject -Class Win32_Service -Filter \"Name='servicename'\" \n$service.delete()\n\n<\/code><\/pre>\n<ul>\n<li>\n<p>Operating the response from commands<\/p>\n<\/li>\n<\/ul>\n<pre><code>XXcommand | Select-Object -Expand Conlumn\n(XXcommand).ResponseColumn\n<\/code><\/pre>\n<ul>\n<li>\n<p>Send mail<\/p>\n<\/li>\n<\/ul>\n<pre><code>Send-MailMessage -From 'User01 &lt;user01@fabrikam.com&gt;' -To 'User02 &lt;user02@fabrikam.com&gt;' -Subject 'Sending the Attachment' -Body \"Forgot to send the attachment. Sending now.\" -SmtpServer 'smtp.fabrikam.com'\n\n\n# More\nSend-MailMessage -From 'User01 &lt;user01@fabrikam.com&gt;' -To 'User02 &lt;user02@fabrikam.com&gt;', 'User03 &lt;user03@fabrikam.com&gt;' -Subject 'Sending the Attachment' -Body \"Forgot to send the attachment. Sending now.\" -Attachments .\\data.csv -Priority High -DeliveryNotificationOption OnSuccess, OnFailure -SmtpServer 'smtp.fabrikam.com'\n<\/code><\/pre>\n<ul>\n<li>\n<p><b>Create symbolic link from folder to folder.<\/b><\/p>\n<\/li>\n<\/ul>\n<pre><code>mklink \/D {{folderPath_to_create_link_destination}} {{folderPath_to_link_from}}\n\nPS. in PowerShell, use `cmd \/c mklink xxxxx`\nmklink \/d \\MyFolder \\Users\\User1\\Documents\u00a0 \u00a0 # soft link for folder \nmklink \/h \\MyFile.file \\User1\\Documents\\example.file\u00a0  # hard link for file\n<\/code><\/pre>\n<ul>\n<li>\n<p><b><span style=\"font-family: &quot;Titillium Web&quot;;\"><span style=\"font-size: 10pt;\"><span style=\"color:rgb(39, 39, 39);\">Got path not exists<\/span><\/span><\/span><\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p><span style=\"font-size: 10pt;\">Error message:<\/span><\/p>\n<p><span style=\"font-size: 13.3333px;\"><span style=\"--en-highlight:yellow;background-color: #ffef9e;\">&#8220;<\/span><\/span><span style=\"font-family: &quot;Roboto Mono&quot;, monospace;\"><span style=\"font-size: 14px;\"><span style=\"--en-highlight:yellow;background-color: #ffef9e;\"><span style=\"color:rgb(233, 237, 237);\">{path}<\/span><\/span><\/span><\/span><span style=\"--en-highlight:yellow;background-color: #ffef9e;\"> <\/span><span style=\"font-family: &quot;Roboto Mono&quot;, monospace;\"><span style=\"font-size: 14px;\"><span style=\"--en-highlight:yellow;background-color: #ffef9e;\"><span style=\"color:rgb(233, 237, 237);\">No\u00a0such file or directory<\/span><\/span><\/span><\/span><span style=\"font-size: 13.3333px;\"><span style=\"--en-highlight:yellow;background-color: #ffef9e;\">&#8220;<\/span><\/span><\/p>\n<\/li>\n<li>\n<p>Remove the &#8220;&#8221; on the path behind `cat` command.\u00a0<\/p>\n<p>git secrets &#8211;add-provider &#8212; cat .\/folder\/*<\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b><span style=\"font-family: &quot;Titillium Web&quot;;\"><span style=\"font-size: 10pt;\"><span style=\"color:rgb(39, 39, 39);\">Got path not exists<\/span><\/span><\/span><\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p><span style=\"font-size: 10pt;\">Error message:<\/span><\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<p><b><span style=\"font-size: 14pt;\"><span style=\"color:rgb(30, 204, 255);\">Windows Commands\u00a0<\/span><\/span><\/b><\/p>\n<ul>\n<li>\n<p>Print datetime as log filename<\/p>\n<\/li>\n<\/ul>\n<pre><code>echo off\nset CUR_YYYY=%date:~10,4%\nset CUR_MM=%date:~4,2%\nset CUR_DD=%date:~7,2%\nset CUR_HH=%time:~0,2%\nif %CUR_HH% lss 10 (set CUR_HH=0%time:~1,1%)\nset CUR_NN=%time:~3,2%\nset CUR_SS=%time:~6,2%\nset CUR_MS=%time:~9,2%\nset SUBFILENAME=%CUR_YYYY%%CUR_MM%%CUR_DD%-%CUR_HH%%CUR_NN%%CUR_SS%\n\necho \"HI\" &gt;&gt; jj_%SUBFILENAME%.log\u00a0 ## Output: jj_20200902-110133.log\n<\/code><\/pre>\n<ul>\n<li>\n<p>Calling execute file without hanging on it<\/p>\n<\/li>\n<\/ul>\n<pre><code>start \"\" XXX.exe -p C:\\Work\n<\/code><\/pre>\n<ul>\n<li>\n<p>\u522a\u9664 Windows service<\/p>\n<\/li>\n<\/ul>\n<pre><code>SC delete {{serviceName}}\n<\/code><\/pre>\n<ul>\n<li>\n<p>\u95dc\u9589 WSUS<\/p>\n<\/li>\n<\/ul>\n<pre><code>\"Computer\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU\" &gt; UseWUServer &gt; 0\n-------\n$currentWU = Get-ItemProperty -Path \"HKLM:\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU\" -Name \"UseWUServer\" | select -ExpandProperty UseWUServer\nSet-ItemProperty -Path \"HKLM:\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU\" -Name \"UseWUServer\" -Value 0\nRestart-Service wuauserv\n<\/code><\/pre>\n<ul>\n<li>\n<p>Install RSAT Tools<\/p>\n<\/li>\n<\/ul>\n<pre><code># install AD management tools (including the ADUC console):\nAdd-WindowsCapability \u2013online \u2013Name \u201cRsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0\u201d\n# install DNS management console, run:\nAdd-WindowsCapability \u2013online \u2013Name \u201cRsat.Dns.Tools~~~~0.0.1.0\u201d\n# Verify\nGet-WindowsCapability -Name RSAT* -Online | Select-Object -Property DisplayName, State\n\n# Etc.\nAdd-WindowsCapability -Online -Name Rsat.FileServices.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.GroupPolicy.Management.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.IPAM.Client.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.LLDP.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.NetworkController.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.NetworkLoadBalancing.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.BitLocker.Recovery.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.CertificateServices.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.DHCP.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.FailoverCluster.Management.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.RemoteAccess.Management.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.RemoteDesktop.Services.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.ServerManager.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.Shielded.VM.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.StorageMigrationService.Management.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.StorageReplica.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.SystemInsights.Management.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.VolumeActivation.Tools~~~~0.0.1.0\nAdd-WindowsCapability -Online -Name Rsat.WSUS.Tools~~~~0.0.1.0\n\n# To install all the available RSAT tools at once, run:\nGet-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability \u2013Online\n# To install only disabled RSAT components, run:\nGet-WindowsCapability -Online |? {$_.Name -like \"*RSAT*\" -and $_.State -eq \"NotPresent\"} | Add-WindowsCapability -Online\n<\/code><\/pre>\n<p><b><span style=\"font-size: 14pt;\"><span style=\"color:rgb(30, 204, 255);\">Windows Others<\/span><\/span><\/b><\/p>\n<ul>\n<li>\n<p>Check current windows version (GUI)<\/p>\n<\/li>\n<\/ul>\n<pre><code>Check your Windows version by selecting the Windows logo key + R, type winver\n<\/code><\/pre>\n<ul>\n<li>\n<p>Loop script &#8211; foreach<\/p>\n<\/li>\n<\/ul>\n<pre><code>set list=A B C D\n\n\nfor %%a in (%list%) do (\n\u00a0 echo %%a\n\u00a0 echo\/\n)\n<\/code><\/pre>\n<ul>\n<li>\n<p>Auto newline to &#8220;press ENTER to continue&#8221; (or any key XXXX)<\/p>\n<\/li>\n<\/ul>\n<pre><code>echo XXXX | YYYY\n<\/code><\/pre>\n<ul>\n<li>\n<p>Add app to startup<\/p>\n<\/li>\n<ul>\n<li>\n<p>Win + R &gt; run &#8220;shell:startup&#8221;<\/p>\n<\/li>\n<li>\n<p>Add app shortcut to folder.<\/p>\n<\/li>\n<\/ul>\n<li>\n<p>Disable error reporting &#8211; &#8220;Hold on &#8220;<\/p>\n<\/li>\n<ul>\n<li>\n<p>Win + R &gt; run &#8220;services.msc&#8221;<\/p>\n<\/li>\n<li>\n<p>Disable service: &#8220;Windows Error Reporting Service&#8221;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2022\/08\/8b25a37b50f0ae5949bce4dc084a06b0.png\"\/><\/li>\n<\/ul>\n<li>\n<p>\u95dc\u9589 telnet<\/p>\n<\/li>\n<\/ul>\n<pre><code>Ctrl + ]\ntelnet&gt; quit(q) \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>PowerShell\u00a0<\/p>\n<\/div>","protected":false},"author":1,"featured_media":1904,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1289","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PowerShell\/Windows commands (updating) - John&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/john.pentaidea.com\/?p=1289\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PowerShell\/Windows commands (updating) - John&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"PowerShell\u00a0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/john.pentaidea.com\/?p=1289\" \/>\n<meta property=\"og:site_name\" content=\"John&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-12-13T02:49:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2022\/08\/8b25a37b50f0ae5949bce4dc084a06b0.png\" \/>\n\t<meta property=\"og:image:width\" content=\"988\" \/>\n\t<meta property=\"og:image:height\" content=\"257\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"jj\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"jj\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/john.pentaidea.com\/?p=1289\",\"url\":\"https:\/\/john.pentaidea.com\/?p=1289\",\"name\":\"PowerShell\/Windows commands (updating) - John&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/john.pentaidea.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/john.pentaidea.com\/?p=1289#primaryimage\"},\"image\":{\"@id\":\"https:\/\/john.pentaidea.com\/?p=1289#primaryimage\"},\"thumbnailUrl\":\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2022\/08\/8b25a37b50f0ae5949bce4dc084a06b0.png\",\"datePublished\":\"2018-12-13T02:49:04+00:00\",\"dateModified\":\"2018-12-13T02:49:04+00:00\",\"author\":{\"@id\":\"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f\"},\"breadcrumb\":{\"@id\":\"https:\/\/john.pentaidea.com\/?p=1289#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/john.pentaidea.com\/?p=1289\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/john.pentaidea.com\/?p=1289#primaryimage\",\"url\":\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2022\/08\/8b25a37b50f0ae5949bce4dc084a06b0.png\",\"contentUrl\":\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2022\/08\/8b25a37b50f0ae5949bce4dc084a06b0.png\",\"width\":988,\"height\":257},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/john.pentaidea.com\/?p=1289#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/john.pentaidea.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PowerShell\/Windows commands (updating)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/john.pentaidea.com\/#website\",\"url\":\"https:\/\/john.pentaidea.com\/\",\"name\":\"John's Blog\",\"description\":\"\u4e16\u754c\u56e0\u601d\u7dd2\u800c\u8907\u96dc, \u4eba\u56e0\u5922\u60f3\u800c\u5049\u5927\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/john.pentaidea.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f\",\"name\":\"jj\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/john.pentaidea.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g\",\"caption\":\"jj\"},\"sameAs\":[\"https:\/\/john.pentaidea.com\"],\"url\":\"https:\/\/john.pentaidea.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PowerShell\/Windows commands (updating) - John&#039;s Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/john.pentaidea.com\/?p=1289","og_locale":"en_US","og_type":"article","og_title":"PowerShell\/Windows commands (updating) - John&#039;s Blog","og_description":"PowerShell\u00a0","og_url":"https:\/\/john.pentaidea.com\/?p=1289","og_site_name":"John&#039;s Blog","article_published_time":"2018-12-13T02:49:04+00:00","og_image":[{"width":988,"height":257,"url":"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2022\/08\/8b25a37b50f0ae5949bce4dc084a06b0.png","type":"image\/png"}],"author":"jj","twitter_card":"summary_large_image","twitter_misc":{"Written by":"jj","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/john.pentaidea.com\/?p=1289","url":"https:\/\/john.pentaidea.com\/?p=1289","name":"PowerShell\/Windows commands (updating) - John&#039;s Blog","isPartOf":{"@id":"https:\/\/john.pentaidea.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/john.pentaidea.com\/?p=1289#primaryimage"},"image":{"@id":"https:\/\/john.pentaidea.com\/?p=1289#primaryimage"},"thumbnailUrl":"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2022\/08\/8b25a37b50f0ae5949bce4dc084a06b0.png","datePublished":"2018-12-13T02:49:04+00:00","dateModified":"2018-12-13T02:49:04+00:00","author":{"@id":"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f"},"breadcrumb":{"@id":"https:\/\/john.pentaidea.com\/?p=1289#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/john.pentaidea.com\/?p=1289"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/john.pentaidea.com\/?p=1289#primaryimage","url":"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2022\/08\/8b25a37b50f0ae5949bce4dc084a06b0.png","contentUrl":"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2022\/08\/8b25a37b50f0ae5949bce4dc084a06b0.png","width":988,"height":257},{"@type":"BreadcrumbList","@id":"https:\/\/john.pentaidea.com\/?p=1289#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/john.pentaidea.com\/"},{"@type":"ListItem","position":2,"name":"PowerShell\/Windows commands (updating)"}]},{"@type":"WebSite","@id":"https:\/\/john.pentaidea.com\/#website","url":"https:\/\/john.pentaidea.com\/","name":"John's Blog","description":"\u4e16\u754c\u56e0\u601d\u7dd2\u800c\u8907\u96dc, \u4eba\u56e0\u5922\u60f3\u800c\u5049\u5927","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/john.pentaidea.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f","name":"jj","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/john.pentaidea.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g","caption":"jj"},"sameAs":["https:\/\/john.pentaidea.com"],"url":"https:\/\/john.pentaidea.com\/?author=1"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2022\/08\/8b25a37b50f0ae5949bce4dc084a06b0.png","_links":{"self":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts\/1289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1289"}],"version-history":[{"count":0,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts\/1289\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/media\/1904"}],"wp:attachment":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}