{"id":10932,"date":"2024-10-04T17:46:07","date_gmt":"2024-10-04T15:46:07","guid":{"rendered":"https:\/\/lazyadmin.nl\/?p=10932"},"modified":"2024-10-04T17:46:11","modified_gmt":"2024-10-04T15:46:11","slug":"wait-command","status":"publish","type":"post","link":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/","title":{"rendered":"How to Wait for a Command in PowerShell"},"content":{"rendered":"\n<p>When you run a command or start a process from PowerShell, you often want to wait for the command or process to finish, before the script continues. The easiest option for this is to use the -Wait parameter from the Start-Process cmdlet, but there are other options as well.<\/p>\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">In this article<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f55781543c1\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\" style='display:none' id=\"ez-toc-cssicon-toggle-item-69f55781543c1\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#wait-in-powershell\" >Wait in PowerShell<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#start-process-with-wait\" >Start-Process with -Wait<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#wait-process\" >Wait-Process<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#start-sleep\" >Start-Sleep<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#wait-for-input\" >Wait for Input<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#wrapping-up\" >Wrapping Up<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<p>In this article, we will look at how to use the -Wait parameter, use the Wait-Process cmdlet and I will show you some other options as well.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"wait-in-powershell\"><\/span>Wait in PowerShell<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We can use PowerShell for all kinds of tasks, including starting a program or running another command. But the &#8220;problem&#8221; with PowerShell is, that it by default won&#8217;t wait for the program or command to finish.<\/p>\n\n\n\n<p>It will just try to start the program or run the command, and if that is successful, it will continue to the next part of your script. Now in some situations, you want PowerShell to wait before it continues. To do this, we have a couple of options:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>-Wait<\/strong> <strong>parameter <\/strong>for the Start-Process cmdlet<\/li>\n\n\n\n<li><strong>Wait-Process<\/strong><\/li>\n\n\n\n<li><strong>Start-Sleep<\/strong><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"start-process-with-wait\"><\/span>Start-Process with -Wait<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>When you want to run a program or command from PowerShell, you can use the <code>Start-Process<\/code> cmdlet. Let&#8217;s take a look at an example, we are going to open a text file in Notepad, and wait for the user to close the file, before we continue with the script:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Open File1.txt in the default editor (notepad)\nStart-Process -FilePath \"C:\\temp\\File1.txt\" -Wait\n\n# Notepad is closed, get the content of the file\nGet-Content -path \"C:\\temp\\File1.txt\"<\/pre>\n\n\n\n<p>If you run the above code in PowerShell, you will see that Notepad will open, allowing you to write content in the file, and after you close it, the contents of the file will be displayed in the console.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"798\" height=\"231\" src=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/image-21.png\" alt=\"powershell wait command\" class=\"wp-image-10936\" srcset=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/image-21.png 798w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/image-21-300x87.png 300w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/image-21-768x222.png 768w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/image-21-400x116.png 400w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/image-21-50x14.png 50w\" sizes=\"(max-width: 798px) 100vw, 798px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"wait-process\"><\/span>Wait-Process<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Another option is to use the <code>Wait-Process<\/code> cmdlet. This cmdlet waits for one or more processes to be closed before it allows PowerShell to continue. Important to note, that the Wait-Process cmdlet doesn&#8217;t work on Linux or macOS.<\/p>\n\n\n\n<p>To check if a process is closed, we first need to know the process name or process ID. Another option is to use a process object, which we for example can get with the <code>Get-Process<\/code> or <code>Start-Process<\/code> cmdlet.<\/p>\n\n\n\n<p>If you know the process name and the name is unique, then you can simply use the <code>-name<\/code> parameter to get and wait for the process to finish:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Wait-Process Name \"Notepad\"<\/pre>\n\n\n\n<p>Another option is to first look up the process, using the <code>Get-Process<\/code> cmdlet. This cmdlet will list all running processes, but we can also filter the processes on name using the <code>-name<\/code> parameter. Good to know is that we can use wildcards in the name:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$proc = Get-Process -Name \"Notepad\"\nWait-Proces -Id $proc.id<\/pre>\n\n\n\n<p>We can also combine Start-Process and Wait-Process. To do this, we will need to use the <code>-PassThru<\/code> parameter for the Start-Process cmdlet so it returns the process object.<\/p>\n\n\n\n<p>This allows us to do comes while the process is running, but check later in the script if the process is finished before we continue with the last part:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Start the process\n$process = Start-Process -FilePath \"notepad.exe\" -ArgumentList \"C:\\temp\\File1.txt\" -PassThru\n\n# Do something in between\nWrite-Output \"Process $($process.Id) is running.\"\n\n# Wait untill process is finished\nWait-Process -Id $process.Id\nWrite-Output \"Process has finished.\"<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"start-sleep\"><\/span>Start-Sleep<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The last method that you could use to wait if a process is finished in PowerShell is the <a href=\"https:\/\/lazyadmin.nl\/powershell\/pause-powershell\/\">Start-Sleep method<\/a>. This cmdlet isn&#8217;t able to check if a process is running or not but only lets PowerShell wait for an x amount of time.<\/p>\n\n\n\n<p>This can still be pretty useful if you for example know that a process always needs a couple of seconds to get up and running or to finish.<\/p>\n\n\n\n<p>The <code>Start-Sleep<\/code> cmdlet works by specifying how long, in seconds or milliseconds, PowerShell should wait.<\/p>\n\n\n\n<p>For example, to let PowerShell Wait for 5 seconds, we can use:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Wait for 5 seconds before continuing\nStart-Sleep -Seconds 5<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"wait-for-input\"><\/span>Wait for Input<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Another method that I want to show you as well is to wait for input in PowerShell. Sometimes it&#8217;s just easier to let PowerShell wait for a keypress before it continues. This can be any key input, or a specific key if you want. We have two options to wait for input, we can use the <code>ReadKey<\/code> method from the <code>System.Console .Net<\/code> class or we can use the <code>Read-Host method<\/code>. <\/p>\n\n\n\n<p>The ReadKey method below won&#8217;t return any output in the console (except for the write-host of course), but it doesn&#8217;t work in PowerShell ISE (but I <a href=\"https:\/\/lazyadmin.nl\/powershell\/powershell-script\/\">recommend using Visual Studio Code<\/a> anyway..)<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Write-Host \"Press any key to continue...\"\n$Host.UI.RawUI.ReadKey(\"NoEcho,IncludeKeyDown\") | Out-Null<\/pre>\n\n\n\n<p>With Read-Host, however, we can specify which key the user must press. This give a bit more control over when to continue the script. In the example below, we combine a While loop with the Read-Host cmdlet, so it will keep asking to press the <code>Y<\/code> key before PowerShell continues.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">while ((Read-Host \"Press 'Y' to continue\") -ne 'Y') {}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"wrapping-up\"><\/span>Wrapping Up<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When start the process or command from PowerShell, it&#8217;s best to use the Start-Process cmdlet combined with the -Wait parameter. If the process is already running, then the Wait-Process cmdlet is the best option to use.<\/p>\n\n\n\n<p>Hope you liked this article, if you have any questions, just drop a comment below.<\/p>\n<script async src=\"https:\/\/alatus.eocampaign1.com\/form\/d0ce5de8-9b48-11ee-8cf4-eb425eea7369.js\" data-form=\"d0ce5de8-9b48-11ee-8cf4-eb425eea7369\"><\/script>","protected":false},"excerpt":{"rendered":"<p>When you run a command or start a process from PowerShell, you often want to wait for the command or process to finish, before the script continues. The easiest option for this is to use the -Wait parameter from the &#8230; <a title=\"How to Wait for a Command in PowerShell\" class=\"read-more\" href=\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/\">Read more<span class=\"screen-reader-text\">How to Wait for a Command in PowerShell<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":10938,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[69],"tags":[22],"class_list":["post-10932","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-powershell"],"wppr_data":{"cwp_meta_box_check":"No"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Wait for a Command in PowerShell &#8212; LazyAdmin<\/title>\n<meta name=\"description\" content=\"Let your PowerShell script Wait for a Command or Process to finish with these 3 Methods.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Wait for a Command in PowerShell &#8212; LazyAdmin\" \/>\n<meta property=\"og:description\" content=\"Let your PowerShell script Wait for a Command or Process to finish with these 3 Methods.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/\" \/>\n<meta property=\"og:site_name\" content=\"LazyAdmin\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/lazyadminnl\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/lazyadminnl\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-04T15:46:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-04T15:46:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"450\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Rudy Mens\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/lazyadmin\" \/>\n<meta name=\"twitter:site\" content=\"@lazyadmin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rudy Mens\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/\"},\"author\":{\"name\":\"Rudy Mens\",\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952\"},\"headline\":\"How to Wait for a Command in PowerShell\",\"datePublished\":\"2024-10-04T15:46:07+00:00\",\"dateModified\":\"2024-10-04T15:46:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/\"},\"wordCount\":778,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952\"},\"image\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg\",\"keywords\":[\"Powershell\"],\"articleSection\":[\"PowerShell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/\",\"url\":\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/\",\"name\":\"How to Wait for a Command in PowerShell &#8212; LazyAdmin\",\"isPartOf\":{\"@id\":\"https:\/\/lazyadmin.nl\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg\",\"datePublished\":\"2024-10-04T15:46:07+00:00\",\"dateModified\":\"2024-10-04T15:46:11+00:00\",\"description\":\"Let your PowerShell script Wait for a Command or Process to finish with these 3 Methods.\",\"breadcrumb\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#primaryimage\",\"url\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg\",\"contentUrl\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg\",\"width\":800,\"height\":450,\"caption\":\"PowerShell Wait Command\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/lazyadmin.nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Wait for a Command in PowerShell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/lazyadmin.nl\/#website\",\"url\":\"https:\/\/lazyadmin.nl\/\",\"name\":\"LazyAdmin\",\"description\":\"Tips and howto&#039;s about Office 365, PowerShell, Home network and smart devices\",\"publisher\":{\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/lazyadmin.nl\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952\",\"name\":\"Rudy Mens\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/06\/Profile-photo-2024-Ruud.jpg\",\"contentUrl\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/06\/Profile-photo-2024-Ruud.jpg\",\"width\":500,\"height\":500,\"caption\":\"Rudy Mens\"},\"logo\":{\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/image\/\"},\"description\":\"Ruud worked for more than 15 years as a SysAdmin in the Netherlands and is now working as an independent consultant. In his spare time, he loves to thinker with Smart Devices.\",\"sameAs\":[\"https:\/\/lazyadmin.nl\",\"https:\/\/www.facebook.com\/lazyadminnl\/\",\"http:\/\/nl.linkedin.com\/in\/rudymens\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/lazyadmin\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Wait for a Command in PowerShell &#8212; LazyAdmin","description":"Let your PowerShell script Wait for a Command or Process to finish with these 3 Methods.","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:\/\/lazyadmin.nl\/powershell\/wait-command\/","og_locale":"en_US","og_type":"article","og_title":"How to Wait for a Command in PowerShell &#8212; LazyAdmin","og_description":"Let your PowerShell script Wait for a Command or Process to finish with these 3 Methods.","og_url":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/","og_site_name":"LazyAdmin","article_publisher":"https:\/\/www.facebook.com\/lazyadminnl\/","article_author":"https:\/\/www.facebook.com\/lazyadminnl\/","article_published_time":"2024-10-04T15:46:07+00:00","article_modified_time":"2024-10-04T15:46:11+00:00","og_image":[{"width":800,"height":450,"url":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg","type":"image\/jpeg"}],"author":"Rudy Mens","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/lazyadmin","twitter_site":"@lazyadmin","twitter_misc":{"Written by":"Rudy Mens","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#article","isPartOf":{"@id":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/"},"author":{"name":"Rudy Mens","@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952"},"headline":"How to Wait for a Command in PowerShell","datePublished":"2024-10-04T15:46:07+00:00","dateModified":"2024-10-04T15:46:11+00:00","mainEntityOfPage":{"@id":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/"},"wordCount":778,"commentCount":0,"publisher":{"@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952"},"image":{"@id":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#primaryimage"},"thumbnailUrl":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg","keywords":["Powershell"],"articleSection":["PowerShell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/lazyadmin.nl\/powershell\/wait-command\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/","url":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/","name":"How to Wait for a Command in PowerShell &#8212; LazyAdmin","isPartOf":{"@id":"https:\/\/lazyadmin.nl\/#website"},"primaryImageOfPage":{"@id":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#primaryimage"},"image":{"@id":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#primaryimage"},"thumbnailUrl":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg","datePublished":"2024-10-04T15:46:07+00:00","dateModified":"2024-10-04T15:46:11+00:00","description":"Let your PowerShell script Wait for a Command or Process to finish with these 3 Methods.","breadcrumb":{"@id":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/lazyadmin.nl\/powershell\/wait-command\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#primaryimage","url":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg","contentUrl":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg","width":800,"height":450,"caption":"PowerShell Wait Command"},{"@type":"BreadcrumbList","@id":"https:\/\/lazyadmin.nl\/powershell\/wait-command\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/lazyadmin.nl\/"},{"@type":"ListItem","position":2,"name":"How to Wait for a Command in PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/lazyadmin.nl\/#website","url":"https:\/\/lazyadmin.nl\/","name":"LazyAdmin","description":"Tips and howto&#039;s about Office 365, PowerShell, Home network and smart devices","publisher":{"@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/lazyadmin.nl\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952","name":"Rudy Mens","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/image\/","url":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/06\/Profile-photo-2024-Ruud.jpg","contentUrl":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/06\/Profile-photo-2024-Ruud.jpg","width":500,"height":500,"caption":"Rudy Mens"},"logo":{"@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/image\/"},"description":"Ruud worked for more than 15 years as a SysAdmin in the Netherlands and is now working as an independent consultant. In his spare time, he loves to thinker with Smart Devices.","sameAs":["https:\/\/lazyadmin.nl","https:\/\/www.facebook.com\/lazyadminnl\/","http:\/\/nl.linkedin.com\/in\/rudymens\/","https:\/\/x.com\/https:\/\/twitter.com\/lazyadmin"]}]}},"uagb_featured_image_src":{"full":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg",800,450,false],"thumbnail":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command-150x150.jpg",150,150,true],"medium":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command-300x169.jpg",300,169,true],"medium_large":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command-768x432.jpg",768,432,true],"large":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg",800,450,false],"1536x1536":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg",800,450,false],"2048x2048":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg",800,450,false],"post-thumb":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg",800,450,false],"post-thumb-half":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command-400x225.jpg",400,225,true],"wppr-widget":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command-50x28.jpg",50,28,true],"gform-image-choice-sm":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg",300,169,false],"gform-image-choice-md":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg",400,225,false],"gform-image-choice-lg":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/10\/PowerShell-Wait-Command.jpg",600,338,false]},"uagb_author_info":{"display_name":"Rudy Mens","author_link":"https:\/\/lazyadmin.nl\/author\/lajcud8123b\/"},"uagb_comment_info":0,"uagb_excerpt":"When you run a command or start a process from PowerShell, you often want to wait for the command or process to finish, before the script continues. The easiest option for this is to use the -Wait parameter from the ... Read moreHow to Wait for a Command in PowerShell","_links":{"self":[{"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/posts\/10932"}],"collection":[{"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/comments?post=10932"}],"version-history":[{"count":0,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/posts\/10932\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/media\/10938"}],"wp:attachment":[{"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/media?parent=10932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/categories?post=10932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/tags?post=10932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}