{"id":3131,"date":"2020-02-03T06:13:08","date_gmt":"2020-02-03T14:13:08","guid":{"rendered":"https:\/\/techthoughts.info\/?p=3131"},"modified":"2020-02-03T06:13:14","modified_gmt":"2020-02-03T14:13:14","slug":"powershell-scripts","status":"publish","type":"post","link":"https:\/\/www.techthoughts.info\/powershell-scripts\/","title":{"rendered":"PowerShell Scripts"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_69_1 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<label for=\"ez-toc-cssicon-toggle-item-69e4e1114d70a\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><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\"  id=\"ez-toc-cssicon-toggle-item-69e4e1114d70a\"  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:\/\/www.techthoughts.info\/powershell-scripts\/#PowerShell_Scripts\" title=\"PowerShell Scripts\">PowerShell Scripts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.techthoughts.info\/powershell-scripts\/#Video\" title=\"Video\">Video<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.techthoughts.info\/powershell-scripts\/#Creating_and_Saving_PowerShell_Scripts\" title=\"Creating and Saving PowerShell Scripts\">Creating and Saving PowerShell Scripts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.techthoughts.info\/powershell-scripts\/#Running_PowerShell_Scripts\" title=\"Running PowerShell Scripts\">Running PowerShell Scripts<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.techthoughts.info\/powershell-scripts\/#PowerShell_Execution_Policy\" title=\"PowerShell Execution Policy\">PowerShell Execution Policy<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.techthoughts.info\/powershell-scripts\/#Script_Scope\" title=\"Script Scope\">Script Scope<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.techthoughts.info\/powershell-scripts\/#PowerShell_Script_Example\" title=\"PowerShell Script Example\">PowerShell Script Example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.techthoughts.info\/powershell-scripts\/#Additional_Reading\" title=\"Additional Reading\">Additional Reading<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"PowerShell_Scripts\"><\/span>PowerShell Scripts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Episodes 0-9 of the <a rel=\"noreferrer noopener\" aria-label=\"Learn PowerShell (opens in a new tab)\" href=\"https:\/\/techthoughts.info\/learn-powershell-series\/\" target=\"_blank\">Learn PowerShell<\/a> series covered the fundamentals of PowerShell. Now, in Episode 10, you have the basic elements to begin creating your own PowerShell scripts!<\/p>\n\n\n\n<p>A PowerShell script is simply a <em>ps1 file<\/em> that contains PowerShell logic. What logic is entirely up to you and will be shaped by the purpose of the script. If you haven&#8217;t already you should begin attempting to write your first script. Not sure what to create? Think about a process that you perform often at work that requires a lot of manual steps. Try performing those same steps and save it as a script! If your first attempt turns out to be too difficult, drop down to a task that has lower complexity.<\/p>\n\n\n\n<p>Every time you succeed, no matter how small, you&#8217;ll be freeing up your bandwidth! With that extra time in your day, you can write a little more PowerShell, which will create even more bandwidth to tackle more complex tasks. Before you know it, you&#8217;ll have a collection of scripts capable of performing a variety of tasks that used to be manual processes!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Video\"><\/span>Video<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p> If you prefer video format over written documentation, I discuss this topic in the following TechThoughts video:  <\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"video-container\"><iframe loading=\"lazy\" title=\"PowerShell Scripts\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/IABNJEl2ZWk?feature=oembed&#038;wmode=opaque\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/div>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_and_Saving_PowerShell_Scripts\"><\/span>Creating and Saving PowerShell Scripts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Creating a PowerShell script is as simple as saving your PowerShell commands with the <strong>.ps1<\/strong> file extension. Go ahead and copy the simple code below and save it as <strong>math.ps1<\/strong>. We&#8217;ll use this simple script example moving forward.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: Code example:; notranslate\" title=\"Code example:\">\n$total = 2 + 2\n$output = &quot;two plus two is equal to $total&quot;\nWrite-Output $output\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Running_PowerShell_Scripts\"><\/span>Running PowerShell Scripts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can run a PowerShell script by specifying the path to the script:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: Code example:; notranslate\" title=\"Code example:\">\n#windows\nC:\\scripts\\math.ps1\n#linux\n\/scripts\/math.ps1\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"PowerShell_Execution_Policy\"><\/span>PowerShell Execution Policy<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Depending on the configuration of your device and environment you may not be able to run PowerShell scripts. You may need to adjust your PowerShell Execution policy.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Restricted<\/strong> \u2014 Stops any script from running.<\/li><li><strong>RemoteSigned<\/strong> \u2014 Runs scripts created on the device. However, scripts created on another computer won&#8217;t run unless they include a signature of a trusted publisher.<\/li><li><strong>AllSigned<\/strong> \u2014 All the scripts will run as long as they&#8217;ve been signed by a trusted publisher.<\/li><li><strong>Unrestricted<\/strong> \u2014 Runs any script without any restrictions.<\/li><\/ul>\n\n\n\n<p>To determine the current execution policy run the following cmdlet:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: Code example:; notranslate\" title=\"Code example:\">\n#get the execution policy of all scopes in the order of precedence\nGet-ExecutionPolicy -List\n<\/pre><\/div>\n\n\n<p>To change the execution policy:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: Code example:; notranslate\" title=\"Code example:\">\n#change execution policy\nSet-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Script_Scope\"><\/span>Script Scope<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>When you run a script by specifying the ps1 file path, that script does not run in the scope of the current session. This means that if you open a PowerShell session, and run a script, you will not have access to the variables and information in your current session. You can see this in action for yourself. Open a PowerShell window and run the <strong>math.ps1<\/strong> script from above.<\/p>\n\n\n\n<p>After it runs, try typing <strong>$total<\/strong> in your PowerShell session. It will not return anything. This is because <strong>math.ps1<\/strong> was run under the scope of a different PowerShell session. Once the script completed, so did that session.<\/p>\n\n\n\n<p>If you need to access the information in the context of the current PowerShell session, you can <strong><em>dot source<\/em><\/strong> the PowerShell script. This is achieved by placing a dot and then a space before the script path.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: Code example:; notranslate\" title=\"Code example:\">\n# dot source a full file path\n. C:\\scripts\\math.ps1\n# dot source a local file\n. .\\math.ps1\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"PowerShell_Script_Example\"><\/span>PowerShell Script Example<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you&#8217;ve completed Episodes 0-9, you&#8217;re ready to start writing PowerShell scripts. You may not feel ready, but the only way to shake that feeling is to write more PowerShell. We&#8217;re going to kick things off with our first script. Before sitting down and writing code, you need to have an objective. Lets declare our script&#8217;s objective now.<\/p>\n\n\n\n<p>We want to be notified when a drive in our home network is running low on space. The script will check the desired drive for free space, and send a <a rel=\"noreferrer noopener\" aria-label=\"Telegram (opens in a new tab)\" href=\"https:\/\/telegram.org\/\" target=\"_blank\">Telegram<\/a> notification if it is below 20%. All actions should be logged. The script should support scanning multiple different drives. The script should support both Linux and Windows.<\/p>\n\n\n\n<p> If this is your first time writing a script, you may have no idea where to start. That&#8217;s OK. Just break the objective into manageable chunks:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Supports logging<\/li><li>Checks desired drive for free space<\/li><li>Sends Telegram notification<\/li><li>Lets user specify drive<\/li><li>Supports both windows and Linux<\/li><\/ul>\n\n\n\n<p>Try tackling these one at a time. In the video above you can watch me live-code this solution. This gives you a chance to see my thought process and workflow for tackling something like this. Alternatively, you can reference the solution below, and try scripting your own objective.<\/p>\n\n\n\n<p>As an additional exercise try enhancing the script below to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Permit the user to specify the percentage threshold<ul><li>Tip: it&#8217;s currently hard-coded to 20<\/li><\/ul><\/li><li>Not a Telegram user? Try adjusting the script to send an email instead.<\/li><\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: Code example:; notranslate\" title=\"Code example:\">\nparam (\n    &#x5B;Parameter(Mandatory = $true)]\n    &#x5B;string]\n    $Drive\n)\n\nif ($PSVersionTable.Platform -eq &#039;Unix&#039;) {\n    $logPath = &#039;\/tmp&#039;\n}\nelse {\n    $logPath = &#039;C:\\Logs&#039; #log path location\n}\n\n#need linux path\n\n$logFile = &quot;$logPath\\driveCheck.log&quot; #log file\n\n#verify if log directory path is present. if not, create it.\ntry {\n    if (-not (Test-Path -Path $logPath -ErrorAction Stop )) {\n        # Output directory not found. Creating...\n        New-Item -ItemType Directory -Path $logPath -ErrorAction Stop | Out-Null\n        New-Item -ItemType File -Path $logFile -ErrorAction Stop | Out-Null\n    }\n}\ncatch {\n    throw\n}\n\nAdd-Content -Path $logFile -Value &quot;&#x5B;INFO] Running $PSCommandPath&quot;\n\n#verify that the required Telegram module is installed.\nif (-not (Get-Module -ListAvailable -Name PoshGram)) {\n    Add-Content -Path $logFile -Value &#039;&#x5B;INFO] PoshGram not installed.&#039;\n    throw\n}\nelse {\n    Add-Content -Path $logFile -Value &#039;&#x5B;INFO] PoshGram module verified.&#039;\n}\n\n#get hard drive volume information and free space\ntry {\n    if ($PSVersionTable.Platform -eq &#039;Unix&#039;) {\n        $volume = Get-PSDrive -Name $Drive -ErrorAction Stop\n        #verify volume actually exists\n        if ($volume) {\n            $total = $volume.Free + $volume.Used\n            $percentFree = &#x5B;int](($volume.Free \/ $total) * 100)\n            Add-Content -Path $logFile -Value &quot;&#x5B;INFO] Percent Free: $percentFree%&quot;\n        }\n        else {\n            Add-Content -Path $logFile -Value &quot;&#x5B;ERROR] $Drive was not found.&quot;\n            throw\n        }\n    }\n    else {\n        $volume = Get-Volume -ErrorAction Stop | Where-Object { $_.DriveLetter -eq $Drive }\n        #verify volume actually exists\n        if ($volume) {\n            $total = $volume.Size\n            $percentFree = &#x5B;int](($volume.SizeRemaining \/ $total) * 100)\n            Add-Content -Path $logFile -Value &quot;&#x5B;INFO] Percent Free: $percentFree%&quot;\n        }\n        else {\n            Add-Content -Path $logFile -Value &quot;&#x5B;ERROR] $Drive was not found.&quot;\n            throw\n        }\n    }\n}\ncatch {\n    Add-Content -Path $logFile -Value &#039;&#x5B;ERROR] Unable to retrieve volume information:&#039;\n    Add-Content -Path $logFile -Value $_\n    throw\n}\n\n#evaluate if a message needs to be sent if the drive is below 20GB freespace\nif ($percentFree -le 20) {\n\n    try {\n        Import-Module PoshGram -ErrorAction Stop\n        Add-Content -Path $logFile -Value &#039;&#x5B;INFO] PoshGram imported successfully.&#039;\n    }\n    catch {\n        Add-Content -Path $logFile -Value &#039;&#x5B;ERROR] PoshGram could not be imported:&#039;\n        Add-Content -Path $logFile -Value $_\n        throw\n    }\n\n    Add-Content -Path $logFile -Value &#039;&#x5B;INFO] Sending Telegram notification&#039;\n\n    $messageSplat = @{\n        BotToken    = &quot;#########:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;\n        ChatID      = &quot;-#########&quot;\n        Message     = &quot;&#x5B;LOW SPACE] Drive at: $percentFree%&quot;\n        ErrorAction = &#039;Stop&#039;\n    }\n\n    try {\n        Send-TelegramTextMessage @messageSplat\n        Add-Content -Path $logFile -Value &#039;&#x5B;INFO] Message sent successfully&#039;\n    }\n    catch {\n        Add-Content -Path $logFile -Value &#039;&#x5B;ERROR] Error encountered sending message:&#039;\n        Add-Content -Path $logFile -Value $_\n        throw\n    }\n\n}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Additional_Reading\"><\/span>Additional Reading<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/docs.microsoft.com\/powershell\/module\/microsoft.powershell.core\/about\/about_scripts?view=powershell-6\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"About&nbsp;Scripts (opens in a new tab)\">About&nbsp;Scripts<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\" About&nbsp;Execution&nbsp;Policies (opens in a new tab)\" href=\"https:\/\/docs.microsoft.com\/powershell\/module\/microsoft.powershell.core\/about\/about_execution_policies?view=powershell-6\" target=\"_blank\">About&nbsp;Execution&nbsp;Policies<\/a><\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell Scripts Episodes 0-9 of the Learn PowerShell series covered the fundamentals of PowerShell. Now, in Episode 10, you have the basic elements to begin creating your own PowerShell scripts! A PowerShell script is&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":3222,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[421],"tags":[265],"series":[436],"class_list":["post-3131","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-powershell","series-learn-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PowerShell Scripts - Tech Thoughts<\/title>\n<meta name=\"description\" content=\"Learn how to run PowerShell scripts. Write your first PowerShell script by following along with an example and watch the process in a live script session.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.techthoughts.info\/powershell-scripts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PowerShell Scripts - Tech Thoughts\" \/>\n<meta property=\"og:description\" content=\"Learn how to run PowerShell scripts. Write your first PowerShell script by following along with an example and watch the process in a live script session.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.techthoughts.info\/powershell-scripts\/\" \/>\n<meta property=\"og:site_name\" content=\"Tech Thoughts\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/techthoughts2\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-03T14:13:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-02-03T14:13:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2020\/01\/powershel_scripts.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jake\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JakeMorrison\" \/>\n<meta name=\"twitter:site\" content=\"@JakeMorrison\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jake\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.techthoughts.info\/powershell-scripts\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.techthoughts.info\/powershell-scripts\/\"},\"author\":{\"name\":\"Jake\",\"@id\":\"https:\/\/www.techthoughts.info\/#\/schema\/person\/422a290e8bc3f6a94775f6290c26105d\"},\"headline\":\"PowerShell Scripts\",\"datePublished\":\"2020-02-03T14:13:08+00:00\",\"dateModified\":\"2020-02-03T14:13:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.techthoughts.info\/powershell-scripts\/\"},\"wordCount\":785,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.techthoughts.info\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.techthoughts.info\/powershell-scripts\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2020\/01\/powershel_scripts.jpg\",\"keywords\":[\"PowerShell\"],\"articleSection\":[\"Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.techthoughts.info\/powershell-scripts\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.techthoughts.info\/powershell-scripts\/\",\"url\":\"https:\/\/www.techthoughts.info\/powershell-scripts\/\",\"name\":\"PowerShell Scripts - Tech Thoughts\",\"isPartOf\":{\"@id\":\"https:\/\/www.techthoughts.info\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.techthoughts.info\/powershell-scripts\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.techthoughts.info\/powershell-scripts\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2020\/01\/powershel_scripts.jpg\",\"datePublished\":\"2020-02-03T14:13:08+00:00\",\"dateModified\":\"2020-02-03T14:13:14+00:00\",\"description\":\"Learn how to run PowerShell scripts. Write your first PowerShell script by following along with an example and watch the process in a live script session.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.techthoughts.info\/powershell-scripts\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.techthoughts.info\/powershell-scripts\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.techthoughts.info\/powershell-scripts\/#primaryimage\",\"url\":\"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2020\/01\/powershel_scripts.jpg\",\"contentUrl\":\"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2020\/01\/powershel_scripts.jpg\",\"width\":1280,\"height\":720,\"caption\":\"Learn PowerShell Episode 10 - PowerShell Scripts\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.techthoughts.info\/powershell-scripts\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Tech Thoughts\",\"item\":\"https:\/\/www.techthoughts.info\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PowerShell Scripts\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.techthoughts.info\/#website\",\"url\":\"https:\/\/www.techthoughts.info\/\",\"name\":\"Tech Thoughts\",\"description\":\"A cloud, PowerShell, server, hardware, technology, and more tech thoughts blog\",\"publisher\":{\"@id\":\"https:\/\/www.techthoughts.info\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.techthoughts.info\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.techthoughts.info\/#organization\",\"name\":\"TechThoughts\",\"url\":\"https:\/\/www.techthoughts.info\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.techthoughts.info\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2017\/12\/techthoughts_icon.png\",\"contentUrl\":\"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2017\/12\/techthoughts_icon.png\",\"width\":110,\"height\":109,\"caption\":\"TechThoughts\"},\"image\":{\"@id\":\"https:\/\/www.techthoughts.info\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/techthoughts2\",\"https:\/\/x.com\/JakeMorrison\",\"https:\/\/www.youtube.com\/TechthoughtsInfo2\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.techthoughts.info\/#\/schema\/person\/422a290e8bc3f6a94775f6290c26105d\",\"name\":\"Jake\",\"description\":\"A little about me...\",\"sameAs\":[\"https:\/\/jakewmorrison.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PowerShell Scripts - Tech Thoughts","description":"Learn how to run PowerShell scripts. Write your first PowerShell script by following along with an example and watch the process in a live script session.","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:\/\/www.techthoughts.info\/powershell-scripts\/","og_locale":"en_US","og_type":"article","og_title":"PowerShell Scripts - Tech Thoughts","og_description":"Learn how to run PowerShell scripts. Write your first PowerShell script by following along with an example and watch the process in a live script session.","og_url":"https:\/\/www.techthoughts.info\/powershell-scripts\/","og_site_name":"Tech Thoughts","article_publisher":"https:\/\/www.facebook.com\/techthoughts2","article_published_time":"2020-02-03T14:13:08+00:00","article_modified_time":"2020-02-03T14:13:14+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2020\/01\/powershel_scripts.jpg","type":"image\/jpeg"}],"author":"Jake","twitter_card":"summary_large_image","twitter_creator":"@JakeMorrison","twitter_site":"@JakeMorrison","twitter_misc":{"Written by":"Jake","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.techthoughts.info\/powershell-scripts\/#article","isPartOf":{"@id":"https:\/\/www.techthoughts.info\/powershell-scripts\/"},"author":{"name":"Jake","@id":"https:\/\/www.techthoughts.info\/#\/schema\/person\/422a290e8bc3f6a94775f6290c26105d"},"headline":"PowerShell Scripts","datePublished":"2020-02-03T14:13:08+00:00","dateModified":"2020-02-03T14:13:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.techthoughts.info\/powershell-scripts\/"},"wordCount":785,"commentCount":1,"publisher":{"@id":"https:\/\/www.techthoughts.info\/#organization"},"image":{"@id":"https:\/\/www.techthoughts.info\/powershell-scripts\/#primaryimage"},"thumbnailUrl":"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2020\/01\/powershel_scripts.jpg","keywords":["PowerShell"],"articleSection":["Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.techthoughts.info\/powershell-scripts\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.techthoughts.info\/powershell-scripts\/","url":"https:\/\/www.techthoughts.info\/powershell-scripts\/","name":"PowerShell Scripts - Tech Thoughts","isPartOf":{"@id":"https:\/\/www.techthoughts.info\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.techthoughts.info\/powershell-scripts\/#primaryimage"},"image":{"@id":"https:\/\/www.techthoughts.info\/powershell-scripts\/#primaryimage"},"thumbnailUrl":"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2020\/01\/powershel_scripts.jpg","datePublished":"2020-02-03T14:13:08+00:00","dateModified":"2020-02-03T14:13:14+00:00","description":"Learn how to run PowerShell scripts. Write your first PowerShell script by following along with an example and watch the process in a live script session.","breadcrumb":{"@id":"https:\/\/www.techthoughts.info\/powershell-scripts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.techthoughts.info\/powershell-scripts\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.techthoughts.info\/powershell-scripts\/#primaryimage","url":"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2020\/01\/powershel_scripts.jpg","contentUrl":"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2020\/01\/powershel_scripts.jpg","width":1280,"height":720,"caption":"Learn PowerShell Episode 10 - PowerShell Scripts"},{"@type":"BreadcrumbList","@id":"https:\/\/www.techthoughts.info\/powershell-scripts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Tech Thoughts","item":"https:\/\/www.techthoughts.info\/"},{"@type":"ListItem","position":2,"name":"PowerShell Scripts"}]},{"@type":"WebSite","@id":"https:\/\/www.techthoughts.info\/#website","url":"https:\/\/www.techthoughts.info\/","name":"Tech Thoughts","description":"A cloud, PowerShell, server, hardware, technology, and more tech thoughts blog","publisher":{"@id":"https:\/\/www.techthoughts.info\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.techthoughts.info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.techthoughts.info\/#organization","name":"TechThoughts","url":"https:\/\/www.techthoughts.info\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.techthoughts.info\/#\/schema\/logo\/image\/","url":"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2017\/12\/techthoughts_icon.png","contentUrl":"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2017\/12\/techthoughts_icon.png","width":110,"height":109,"caption":"TechThoughts"},"image":{"@id":"https:\/\/www.techthoughts.info\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/techthoughts2","https:\/\/x.com\/JakeMorrison","https:\/\/www.youtube.com\/TechthoughtsInfo2"]},{"@type":"Person","@id":"https:\/\/www.techthoughts.info\/#\/schema\/person\/422a290e8bc3f6a94775f6290c26105d","name":"Jake","description":"A little about me...","sameAs":["https:\/\/jakewmorrison.com"]}]}},"jetpack_featured_media_url":"https:\/\/www.techthoughts.info\/wp-content\/uploads\/2020\/01\/powershel_scripts.jpg","jetpack_shortlink":"https:\/\/wp.me\/p2EFB0-Ov","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techthoughts.info\/wp-json\/wp\/v2\/posts\/3131"}],"collection":[{"href":"https:\/\/www.techthoughts.info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techthoughts.info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techthoughts.info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techthoughts.info\/wp-json\/wp\/v2\/comments?post=3131"}],"version-history":[{"count":21,"href":"https:\/\/www.techthoughts.info\/wp-json\/wp\/v2\/posts\/3131\/revisions"}],"predecessor-version":[{"id":3237,"href":"https:\/\/www.techthoughts.info\/wp-json\/wp\/v2\/posts\/3131\/revisions\/3237"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techthoughts.info\/wp-json\/wp\/v2\/media\/3222"}],"wp:attachment":[{"href":"https:\/\/www.techthoughts.info\/wp-json\/wp\/v2\/media?parent=3131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techthoughts.info\/wp-json\/wp\/v2\/categories?post=3131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techthoughts.info\/wp-json\/wp\/v2\/tags?post=3131"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.techthoughts.info\/wp-json\/wp\/v2\/series?post=3131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}