{"id":1315,"date":"2014-05-20T00:01:00","date_gmt":"2014-05-20T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/05\/20\/whats-in-your-powershell-profile-here-are-some-users-favorites\/"},"modified":"2014-05-20T00:01:00","modified_gmt":"2014-05-20T00:01:00","slug":"whats-in-your-powershell-profile-here-are-some-users-favorites","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/whats-in-your-powershell-profile-here-are-some-users-favorites\/","title":{"rendered":"What&#039;s in Your PowerShell Profile? Here Are Some User&#039;s Favorites"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, talks to various Windows PowerShell users about what is in their profiles.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. I have had this idea floating in my head, and I decided to reach out to some fellow Windows PowerShell experts and enthusiasts in regards to &ldquo;What is in your profile?&rdquo; I asked each person to share a portion of their profile with you, our readers. Today I will be sharing ideas from internal Microsoft employees.<\/p>\n<p><span style=\"font-size:large\"><b>Alex Lee<\/b><\/span> shared three functions. The functions are called <b>Parse-Script<\/b>, <b>Find-String<\/b>, and <b>Count-Lines<\/b>.&nbsp;Here is what he has to say about these functions:<\/p>\n<p>&quot;I use these three functions when I am working on projects that involve packaging scripts for some kind of delivery and\/or sharing scripts with and from others&mdash;mostly only when I have a folder full of files.&quot;<\/p>\n<ul>\n<li><b>Parse-Script<\/b>. I borrowed this function from Windows PowerShell MVP, Keith Hill.&nbsp;<\/li>\n<li><b>Find-String<\/b>. I don&rsquo;t actually remember why I wrote this function.&nbsp;I think I wanted to use the command prompt to find files that need to change (for example, changing variable names or paths). And I think I had XML files that FINDSTR.EXE didn&rsquo;t like.<\/li>\n<li><b>Count-Lines<\/b>. This is simply a way to quantify the size of a package.&nbsp;It ignores empty lines and comments.<\/li>\n<\/ul>\n<p><span style=\"font-size:large\"><b>Dan Bjorge<\/b> <\/span>shared two functions. The first one is a <b>Format-History<\/b> function that accepts a history entry as input and will display the amount of time a job in the history ran. The second function is a customized Windows PowerShell prompt.<\/p>\n<p><b>Format-History function<\/b><\/p>\n<p style=\"margin-left:30px\">function Format-History($HistoryEntry) {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; if ($HistoryEntry -ne $null) {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Duration = $HistoryEntry.EndExecutionTime &#8211; $HistoryEntry.StartExecutionTime<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($Duration.Days -ge 1) {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $DurationString = [String]::Format(&quot;{0:0}d{1:00}h{2:00}m{3:00}s&quot;, $Duration.Days,$Duration.Hours,$Duration.Minutes,$Duration.Seconds)<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } elseif($Duration.Hours -ge 1) {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $DurationString = [String]::Format(&quot;{0:0}h{1:00}m{2:00}s&quot;, $Duration.Hours,$Duration.Minutes,$Duration.Seconds)<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } elseif($Duration.Minutes -ge 1) {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $DurationString = [String]::Format(&quot;{0:0}m{1:00}.{2:000}s&quot;, $Duration.Minutes,$Duration.Seconds,$Duration.Milliseconds)<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $DurationString = [String]::Format(&quot;{0:0}.{1:000}s&quot;, $Duration.Seconds,$Duration.Milliseconds)<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &quot;[$DurationString] $($HistoryEntry.CommandLine)&quot;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; } else {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &quot;&quot;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p><b>Customized Windows PowerShell prompt<\/b><\/p>\n<p style=\"margin-left:30px\">function global:Prompt {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; $Location = (Get-Location).Path<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; $LastCommand = Get-History -Count 1<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; $LastCommandStr = Format-History $LastCommand<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; $WindowTitle = &quot;$Location | $LastCommandStr&quot;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; $TabTitle = $Location<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; if (Test-Elevated) {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Host &quot;ADMIN &quot; -NoNewline -ForegroundColor Red<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $WindowTitle = &quot;[ADMIN] $WindowTitle&quot;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;Write-Host &quot;$Location&quot; -NoNewline<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; if ($LastCommand -ne $null) {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Host &quot; $($LastCommand.Id+1)&quot; -NoNewline -ForegroundColor Green<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; } else {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Host &quot; 1&quot; -NoNewline -ForegroundColor Green<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; }<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; if ($PsIse -ne $null) {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $PsIse.CurrentPowerShellTab.DisplayName = $TabTitle<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; } else {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Host.UI.RawUI.WindowTitle = $WindowTitle<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; }<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; return &#039;&gt; &#039;<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p>One cool thing that the custom prompt function does is display the admin status in red. This is shown in the following image:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-5-20-14-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-5-20-14-1.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p><span style=\"font-size:large\"><b>Dan Thompson<\/b><\/span> shared several functions that look pretty cool. One thing he does is turn on <b>StrictM<\/b><strong>ode<\/strong>. It is almost the first line in his Windows PowerShell profile. He then creates a <b>Resolve-Error<\/b> function that provides useful error messages when there is a problem. He has a <b>pushd<\/b> function that looks rather intriguing. He also has a <b>Find-InSource<\/b> function, and a <b>Set-WindowTitle<\/b> function.<\/p>\n<p>I like that Dan creates useful aliases for his functions. This makes working in the Windows PowerShell shell much easier. Here are Dan&#039;s functions:<\/p>\n<p><b>Set-StrictMode and Resolve-Error functions<\/b><\/p>\n<p style=\"margin-left:30px\">Set-StrictMode -Version Latest<\/p>\n<p style=\"margin-left:30px\">function Resolve-Error<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; [CmdletBinding()]<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; param( [Parameter( Mandatory = $false, Position = 0, ValueFromPipeline = $true )]<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [System.Management.Automation.ErrorRecord] $ErrorRecord )<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; process<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( !$ErrorRecord )<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( 0 -eq $global:Error.Count )<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ErrorRecord = $global:Error[ 0 ]<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $global:e = $ErrorRecord<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ErrorRecord | Format-List * -Force<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ErrorRecord.InvocationInfo | Format-List *<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Exception = $ErrorRecord.Exception<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for( $i = 0; $Exception; $i++, ($Exception = $Exception.InnerException) )<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; &quot;$i&quot; * 80<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Exception | Format-List * -Force<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; finally { }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p style=\"margin-left:30px\">Set-Alias rver Resolve-Error<\/p>\n<p><b>Pushd function<\/b><\/p>\n<p style=\"margin-left:30px\">function .. { pushd .. }<\/p>\n<p style=\"margin-left:30px\">function &#8230; { pushd ..\\.. }<\/p>\n<p style=\"margin-left:30px\">function &#8230;. { pushd ..\\..\\.. }<\/p>\n<p style=\"margin-left:30px\">function &#8230;.. { pushd ..\\..\\..\\.. }<\/p>\n<p style=\"margin-left:30px\">function &#8230;&#8230; { pushd ..\\..\\..\\..\\.. }<\/p>\n<p style=\"margin-left:30px\">function &#8230;&#8230;. { pushd ..\\..\\..\\..\\..\\.. }<\/p>\n<p style=\"margin-left:30px\">function &#8230;&#8230;.. { pushd ..\\..\\..\\..\\..\\..\\.. }<\/p>\n<p style=\"margin-left:30px\">Set-Alias go Push-Location<\/p>\n<p style=\"margin-left:30px\">Set-Alias back Pop-Location<\/p>\n<p style=\"margin-left:30px\">Set-Alias l Get-ChildItem<\/p>\n<p style=\"margin-left:30px\">function q { exit }<\/p>\n<p><b>Find-InSource function<\/b><\/p>\n<p style=\"margin-left:30px\">function Find-InSource<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; findstr \/spinc:&quot;$args&quot; *.c *.cs *.cxx *.cpp *.h *.hxx *.hpp *.idl *.wxs *.wix *.wxi *.ps1 *.psm1 *.psd1<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p style=\"margin-left:30px\">Set-Alias fs Find-InSource<\/p>\n<p style=\"margin-left:30px\">Set-WindowTitle function<\/p>\n<p style=\"margin-left:30px\">function Set-WindowTitle()<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; $host.ui.RawUI.WindowTitle = [String]::Join( &#039; &#039;, $args )<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p style=\"margin-left:30px\">Set-Alias &#039;title&#039; &#039;Set-WindowTitle&#039; -Scope Global<\/p>\n<p><span style=\"font-size:large\"><b>Dave Bishop<\/b><\/span> shared the following:<\/p>\n<p>&quot;I customize my prompt in (what I think) is a clever and useful way.&nbsp;I also load a few useful modules and tools. The big thing for me is that I created a folder on my OneDrive, and I store everything there:&nbsp;&nbsp;C:\\users\\davbish\\OneDrive\\WindowsPowerShell. I then hard link to my profile folder with junction.exe (SysInternals tool) as follows.&quot;<\/p>\n<p style=\"margin-left:30px\">Junction c:\\users\\davbish\\documents\\windowspowershell c:\\users\\davbish\\onedrive\\windowspowershell<\/p>\n<p>&quot;I do this on all of my computers so my profile scripts (and more importantly, any edits) and certain modules follow me everywhere!&quot;<\/p>\n<p>Dave also customizes his prompt function, as shown here:<\/p>\n<p style=\"margin-left:30px\">function Prompt<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $id=1<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $historyItem=get-history -count 1<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if($historyitem)<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $id=$historyItem.id+1<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-host -foregroundcolor darkgray &quot;`n[$(get-location)]&quot;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-host -foregroundcolor yellow -nonewline &quot;PS:$id &gt; &quot;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;`b&quot;<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p>Dave also creates an alias for Internet Explorer as follows:<\/p>\n<p style=\"margin-left:30px\">set-alias iexplore &#039;c:\\program files\\internet explorer\\iexplore.exe&#039;<\/p>\n<p><b><span style=\"font-size:large\">Heath Stewart<\/span> <\/b>shared the following:<\/p>\n<p>&quot;I added another cmdlet that I use often (although, I just finally added it to my $profile&mdash;not sure why it took me so long to do it), and you might find it useful. The idea is that sometimes you get repetitive row data like the one that follows.&quot;<\/p>\n<p style=\"margin-left:30px\">Key, Property, Value<\/p>\n<p style=\"margin-left:30px\">&#8212;, &#8212;&#8212;&#8211;, &#8212;&#8211;<\/p>\n<p style=\"margin-left:30px\">Foo, Name, Foo<\/p>\n<p style=\"margin-left:30px\">Foo, Language, 1033<\/p>\n<p style=\"margin-left:30px\">Foo, Id, {GUID1}<\/p>\n<p style=\"margin-left:30px\">Bar, Name, Bar<\/p>\n<p style=\"margin-left:30px\">Bar, Language, 1031<\/p>\n<p style=\"margin-left:30px\">Bar, Id, {GUID2}<\/p>\n<p style=\"margin-left:30px\">Bar, Other, Other<\/p>\n<p>&quot;This happens a lot when processing metadata records that are user-definable. To create objects with the metadata properties as actual properties of a PSObject, you can use <b>Join-Object<\/b> as follows (<b>Property<\/b> and <b>Value<\/b> are defaults for the second and third parameters).&quot; This is shown here:<\/p>\n<p style=\"margin-left:30px\">Import-Csv foo.csv | Join-Object Key<\/p>\n<p>You can download the function from GitHub: <a href=\"https:\/\/github.com\/heaths\/profile\/blob\/master\/Modules\/My\/My.psm1\" target=\"_blank\">Join-Object cmdlet<\/a>.<\/p>\n<p><span style=\"font-size:large\"><b>Jason Chenault<\/b><\/span> provided the following:<\/p>\n<p>&quot;I found this function useful when I was supporting Exchange Server&nbsp;2010. I used it whenever I needed a quick report about disconnected mailboxes or simply to clean the databases.&quot;<\/p>\n<p style=\"margin-left:30px\">function Get-DisconnectedMailbox {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param(<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [String]$Name = &#039;*&#039;,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [String]$Server = &#039;*&#039;,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Switch]$Clean,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Switch]$Archive<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($Clean) {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-MailboxDatabase | Clean-MailboxDatabase<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $databases = Get-MailboxDatabase | ?{$_.Name -like $Server}<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $databases | %{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $db = Get-Mailboxstatistics -database $_.Name |<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ?{$_.DisconnectDate -and $_.IsArchiveMailbox -eq $Archive}<\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $db | ?{$_.displayname -like $Name} |<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select-Object DisplayName,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MailboxGuid,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Database,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DisconnectReason,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ItemCount,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; disconnectDate | Out-file -append DiscMBReport.txt<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p>Thank-you all for sharing portions of your profiles. I think it is cool to see what people add into their Windows PowerShell profile. It is interesting that several of the people I highlighted today customized their Windows PowerShell prompt, and several wrote search\/find functions. I like Dave Bishop&#039;s idea about storing stuff on OneDrive so it follows him around. I really love the <b>Join-Object<\/b> function from Heath.&nbsp;<\/p>\n<p>Join me tomorrow when we will look into more profiles. It will be way cool, just wait and see. So let me ask you, &ldquo;What&rsquo;s in your profile?&rdquo; Post a comment and let us know.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks to various Windows PowerShell users about what is in their profiles. Microsoft Scripting Guy, Ed Wilson, is here. I have had this idea floating in my head, and I decided to reach out to some fellow Windows PowerShell experts and enthusiasts in regards to &ldquo;What is in your [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[144,3,4,45],"class_list":["post-1315","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-profiles","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks to various Windows PowerShell users about what is in their profiles. Microsoft Scripting Guy, Ed Wilson, is here. I have had this idea floating in my head, and I decided to reach out to some fellow Windows PowerShell experts and enthusiasts in regards to &ldquo;What is in your [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=1315"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1315\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=1315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}