{"id":1695,"date":"2014-04-02T00:01:00","date_gmt":"2014-04-02T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/04\/02\/build-constrained-powershell-endpoint-using-configuration-file\/"},"modified":"2014-04-02T00:01:00","modified_gmt":"2014-04-02T00:01:00","slug":"build-constrained-powershell-endpoint-using-configuration-file","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/build-constrained-powershell-endpoint-using-configuration-file\/","title":{"rendered":"Build Constrained PowerShell Endpoint Using Configuration File"},"content":{"rendered":"<p><b>Summary<\/b>: Boe Prox teaches you how to build a constrained endpoint by using a configuration file.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;Hey, Scripting Guy!, is there a better way to lock down my remote endpoint by using something other than a startup script?<\/p>\n<p>&mdash;SH<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>&nbsp;Hello SH, Honorary Scripting Guy, Boe Prox, here today filling in for my good friend, The Scripting Guy. This is the third part in a series of five posts about Remoting Endpoints. The series includes:<\/p>\n<ol>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/introduction-to-powershell-endpoints\/\" target=\"_blank\">Introduction to PowerShell Endpoints<\/a><\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/build-constrained-powershell-endpoint-using-startup-script\/\" target=\"_blank\">Build Constrained PowerShell Endpoint Using Startup Script<\/a><\/li>\n<li><b>Build Constrained PowerShell Endpoint Using Configuration File<\/b> (today&rsquo;s post)<\/li>\n<li>Use Delegated Administration and Proxy Functions<\/li>\n<li>Build a Tool that Uses Constrained PowerShell Endpoint<\/li>\n<\/ol>\n<p>In yesterday&rsquo;s post, I was able to restrict the commands that are available from a remote Windows PowerShell session by using a startup script to create a constrained endpoint. Today I am going to show you how to create a constrained endpoint by using a configuration file, which became available in Windows PowerShell&nbsp;3.0.<\/p>\n<p>Although startup scripts work great and were a necessity in Windows PowerShell&nbsp;2.0, they are optional for configuring constrained remote endpoints since Windows PowerShell&nbsp;3.0 because a session configuration file (.pssc) makes the process much easier to work with.<\/p>\n<p>So what is a session configuration file and what does it look like? The .pssc file is used with <b>Register-PSSessionConfiguration<\/b>, and it is used in the <b>Path<\/b> parameter. After the session configuration has been registered, the file is copied to the C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\SessionConfig folder.<\/p>\n<p>It is saved in the following format: <b>SessionName_GUID.pssc<\/b>. The GUID is the same as that in the .pssc file and the same as what you would see when you use <b>Get-PSSessionConfiguration<\/b> and view the <b>GUID<\/b> property. It is a text file that contains a hash table that allows you to specify various parts of the remote endpoint.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/ConfigFile1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/ConfigFile1.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>To building a session configuration file, we use the <b>New-PSSessionConfigurationFile<\/b> cmdlet. Looking at the Help file for this cmdlet, you can see that there are a lot of parameters, which cover all aspects of the configuration file.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5165.2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5165.2.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>You have a number of options for creating the file. You can specify the parameters you want to use and supply the proper arguments, build a hash file, and splat the parameters into the cmdlet. I plan to use splatting to build my file. But before that, I am going to run the cmdlet with only the <b>Path<\/b> parameter, which will create a default configuration file. Then I&rsquo;ll edit it by using the ISE. This way I can show you everything that is available to edit.<\/p>\n<p>Creating a blank session configuration file is as simple as running the following command:<\/p>\n<p style=\"margin-left:30px\">New-PSSessionConfigurationFile -Path &quot;ConstainedSession.pssc&quot;<\/p>\n<p>We can then open the file by using the ISE and view the contents of the empty configuration file.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/ConfigFile3.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/ConfigFile3.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/ConfigFile4.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/ConfigFile4.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>As you can see, there is quite a bit of stuff here that you can adjust, based on your requirements. Only a few items are actually enabled by default (such as <b>Language<\/b> and <b>SessionType<\/b>) because of the need for the remote endpoint to work properly.<\/p>\n<p>If you recall from yesterday&rsquo;s post, <b>Language<\/b> is important to determine what you will allow for this remote endpoint. Its current setting of <b>FullLanguage<\/b> is not what I plan to use because it opens everything in the Windows PowerShell language. I want to stick with <b>NoLanguage<\/b> to restrict the use of variables and .NET types (to name a couple).<\/p>\n<p>Now that we have that out of the way, I am going to build the configuration file:<\/p>\n<p style=\"margin-left:30px\">New-PSSessionConfigurationFile -Path &#039;PrinterAuditSession.pssc&#039; `<\/p>\n<p style=\"margin-left:30px\">-SessionType RestrictedRemoteServer `<\/p>\n<p style=\"margin-left:30px\">-LanguageMode NoLanguage `<\/p>\n<p style=\"margin-left:30px\">-ModulesToImport PrintManagement, Microsoft.PowerShell.Management `<\/p>\n<p style=\"margin-left:30px\">-VisibleCmdlets Get-Service `<\/p>\n<p style=\"margin-left:30px\">-VisibleFunctions Get-Printer,Get-PrintJob<\/p>\n<p>Let me break down some of this before I create the session:<\/p>\n<p style=\"margin-left:30px\"><b>Path<\/b>&nbsp;&nbsp;Name of the file that will be created from the cmdlet.<\/p>\n<p style=\"margin-left:30px\"><b>SessionType&nbsp;&nbsp;<\/b>Determines what commands will be made available when the session is started. By specifying <b>RestrictedRemoteServer<\/b>, I am allowing only the 7 proxy functions that are required for the remote session to work properly. <b><\/b><\/p>\n<p style=\"margin-left:30px\"><b>LanguageMode<\/b>&nbsp;&nbsp;&nbsp;By defining the language as <b>NoLanguage<\/b>, I ensure that whoever uses this session will not have access to the PowerShell language which includes no variables, .Net types, etc&hellip;<\/p>\n<p style=\"margin-left:30px\"><b>VisibileCmdlets<\/b>&nbsp;&nbsp;&nbsp;Besides the 7 proxy functions, I want to include a couple of other cmdlets that the user can make use of.<\/p>\n<p style=\"margin-left:30px\"><b>VisibleFunctions<\/b>&nbsp;&nbsp;&nbsp;Depending on the modules that I choose to import, some of the commands may be functions. I want to make sure that I allow functions which would be required for whoever connects to this endpoint.<\/p>\n<p style=\"margin-left:30px\"><b>ModulesToImport<\/b>&nbsp;&nbsp;&nbsp;By default, no modules are available nor can the user import modules while in this session. I can determine what modules will be made available and already imported using this. Note that only the cmdlets that I specify in VisibleCmdlets will be available in the constrained session.<\/p>\n<p>Next is to actually create the session that will be made available to our users:<\/p>\n<p style=\"margin-left:30px\">Register-PSSessionConfiguration -Name PrinterAudit -Path PrinterAuditSession.pssc &ndash;ShowSecurityDescriptorUI<\/p>\n<p>I&rsquo;ll type <b>A<\/b> to allow the services to restart and allow the session to be made available for user consumption.<\/p>\n<p>I am removing the default groups and only allowing the <b>PrinterAuditors<\/b> group to have access to connect to this endpoint. They only need the Execute permissions, so this will be enough.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/ConfigFile5.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/ConfigFile5.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Let&rsquo;s let them connect and try it out! I will connect with an account that has <b>PrinterAuditors<\/b> rights and see what I have access to do:<\/p>\n<p style=\"margin-left:30px\">Enter-PSSession -ComputerName &#039;boe-pc&#039; -ConfigurationName PrinterAudit<\/p>\n<p>After some exploring, I see that I can check printers and services, but I cannot make any changes while I am connected to the remote endpoint.<\/p>\n<p style=\"margin-left:30px\">[boe-pc]: PS&gt;Get-Command<\/p>\n<p style=\"margin-left:30px\">[boe-pc]: PS&gt;Get-Printer<\/p>\n<p style=\"margin-left:30px\">[boe-pc]: PS&gt;Add-Printer<\/p>\n<p style=\"margin-left:30px\">[boe-pc]: PS&gt;Get-Service Spooler<\/p>\n<p style=\"margin-left:30px\">[boe-pc]: PS&gt;Stop-Service Spooler<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/ConfigFile6.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/ConfigFile6.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>With that, you can see what it takes to configure a constrained remote endpoint by using a <b>pssession<\/b> configuration file.<\/p>\n<p>SH, that is all there is to customizing a constrained remote endpoint by using a configuration file. What happens if we want a user to have access to a command (or commands), but want to further limit what they can do? How about giving a user access to run that command on a system that they do not have access to without giving them the rights to that system? Stay tuned&hellip;<\/p>\n<p>Remote Endpoint Week will continue tomorrow when I will show you how this can be done by creating a proxy function and using delegated administration on the remote endpoint.<\/p>\n<p>I invite you to follow the Scripting Guys 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.<\/p>\n<p><b>Boe Prox, Honorary Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Boe Prox teaches you how to build a constrained endpoint by using a configuration file. &nbsp;Hey, Scripting Guy!, is there a better way to lock down my remote endpoint by using something other than a startup script? &mdash;SH &nbsp;Hello SH, Honorary Scripting Guy, Boe Prox, here today filling in for my good friend, The [&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":[162,496,56,497,45],"class_list":["post-1695","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-boe-prox","tag-endpoint","tag-guest-blogger","tag-remote","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Boe Prox teaches you how to build a constrained endpoint by using a configuration file. &nbsp;Hey, Scripting Guy!, is there a better way to lock down my remote endpoint by using something other than a startup script? &mdash;SH &nbsp;Hello SH, Honorary Scripting Guy, Boe Prox, here today filling in for my good friend, The [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1695","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=1695"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1695\/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=1695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}