{"id":6178,"date":"2019-02-27T11:30:00","date_gmt":"2019-02-27T16:30:00","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?page_id=6178"},"modified":"2021-04-01T12:40:27","modified_gmt":"2021-04-01T16:40:27","slug":"powershell-tips-tricks-and-advice","status":"publish","type":"page","link":"https:\/\/jdhitsolutions.com\/blog\/powershell-tips-tricks-and-advice\/","title":{"rendered":"PowerShell Tips &#038; Tricks"},"content":{"rendered":"\n<div class=\"wp-block-image is-style-default\"><figure class=\"alignleft\"><img loading=\"lazy\" decoding=\"async\" width=\"194\" height=\"300\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/07\/powershell-hero-194x300.jpg\" alt=\"PowerShell Hero\" class=\"wp-image-6022\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/07\/powershell-hero-194x300.jpg 194w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/07\/powershell-hero.jpg 439w\" sizes=\"auto, (max-width: 194px) 100vw, 194px\" \/><\/figure><\/div>\n\n\n\n<p>This page is my one-stop-shop for all sorts of PowerShell-related, tips, tricks, hacks, suggestions, and other bits of wisdom I've gleaned over the last 15 years. These are not intended to carry biblical weight, but many are now part of accepted PowerShell community standards. I encourage you to try things out for yourself and see if they make sense to you. Feel free to ping me on <a href=\"https:\/\/twitter.com\/jeffhicks\" target=\"_blank\" rel=\"noopener noreferrer\">Twitter<\/a> if you have questions or comments about anything on this page.<\/p>\n\n\n\n<p>This page is divided into sections. <a href=\"#pstweet\">PowerShell Tweet Tips<\/a> is a collection of short tips I occasionally post on my social media channels. The <a href=\"#psscript\">PowerShell Scripting and Toolmaking<\/a> section contains a list of recommendations and advice. Many of these come from my classes and conference presentations.&nbsp; Most of these suggestions are targeted at PowerShell beginners. As your PowerShell experience grows you may find the need to bend some of the suggestions.<\/p>\n\n\n\n<p>Finally, <a href=\"#oneliner\">PowerShell One-Liners<\/a> is a collection of what I hope are useful one-line PowerShell commands. These are the types of expressions that are often the seeds of functions and scripts. They can also demonstrate PowerShell concepts and techniques.&nbsp; You can find additional code snippets at <a href=\"https:\/\/gist.github.com\/jdhitsolutions\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/gist.github.com\/jdhitsolutions<\/a>.<\/p>\n\n\n\n<p>I intend to update this page periodically so I hope you will bookmark this and check back frequently. I will try to mention something on Twitter when I make major changes to the content.<\/p>\n\n\n\n<p>If you are new to PowerShell, I encourage you to also take a look at my<a href=\"https:\/\/jdhitsolutions.com\/blog\/essential-powershell-resources\/\" target=\"_blank\" rel=\"noopener noreferrer\"> PowerShell Essentials<\/a> page.<br><a name=\"pstweet\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PowerShell Tweet Tips<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><em>If you can't run PowerShell effectively in the console, you'll never be able to write an effective script.<\/em><\/li><li><em>Always be testing the latest version of PowerShell. It will eventually be a part of your day-to-day work.<\/em><\/li><li>The PowerShell ISE and VS Code are for <em>development<\/em>. Run commands and scripts you need for your job in a PowerShell console.<\/li><li><em>Using PowerShell interactively at the console to do your job and writing PowerShell scripts and tools are separate tasks each with its own set of best practices and recommendations.<\/em><\/li><li><em>Take advantage of <strong>Tee-Object<\/strong>. This will allow you to see the results of your command and save them to a variable: <strong>get-process | tee -Variable p<\/strong><\/em><\/li><li><em>Consider <strong>Get-WmiObject<\/strong> deprecated. Learn to use the CIM cmdlets like <strong>Get-CimInstance<\/strong>.<\/em><\/li><li><em>Run <strong>Update-Help<\/strong> once a month. Better yet, learn how to set it up as a scheduled job in Windows PowerShell.<\/em><\/li><li><em>Use <strong>Invoke-Item<\/strong> or its alias<strong> ii,<\/strong> to open a folder in Windows Explorer: <strong>ii c:\\windows<\/strong><\/em><\/li><li><em>Expose yourself to PowerShell every day. Even if you do nothing but closely read full help and examples for a few cmdlets or an about topic.<\/em><\/li><li><em>Those who fail to automate are doomed to repeat their work.<\/em><\/li><li><em>Don't forget to look through the PowerShell about topics for help<\/em>.<\/li><li><em>If you don't do <strong>something<\/strong> with PowerShell every day, you'll never really learn it.<\/em><\/li><li><em>Enabling PowerShell Remoting is the easy first step. You still need to do your job and properly <strong>secure<\/strong> it.<\/em><\/li><li><em>View the content of any loaded function: <strong>(get-item function:prompt).scriptblock<\/strong> Or <strong>get-content function:prompt<\/strong><\/em><\/li><li><em>The forums at PowerShell.org are your best option for accurate and timely help and answers.<\/em><\/li><li><em>Open the current directory in VSCode. Great when working on a PowerShell module: <strong>code .<\/strong><\/em><\/li><li><em>Get in the habit of using -full when looking at cmdlet help. You could even add a PSDefaultParameterValue.<\/em><\/li><li><em>Take advantage of the <strong>Is*<\/strong> variables in your PowerShell scripts like<\/em> <strong>$IsLinux<\/strong> <em>and<\/em> <strong>$IsWindows<\/strong>.<\/li><li><em>Is your expression not working the way you expect? Learn how to use <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=821866\" target=\"_blank\" rel=\"noopener noreferrer\">Trace-Command<\/a>.<\/em><\/li><li><em>Do you miss being able to run the PowerShell ISE from a prompt in PowerShell 7 on a Windows platform? All you need to do is define the missing alias in your PowerShell Core profile script:<\/em> <em><strong>Set-Alias -name ise -value powershell_ise.exe<\/strong><\/em><\/li><li><em>Are you stuck using the PowerShell ISE but want to code with PowerShell 7? Start a remoting session in the ISE. The ISE will then detect and use PowerShell 7 for Intellisense :<\/em> <strong>Enter-PSSession -ComputerName localhost -ConfigurationName powershell.7<\/strong><\/li><li>Having trouble installing for finding things from the PowerShell Gallery or GitHub? Add this line to your PowerShell profile script:  <strong>[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12<\/strong><\/li><li><em>Once you understand the object-nature of PowerShell, you can do a lot with object notation. This is a one-line command using the gcim alias of Get-CimInstance:<br><\/em><strong><em>(gcim win32_operatingsystem).LastBootUpTime.Date.DayofWeek<\/em><\/strong><\/li><\/ul>\n\n\n\n<p><a name=\"psscript\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PowerShell Scripting and ToolMaking<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Know who will use the tool and how they will use it. What will be their expectation?<\/li><li>Write one type of object to the pipeline.<\/li><li>Use full cmdlet and parameter names in your scripts. No aliases.<\/li><li>Be flexible and modular. Always think about re-use.<\/li><li>Don't hard code yourself into a corner. Aim for flexibility.<\/li><li>Documentation is critical and not just internal comments.<\/li><li>Use the <strong>Verb-Noun<\/strong> naming convention for your function and commonly accepted parameter names. Don't re-invent the wheel.<\/li><li>Use meaningful variable names that don't use Hungarian notation. <em>$strComputername<\/em> is bad. <em>$Computername<\/em> is good.<\/li><li>Standardize script layout with templates and snippets. Especially important in team environments.<\/li><li>White space and formatting is your friend. VSCode can format your scripts for you. Use it.<\/li><li>Write your code for the next person. It could be you.<\/li><li>Include <strong>Write-Verbose<\/strong> messages from the beginning. They will help you develop your code.<\/li><li>Learn how to use <strong>Write-Progress<\/strong> in place of <strong>Write-Host<\/strong> to provide execution details.<\/li><li>Avoid using the value <em>localhost<\/em> as a default parameter value. Use <em>$env:computername<\/em> which will always resolve to a \"real\" name. If you need to script cross-platform you can use <em>[environment]::machinename<\/em>.<\/li><li>Just <strong>because<\/strong> you can use a long, one-line pipelined expression <strong>doesn't mean you should<\/strong>.<\/li><li>Separate the data you need to run your code from the code itself.<\/li><li>Avoid using .NET code when a cmdlet will work.<\/li><li>Recognize that sometimes PowerShell is <strong>not<\/strong> the right solution or tool for the task at hand.<\/li><li>Test your code in a PowerShell session with no profile. Even better, test in a virtual machine of the Windows Sandbox to avoid unintended dependencies.<\/li><li>Understand the PowerShell paradigm. Don't write a VBScript using PowerShell commands and think you're done.<\/li><li>If you are creating a graphical PowerShell tool, start with a console-based script or function that already works.<\/li><li>Your first step in creating a new script or function is to read help and examples. <strong>Not<\/strong> Google or Bing.<\/li><li>Leverage splatting to simplify your code.<\/li><li>Think about how your code will scale. Don't write a function that only works with one remote computer. How would you write it to work with 10 or 100 or 1000? Think \"managing at scale\".<\/li><li>If you need credentials in your script or function use a PSCredential type parameter. Never a username and plain text password.<\/li><li>Learn how to use the <a href=\"https:\/\/github.com\/PowerShell\/platyPS\" target=\"_blank\" rel=\"noopener noreferrer\">Platyps <\/a>module to create help documentation for commands in your PowerShell module.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">PowerShell One-Liners<\/h2>\n\n\n\n<p>These one-line commands are intended to be used in a PowerShell session. They are written so that you can get maximum benefit, often with minimum typing and without having to write a script. Because these are intended for use at the command prompt aliases are allowed and encouraged. I'll assume you can figure out the alias if you don't recognize it.<\/p>\n\n\n\n<p>As written, many of them should not be copied and pasted into a script without reworking. Note that some of these expressions will work on Windows PowerShell and PowerShell 7 or require a Windows platform. You'll have to try them out for yourself and adjust as necessary. You'll need to add things like parameters and error handling. It may also be easier to break some of these into several steps when used in a script.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Get the scriptblock content of a loaded function. Substitute the name of a function.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">(get-item Function:\\prompt).scriptblock<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Copy a function to a remote computer using a PSSession.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">$f = $(get-item function:\\Get-Foo).scriptblock\nInvoke-Command { New-Item -Name Get-Foo -Path Function: -Value $($using:f)} -session $s<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get running scheduled tasks on a Windows system.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">(get-scheduledtask).where({$_.state -eq 'running'})<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get system uptime from multiple computers where $computers is an array of computer names running PowerShell v3 or later.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">Get-CimInstance Win32_operatingsystem -ComputerName $computers |\nSelect-Object PSComputername,LastBootUpTime,\n@{Name=\"Uptime\";Expression = {(Get-Date) - $_.LastBootUptime}}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Another way to get drive utilization using PSDrives.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">Get-PSDrive -PSProvider filesystem | where-object {$_.used -gt 0} |\nselect-Object -property Root,@{name=\"SizeGB\";expression={($_.used+$_.free)\/1GB -as [int]}},\n@{name=\"UsedGB\";expression={($_.used\/1GB) -as [int]}},\n@{name=\"FreeGB\";expression={($_.free\/1GB) -as [int]}},\n@{name=\"PctFree\";expression={[math]::round(($_.free\/($_.used+$_.free))*100,2)}}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>List installed applications and a few details. But use with caution. It is slow, not necessarily complete, and could have unexpected consequences. Here's a good <a href=\"https:\/\/xkln.net\/blog\/please-stop-using-win32product-to-find-installed-software-alternatives-inside\/\" target=\"_blank\" rel=\"noreferrer noopener\">link <\/a>about using this class and alternatives.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">gcim win32_product -computername $env:computername | \nSort-Object -property Vendor,Name | Select-Object -property Vendor,Name,\n@{Name=\"Installed\";Expression = {($_.InstallDate.Insert(4,\"-\").insert(7,\"-\") -as [datetime]).ToShortDateString()}},\nInstallLocation,InstallSource,PackageName,Version<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get details about all external scripts in your %PATH%.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">gcm -commandtype externalscript | Get-Item | \nSelect-Object Directory,Name,Length,CreationTime,LastwriteTime,\n@{name=\"Signature\";Expression={(Get-AuthenticodeSignature $_.fullname).Status }}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get folder utilization for a given directory.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">dir -path C:\\Scripts -file -recurse -force | \nmeasure-object length -sum -max -average | \nSelect-Object @{name=\"Total Files\";Expression={$_.count}},\n@{name=\"Largest File(MB)\";Expression={\"{0:F2}\" -f ($_.maximum\/1MB)}},\n@{name=\"Average Size(MB)\";Expression={\"{0:F2}\" -f ($_.average\/1MB)}},\n@{name=\"Total Size(MB)\";Expression={\"{0:F2}\" -f ($_.sum\/1MB)}}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get event log utilization for remote computers defined in $computers. The remote computers must be running PowerShell v3 or later.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">gcim Win32_NTEventLogFile -computer $computers -filter  \"NumberOfRecords &gt; 0\" | \nSelect-Object @{Name=\"Computername\";Expression={$_.CSName}},\nLogFileName,\nNumberOfRecords,\n@{Name=\"Size(KB)\";Expression={$_.FileSize\/1kb}},\n@{Name=\"MaxSize(KB)\";Expression={($_.MaxFileSize\/1KB) -as [int]}}, \n@{name=\"PercentUsed\";Expression={[math]::round(($_.filesize\/$_.maxFileSize)*100,2)}} |  \nSort Computername,PercentUsed  | \nFormat-Table -GroupBy Computername -property LogFileName,NumberOfRecords,*Size*,PercentUsed<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get free space for drive C on the local computer formatted in GB<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">(gcim win32_logicaldisk -filter \"deviceid = 'C:'\").FreeSpace\/1gb\n#or use the PSDrive\n(gdr c).Free\/1gb<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get a date string in the format year-month-day-hour-min-second. The abbreviations in the format string are case-sensitive.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">get-date -format yyyyMMddhhmmss<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get the last time your computer booted. Can be modified to query remote computers.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">(gcim win32_operatingsystem).LastBootUpTime\n#or modify to get uptime\n(get-date) - ((gcim win32_operatingsystem).LastBootUpTime)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get configured TrustedHosts.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps decode:true\"><code lang=\"powershell\" class=\"language-powershell\">(get-wsmaninstance wsman\/config\/client).trustedhosts<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get all drives identified by a standard drive letter. I'm suppressing errors to ignore non-existent drive letters.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps decode:true\"><code lang=\"powershell\" class=\"language-powershell\">get-volume -driveletter (97..122) -ErrorAction SilentlyContinue<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get total physical memory formatted as GB.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps decode:true\"><code lang=\"powershell\" class=\"language-powershell\">gcim win32_computersystem -computer SRV1,SRV2 | Select PSComputername,@{Name=\"Memory\";Expression={$_.TotalPhysicalMemory\/1GB -as [int]}}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get IPv4 addresses on your local adapters.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps decode:true\"><code lang=\"powershell\" class=\"language-powershell\">Get-NetIPAddress -AddressFamily IPv4 | where-object IPAddress -notmatch \"^(169)|(127)\" | Sort-Object IPAddress | select IPaddress,Interface*<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Find all processes that use a given module (dll). You can filter by the dll name or use part of a path.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps decode:true\"><code lang=\"powershell\" class=\"language-powershell\">get-process | Where { $_.Modules.filename -match \"netapi32.dll\"}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Since PowerShell Core and PowerShell 7 do not include the Get-Eventlog cmdlet, here's a one-liner to list the last 10 errors in the System event log. A level value of 3 will give you warnings.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">get-winevent -FilterHashtable @{Logname = 'System';Level=2} -MaxEvents 10 | sort-Object ProviderName,TimeCreated<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>List all PowerShell profile script settings. You will see different values for different hosts, such as the PowerShell ISE, as well as between Windows PowerShell and PowerShell 7.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">$profile | select *host* | format-list<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Show what PowerShell profile scripts exist.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">$profile.psobject.properties).where({$_.name -ne 'length'}).where({Test-Path $_.value }) | Select-Object Name,Value<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get the current date and time formatted as UTC time.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">(get-date).ToUniversalTime()\n#or pretty it up\n\"$((get-date).ToUniversalTime()) UTC\"\n\"$((Get-Date).ToUniversalTime().tolongdatestring()) UTC\"<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Get a formatted report of all commands with a synopsis.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">(Get-Command).where({ $_.source }) | Sort-Object Source, CommandType, Name | Format-Table -GroupBy Source -Property CommandType, Name, @{Name = \"Synopsis\"; Expression = {(Get-Help $_.name).Synopsis}}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>How long has your PowerShell session been running?<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">(Get-Date) - (get-process -id $pid).starttime<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><i>Last updated 2021-04-01 16:40:11Z<br><\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page is my one-stop-shop for all sorts of PowerShell-related, tips, tricks, hacks, suggestions, and other bits of wisdom I&#8217;ve gleaned over the last 15 years. These are not intended to carry biblical weight, but many are now part of accepted PowerShell community standards. I encourage you to try things out for yourself and see&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"class_list":["post-6178","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PowerShell Tips &amp; Tricks &#8226; Jeffery Hicks<\/title>\n<meta name=\"description\" content=\"A collection of PowerShell tips, tricks, advice and one-line commands. Includes material for both Windows PowerShell and PowerShell Core.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell-tips-tricks-and-advice\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PowerShell Tips &amp; Tricks &#8226; Jeffery Hicks\" \/>\n<meta property=\"og:description\" content=\"A collection of PowerShell tips, tricks, advice and one-line commands. Includes material for both Windows PowerShell and PowerShell Core.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell-tips-tricks-and-advice\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:modified_time\" content=\"2021-04-01T16:40:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/07\/powershell-hero-194x300.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-tips-tricks-and-advice\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-tips-tricks-and-advice\\\/\",\"name\":\"PowerShell Tips & Tricks &#8226; Jeffery Hicks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-tips-tricks-and-advice\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-tips-tricks-and-advice\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/powershell-hero-194x300.jpg\",\"datePublished\":\"2019-02-27T16:30:00+00:00\",\"dateModified\":\"2021-04-01T16:40:27+00:00\",\"description\":\"A collection of PowerShell tips, tricks, advice and one-line commands. Includes material for both Windows PowerShell and PowerShell Core.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-tips-tricks-and-advice\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-tips-tricks-and-advice\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/powershell-hero.jpg\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/powershell-hero.jpg\",\"width\":439,\"height\":678},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PowerShell Tips & Tricks &#8226; Jeffery Hicks","description":"A collection of PowerShell tips, tricks, advice and one-line commands. Includes material for both Windows PowerShell and PowerShell Core.","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:\/\/jdhitsolutions.com\/blog\/powershell-tips-tricks-and-advice\/","og_locale":"en_US","og_type":"article","og_title":"PowerShell Tips & Tricks &#8226; Jeffery Hicks","og_description":"A collection of PowerShell tips, tricks, advice and one-line commands. Includes material for both Windows PowerShell and PowerShell Core.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell-tips-tricks-and-advice\/","og_site_name":"The Lonely Administrator","article_modified_time":"2021-04-01T16:40:27+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/07\/powershell-hero-194x300.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_site":"@JeffHicks","twitter_misc":{"Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-tips-tricks-and-advice\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell-tips-tricks-and-advice\/","name":"PowerShell Tips & Tricks &#8226; Jeffery Hicks","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-tips-tricks-and-advice\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-tips-tricks-and-advice\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/07\/powershell-hero-194x300.jpg","datePublished":"2019-02-27T16:30:00+00:00","dateModified":"2021-04-01T16:40:27+00:00","description":"A collection of PowerShell tips, tricks, advice and one-line commands. Includes material for both Windows PowerShell and PowerShell Core.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell-tips-tricks-and-advice\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-tips-tricks-and-advice\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/07\/powershell-hero.jpg","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/07\/powershell-hero.jpg","width":439,"height":678},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":3636,"url":"https:\/\/jdhitsolutions.com\/blog\/essential-powershell-resources\/","url_meta":{"origin":6178,"position":0},"title":"Essential PowerShell Learning Resources","author":"Jeffery Hicks","date":"November 26, 2018","format":false,"excerpt":"When I speak at conferences or during a training class, I inevitably give attendees and students a list of resources that I feel can help them continue to learn and master Windows PowerShell. I'm assuming other beginners who haven't been to one of my conference sessions or training classes would\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/07\/powershell-hero.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":166,"url":"https:\/\/jdhitsolutions.com\/blog\/books-and-training\/","url_meta":{"origin":6178,"position":1},"title":"Books &#038; Training","author":"Jeffery Hicks","date":"October 18, 2015","format":false,"excerpt":"Here is information about my books and training projects. I appreciate your support when purchasing copies. It helps pay the mortgage and allows me to continue what I'm doing. I always appreciate user reviews on appropriate sites like Amazon, as well as word of mouth recommendations. If I'm speaking at\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/psregex.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/psregex.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/psregex.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2514,"url":"https:\/\/jdhitsolutions.com\/blog\/about-me\/","url_meta":{"origin":6178,"position":2},"title":"About Me","author":"Jeffery Hicks","date":"October 24, 2012","format":false,"excerpt":"I am a long-time Microsoft professional, a multi-year Microsoft MVP in Windows PowerShell (now Cloud and DataCenter Management), and an IT veteran with almost 30 years of experience, much of it spent as an IT consultant specializing in Windows server technologies. I work today as an independent author, teacher, and\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/10\/JeffHicks_2017-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/pages\/6178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=6178"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/pages\/6178\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=6178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}