{"id":4721,"date":"2009-01-10T19:59:00","date_gmt":"2009-01-10T19:59:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2009\/01\/10\/test-pscmdlet\/"},"modified":"2019-02-18T13:12:55","modified_gmt":"2019-02-18T20:12:55","slug":"test-pscmdlet","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/test-pscmdlet\/","title":{"rendered":"Test-PSCmdlet"},"content":{"rendered":"<p>Everyone needs to get good with Advanced Functions \u2013 this is the easiest path to the best semantics for everyone.&nbsp; In previous posts we\u2019ve shown how you can add a few simple attributes and get a TON of stuff for free.&nbsp; There is a LOT more to advanced functions.&nbsp; You can go VERY VERY far with advanced functions.&nbsp; I can\u2019t think of anything you can do in C# Cmdlet that you can\u2019t do with a PowerShell cmdlet.&nbsp; Many of these functions are made available to you via the $PsCmdlet variable.<\/p>\n<p>For example, if&nbsp; you write a Cmdlet which takes multiple ParameterSets, you need to know which ParameterSet the user selected.&nbsp; The way you get at that is:<\/p>\n<p>$PsCmdlet.ParameterSetName<\/p>\n<p>Now there is a TON of good stuff in $PSCmdlet and it is not yet well documented so the question is \u2013 how do you use it.&nbsp; You ALREADY know the answer of course \u2013 <\/p>\n<p><strong>Use PowerShell to explore and figure it out yourself (and then blog it so others can learn)<\/strong><\/p>\n<p>I was doing a bunch of scripting today and couldn\u2019t remember how to use $PsCmdlet to do something so I decided to write myself a function that allowed me to Test PsCmdlet.&nbsp; I\u2019m sharing it with you here so you can use\/enjoy it (remember \u2013 explore, learn, blog\/share).<\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\">function Test-PsCmdlet <br \/>{ <br \/><font color=\"#008000\">&lt;# <br \/>.Synopsis <br \/>&nbsp;&nbsp;&nbsp; Test\/Explore the $PsCmdlet variable <br \/>.Description <br \/>&nbsp;&nbsp;&nbsp; This command creates a nested prompt with $PsCmdlet set so that you explore <br \/>&nbsp;&nbsp;&nbsp; the capabilities of the parameter. <br \/>&nbsp;&nbsp;&nbsp; When you write an advanced function, you use $PsCmdlet to give you access to the <br \/>&nbsp;&nbsp;&nbsp; PowerShell engine and a rich set of functions.&nbsp; Use this function to explore what <br \/>&nbsp;&nbsp;&nbsp; is available to you.&nbsp; <br \/>&nbsp;&nbsp;&nbsp; This command copies $PsCmdlet to $p so you can use it and reduce typing. <br \/>&nbsp;&nbsp;&nbsp; This is implemented by using $host.EnterNestedPrompt() which means that you have <br \/>&nbsp;&nbsp;&nbsp; to type EXIT to get out of this mode. <\/font><\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\"><font color=\"#008000\">.Example <br \/>&nbsp;&nbsp;&nbsp; Test-PsCmdlet <br \/>.ReturnValue <br \/>&nbsp;&nbsp;&nbsp; None <br \/>.Link <br \/>&nbsp;&nbsp;&nbsp; about_functions_advanced <br \/>&nbsp;&nbsp;&nbsp; about_functions_advanced_methods <br \/>&nbsp;&nbsp;&nbsp; about_functions_advanced_parameters <br \/>.Notes <br \/>NAME:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Test-PsCmdlet <br \/>AUTHOR:&nbsp;&nbsp;&nbsp; RugratsVista\\jsnover <br \/>LASTEDIT:&nbsp; 01\/10\/2009 16:25:42 <br \/>#&gt; <br \/><\/font>[CmdletBinding()] <br \/>param() <br \/>&nbsp;&nbsp;&nbsp; Write-Host -ForegroundColor RED &#8220;Interactively explore `$PsCmdlet .&nbsp; Copied `$PsCmdlet to `$p &#8221; <br \/>&nbsp;&nbsp;&nbsp; Write-Host -ForegroundColor RED &#8216;Type &#8220;Exit&#8221; to return&#8217; <br \/>&nbsp;&nbsp;&nbsp; $p = $pscmdlet <br \/>&nbsp;&nbsp;&nbsp; function Prompt {&#8220;Test-PsCmdlet&gt; &#8220;} <br \/>&nbsp;&nbsp;&nbsp; $host.EnterNestedPrompt() <br \/>}<\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\"><\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\"><\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\"><\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\"><\/font><\/p>\n<p><font face=\"Consolas\" color=\"#000000\" size=\"2\">Let\u2019s use it and explore:<\/font><\/p>\n<p><font face=\"Consolas\" color=\"#000000\" size=\"2\"><\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\">PS&gt; <strong>Test-PScmdlet <br \/><\/strong><font color=\"#ff0000\">Interactively explore $PsCmdlet .&nbsp; Copied $PsCmdlet to $p <br \/>Type &#8220;Exit&#8221; to return <br \/><\/font>Test-PsCmdlet&gt; $p |gm <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\">&nbsp;&nbsp; TypeName: System.Management.Automation.PSScriptCmdlet <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\">Name&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; MemberType Definition <br \/>&#8212;-&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; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- <br \/>CurrentProviderLocation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Management.Automat&#8230; <br \/>Dispose&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; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Void Dispose() <br \/>Equals&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; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Boolean Equals(Obj&#8230; <br \/>GetDynamicParameters&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Object GetDynamicP&#8230; <br \/>GetHashCode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Int32 GetHashCode() <br \/>GetResolvedProviderPathFromPSPath&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Collections.Object&#8230; <br \/>GetResourceString&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.String GetResource&#8230; <br \/>GetType&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; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Type GetType() <br \/>GetUnresolvedProviderPathFromPSPath Method&nbsp;&nbsp;&nbsp;&nbsp; System.String GetUnresolv&#8230; <br \/>GetVariableValue&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Object GetVariable&#8230; <br \/>Invoke&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; Method&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Invoke(), System.Collect&#8230; <br \/>ShouldContinue&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Boolean ShouldCont&#8230; <br \/>ShouldProcess&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Boolean ShouldProc&#8230; <br \/>ThrowTerminatingError&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Void ThrowTerminat&#8230; <br \/>ToString&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; Method&nbsp;&nbsp;&nbsp;&nbsp; System.String ToString() <br \/>TransactionAvailable&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Boolean Transactio&#8230; <br \/>WriteCommandDetail&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Void WriteCommandD&#8230; <br \/>WriteDebug&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; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Void WriteDebug(St&#8230; <br \/>WriteError&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; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Void WriteError(Er&#8230; <br \/>WriteObject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Void WriteObject(O&#8230; <br \/>WriteProgress&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Void WriteProgress&#8230; <br \/>WriteVerbose&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Void WriteVerbose(&#8230; <br \/>WriteWarning&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method&nbsp;&nbsp;&nbsp;&nbsp; System.Void WriteWarning(&#8230; <br \/>CommandOrigin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Management.Automat&#8230; <br \/>CommandRuntime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Management.Automat&#8230; <br \/>CurrentPSTransaction&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Management.Automat&#8230; <br \/>Events&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; Property&nbsp;&nbsp; System.Management.Automat&#8230; <br \/>Host&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; Property&nbsp;&nbsp; System.Management.Automat&#8230; <br \/>InvokeCommand&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Management.Automat&#8230; <br \/>InvokeProvider&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Management.Automat&#8230; <br \/>JobRepository&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Management.Automat&#8230; <br \/>MyInvocation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Management.Automat&#8230; <br \/>ParameterSetName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.String ParameterSe&#8230; <br \/>SessionState&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Management.Automat&#8230; <br \/>Stopping&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; Property&nbsp;&nbsp; System.Boolean Stopping {&#8230; <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\">Test-PsCmdlet&gt; $p.CurrentProviderLocation <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\">MemberType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Method <br \/>OverloadDefinitions : {System.Management.Automation.PathInfo CurrentProvide <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rLocation(String providerId)} <br \/>TypeNameOfValue&nbsp;&nbsp;&nbsp;&nbsp; : System.Management.Automation.PSMethod <br \/>Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : System.Management.Automation.PathInfo CurrentProvider <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Location(String providerId) <br \/>Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : CurrentProviderLocation <br \/>IsInstance&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : True <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\">Test-PsCmdlet&gt; $p.CurrentProviderLocation(&#8220;FileSystem&#8221;) <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\">Path <br \/>&#8212;- <br \/>C:\\temp <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\">Test-PsCmdlet&gt; $p.CurrentProviderLocation(&#8220;registry&#8221;) <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\">Path <br \/>&#8212;- <br \/>HKLM:\\ <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\">Test-PsCmdlet&gt; exit <br \/>PS&gt;<\/font><\/p>\n<p>BTW \u2013 when you write a script and you want to write a file into the current directory \u2013 you should NOT use the current directory because in PowerShell, that might be the registry, the certificate store, the WSMAN configuration store, etc.&nbsp; What you REALLY want to do is to write a file into the Current FILESYSTEM directory.&nbsp; This is the way you find out.&nbsp; $psCmdlet.CurrentProviderLocation() is a method that returns the current location for a particular provider (which you pass in as a string).&nbsp; Thus to get the current filesystem directory you type:<\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" size=\"2\">$psCmdlet.CurrentProviderLocation(&#8220;FileSystem&#8221;) <\/font><\/p>\n<p>Remember \u2013 this only works when you have $psCmdlet set which is to say when you are in an Advanced Function.&nbsp; Did I mention that everyone should be using Advanced Functions for everything?&nbsp; Get with the program today.<\/p>\n<p>Enjoy!<\/p>\n<p>Jeffrey Snover [MSFT] <br \/>Windows Management Partner Architect <br \/>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp;&nbsp; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a> <br \/>Visit the Windows PowerShell ScriptCenter at:&nbsp; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Everyone needs to get good with Advanced Functions \u2013 this is the easiest path to the best semantics for everyone.&nbsp; In previous posts we\u2019ve shown how you can add a few simple attributes and get a TON of stuff for free.&nbsp; There is a LOT more to advanced functions.&nbsp; You can go VERY VERY far [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[97,137,210,270],"class_list":["post-4721","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-advanced-functions","tag-ctp3","tag-jeffrey-snover","tag-powershell-v2"],"acf":[],"blog_post_summary":"<p>Everyone needs to get good with Advanced Functions \u2013 this is the easiest path to the best semantics for everyone.&nbsp; In previous posts we\u2019ve shown how you can add a few simple attributes and get a TON of stuff for free.&nbsp; There is a LOT more to advanced functions.&nbsp; You can go VERY VERY far [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4721","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=4721"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4721\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=4721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=4721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=4721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}