<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PowerShell Server</title>
	<atom:link href="http://www.powershellserver.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.powershellserver.com</link>
	<description>Secure Remote Access to PowerShell Over SSH</description>
	<lastBuildDate>Fri, 22 Mar 2013 20:11:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>PowerShell Server: SFTP Scripting</title>
		<link>http://www.powershellserver.com/powershell-server-sftp-scripting/</link>
		<comments>http://www.powershellserver.com/powershell-server-sftp-scripting/#comments</comments>
		<pubDate>Fri, 28 Dec 2012 21:19:20 +0000</pubDate>
		<dc:creator>adaml</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Technical Notes]]></category>

		<guid isPermaLink="false">http://e2/i/?p=1860</guid>
		<description><![CDATA[Introduction By default, the SFTP Server will act as a standard SFTP server and provide file management functionality for the specified root directory. In some cases, it may be desirable to implement advanced functionality. PowerShell Server provides an advanced SFTP&#8230;]]></description>
			<content:encoded><![CDATA[<div style="padding: 5px;">
<h2>Introduction</h2>
<p>By default, the SFTP Server will act as a standard SFTP server and provide file management functionality for the specified root directory. In some cases, it may be desirable to implement advanced functionality. PowerShell Server provides an advanced SFTP scripting technique where a PowerShell script can be used to customize the SFTP functions.</p>
<p>This tutorial will guide you through setting up this functionality within PowerShell Server as well as the PowerShell functions that are required within the script.</p>
<p><strong>Chapter Listing</strong></p>
<ol>
<li><a href="#setup">Setup</a></li>
<li><a href="#script">Script</a>
<ul>
<li><a href="#functions">Required Functions</a></li>
<li><a href="#errorcodes">Error Codes</a></li>
</ul>
</li>
<li><a href="#additionalinfo">Additional Information</a></li>
</ol>
<h2>Setup</h2>
<p>To use a PowerShell Script to control SFTP functionality, simply point the <em>SFTP Root Directory</em> under the <em>Other</em> tab to the location of a PowerShell script.</p>
<p><a href="http://www.powershellserver.com/powershell-server-sftp-scripting/psserversftpscript-2/" rel="attachment wp-att-2042"><img class="alignnone size-full wp-image-2042" title="psserversftpscript" src="http://www.powershellserver.com/wp-content/uploads/2012/12/psserversftpscript1.png" alt="" width="546" height="464" /></a></p>
<h2>Script</h2>
<p>The script used in this tutorial can be downloaded <a href="http://www.powershellserver.com/wp-content/uploads/2012/12/sftpscript.zip">here</a>.</p>
<p>Below is the path variable and some additional functions that are used by the example functions listed below.</p>
<pre class="brush: powershell; title: ; notranslate">
  $sftpRoot = &quot;C:\temp&quot;

  function Get-UnixTime($time) {
    return [long]($time - [DateTime]'1970/01/01 12:00:00 AM').TotalSeconds
  }
  function Resolve-SFTPPath($vpath) {
    return [IO.Path]::Combine($sftpRoot, $vpath.Substring(1))
  }
</pre>
<h3>Required Functions</h3>
<p>Below is a list of functions that must be implemented in the PowerShell script to control the corresponding SFTP functionality. Note that these are just examples of default functionality, and can be modified to suit your implementation&#8217;s specific needs.</p>
<p><strong>Confirm-DirList</strong>: Called when listing the contents of a directory.</p>
<pre class="brush: powershell; title: ; notranslate">
  function Confirm-DirList($sftpArgs) {
  # $sftpArgs.connectionId: connection id
  # $sftpArgs.user: username
  # $sftpArgs.path: directory virtual path
  # out:
  # $sftpArgs.statusCode: operation result
  # $sftpArgs.fileList: string[] with just filenames
    $path = Resolve-SFTPPath $sftpArgs.path
    if ( -not (test-path $path) ) {
      $sftpArgs.statusCode = $SSH_FXS_NO_SUCH_PATH
      return
    }
    $sftpArgs.fileList = Get-ChildItem $path | %{
      $_.Name
    }
    $sftpArgs.statusCode = $SSH_FXS_OK
  }
</pre>
<p><strong>Confirm-DirCreate</strong>: Called when creating a directory.</p>
<pre class="brush: powershell; title: ; notranslate">
  function Confirm-DirCreate($sftpArgs) {
  # $sftpArgs.connectionId: connection id
  # $sftpArgs.user: username
  # $sftpArgs.path: directory virtual path
  # $sftpArgs.attrs: directory attributes
  # out:
  # $sftpArgs.statusCode: operation result
    $sftpArgs.statusCode = $SSH_FXS_OK
    $path = Resolve-SFTPPath $sftpArgs.path
    New-Item -Path $path -ItemType Directory
  }
</pre>
<p><strong>Confirm-DirRemove</strong>: Called when removing a directory.</p>
<pre class="brush: powershell; title: ; notranslate">
  function Confirm-DirRemove($sftpArgs) {
  # $sftpArgs.connectionId: connection id
  # $sftpArgs.user: username
  # $sftpArgs.path: directory virtual path
  # out:
  # $sftpArgs.statusCode: operation result
    $sftpArgs.statusCode = $SSH_FXS_OK
    $path = Resolve-SFTPPath $sftpArgs.path
    Remove-Item -Path $path -force
  }
</pre>
<p><strong>Confirm-FileOpen</strong>: Called when opening a file.</p>
<pre class="brush: powershell; title: ; notranslate">
  function Confirm-FileOpen($sftpArgs) {
  # $sftpArgs.connectionId: connection id
  # $sftpArgs.user: username
  # $sftpArgs.path: file virtual path
  # $sftpArgs.desiredAccess: desired file access
  # $sftpArgs.flags: file open flags
  # $sftpArgs.attrs: file attributes
  # out:
  # $sftpArgs.statusCode: operation result
  # $sftpArgs.physicalPath: physical path to file the server will handle
    $physicalPath = Resolve-SFTPPath $sftpArgs.path
    $flags = $sftpArgs.flags
    if ( -not ($flags -band $SSH_V3_FXF_CREAT) ) {
      # opening existing file
      if ( -not (test-path $physicalPath) ) {
       $sftpArgs.statusCode = $SSH_FXS_NO_SUCH_FILE;
        return
      }
    } else {
      # creating a new file
      if ( -not (test-path $physicalPath) ) {
        New-Item -Path $physicalPath -ItemType File
      }
    }
    $sftpArgs.physicalPath = $physicalPath
    $sftpArgs.statusCode = $SSH_FXS_OK
  }
</pre>
<p><strong>Confirm-FileClose</strong>: Called when closing a file.</p>
<pre class="brush: powershell; title: ; notranslate">
  function Confirm-FileClose($sftpArgs) {
  # $sftpArgs.connectionId: connection id
  # $sftpArgs.user: username
  # $sftpArgs.path: file or directory virtual path
  # $sftpArgs.statusCode: operation result
  # $sftpArgs.physicalPath: physical path of the opened file
  # you could for example grab the contents here and delete it
    $sftpArgs.statusCode = $SSH_FXS_OK
  }
</pre>
<p><strong>Confirm-FileRemove</strong>: Called when removing a file.</p>
<pre class="brush: powershell; title: ; notranslate">
  function Confirm-FileRemove($sftpArgs) {
  # $sftpArgs.connectionId: connection id
  # $sftpArgs.user: username
  # $sftpArgs.path: file virtual path
  # out:
  # $sftpArgs.statusCode: operation result
    $sftpArgs.statusCode = $SSH_FXS_OK
    $path = Resolve-SFTPPath $sftpArgs.path
    if ( -not (test-path $path) ) {
      $sftpArgs.statusCode = $SSH_FXS_NO_SUCH_PATH
      return
    }
    Remove-Item $path
  }
</pre>
<p><strong>Confirm-FileRename</strong>: Called when renaming a file.</p>
<pre class="brush: powershell; title: ; notranslate">
  function Confirm-FileRename($sftpArgs) {
  # $sftpArgs.connectionId: connection id
  # $sftpArgs.user: username
  # $sftpArgs.path: original file virtual path
  # $sftpArgs.newPath: new file virtual path
  # out:
  # $sftpArgs.statusCode: operation result
    $sftpArgs.statusCode = $SSH_FXS_OK
    $path = Resolve-SFTPPath $sftpArgs.path
    if ( -not (test-path $path) ) {
      $sftpArgs.statusCode = $SSH_FXS_NO_SUCH_PATH
      return
    }
    $newPath = Resolve-SFTPPath $sftpArgs.newPath
    Write-Debug -Message &quot;Moving $path to $newPath&quot;
    Move-Item $path $newPath
  }
</pre>
<p><strong>Confirm-GetAttributes</strong>: Called when retrieving a file&#8217;s attributes.</p>
<pre class="brush: powershell; title: ; notranslate">
  function Confirm-GetAttributes($sftpArgs) {
  # $sftpArgs.connectionId: connection id
  # $sftpArgs.user: username
  # $sftpArgs.path: directory virtual path
  # $sftpArgs.flags: flags for this operation
  # $sftpArgs.attrs: file attributes to return, as a hashtable
  # out:
  # $sftpArgs.statusCode: operation result
    $sftpArgs.statusCode = $SSH_FXS_OK
    $path = Resolve-SFTPPath $sftpArgs.path
    if ( -not (test-path $path) ) {
      $sftpArgs.statusCode = $SSH_FXS_NO_SUCH_PATH
      return
    }
    $file = Get-ItemProperty $path
    $acl = Get-ACL $path
    $attrs = $sftpArgs.attrs
    $attrs.creationTime = Get-UnixTime($file.CreationTimeUtc)
    $attrs.isDir = $file.PSIsContainer
    $attrs.modifiedTime = Get-UnixTime($file.LastWriteTimeUtc)
    $attrs.accessTime = Get-UnixTime($file.LastAccessTimeUtc)
    $attrs.size = $file.Length
    $attrs.ownerId = $acl.Owner
    $attrs.groupId = $acl.Group
  }
</pre>
<p><strong>Confirm-SetAttributes</strong>: Called when setting a file&#8217;s attributes.</p>
<pre class="brush: powershell; title: ; notranslate">
  function Confirm-SetAttributes($sftpArgs) {
  # $sftpArgs.connectionId: connection id
  # $sftpArgs.user: username
  # $sftpArgs.path: file virtual path
  # $sftpArgs.attrs: file attributes
  # out:
  # $sftpArgs.statusCode: operation result
    $sftpArgs.statusCode = $SSH_FXS_OK
  }
</pre>
<h3>Error Codes</h3>
<p>The following SFTP Error Codes may be useful if you need to return an error from one of the above functions.</p>
<pre class="brush: powershell; title: ; notranslate">
  $SSH_FXS_OK = 0
  $SSH_FXS_EOF = 1
  $SSH_FXS_NO_SUCH_FILE = 2
  $SSH_FXS_PERMISSION_DENIED = 3
  $SSH_FXS_FAILURE = 4
  $SSH_FXS_BAD_MESSAGE = 5
  $SSH_FXS_NO_CONNECTION = 6
  $SSH_FXS_CONNECTION_LOST = 7
  $SSH_FXS_OP_UNSUPPORTED = 8
  $SSH_FXS_INVALID_HANDLE = 9
  $SSH_FXS_NO_SUCH_PATH = 10
  $SSH_FXS_FILE_ALREADY_EXISTS = 11
  $SSH_FXS_WRITE_PROTECT = 12
  $SSH_FXS_NO_MEDIA = 13
  $SSH_FXS_NO_SPACE_ON_FILESYSTEM = 14
  $SSH_FXS_QUOTA_EXCEEDED = 15
  $SSH_FXS_UNKNOWN_PRINCIPAL = 16
  $SSH_FXS_LOCK_CONFLICT = 17
  $SSH_FXS_DIR_NOT_EMPTY = 18
  $SSH_FXS_NOT_A_DIRECTORY = 19
  $SSH_FXS_INVALID_FILENAME = 20
  $SSH_FXS_LINK_LOOP = 21
  $SSH_FXS_CANNOT_DELETE = 22
  $SSH_FXS_INVALID_PARAMETER = 23
  $SSH_FXS_FILE_IS_A_DIRECTORY = 24
  $SSH_FXS_BYTE_RANGE_LOCK_CONFLICT = 25
  $SSH_FXS_BYTE_RANGE_LOCK_REFUSED = 26
  $SSH_FXS_DELETE_PENDING = 27
  $SSH_FXS_FILE_CORRUPT = 28
  $SSH_FXS_OWNER_INVALID = 29
  $SSH_FXS_GROUP_INVALID = 30
  $SSH_FXS_NO_MATCHING_BYTE_RANGE_LOCK = 31

  # File open flags
  $SSH_V3_FXF_READ = 0x00000001
  $SSH_V3_FXF_WRITE = 0x00000002
  $SSH_V3_FXF_APPEND = 0x00000004
  $SSH_V3_FXF_CREAT = 0x00000008
  $SSH_V3_FXF_TRUNC = 0x00000010
  $SSH_V3_FXF_EXCL = 0x00000020
  $SSH_V4_FXF_TEXT = 0x00000040
</pre>
<h2>Additional Information</h2>
<p>The sample script used in this tutorial can be downloaded <a href="http://www.powershellserver.com/wp-content/uploads/2012/12/sftpscript.zip">here</a>.</p>
<p>We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at <a href="mailto:support@nsoftware.com">support@nsoftware.com</a>.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.powershellserver.com/powershell-server-sftp-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started</title>
		<link>http://www.powershellserver.com/getting-started/</link>
		<comments>http://www.powershellserver.com/getting-started/#comments</comments>
		<pubDate>Wed, 19 Dec 2012 21:46:11 +0000</pubDate>
		<dc:creator>spencerb</dc:creator>
				<category><![CDATA[Technical Notes]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://e2/i/?p=1771</guid>
		<description><![CDATA[Introduction PowerShell Server is a full-featured SSH 2.0 server that enables Windows Desktops and Servers with a secure remote entry point to a Windows PowerShell Host. This gives users the power to securely manage Windows remotely through PowerShell from any&#8230;]]></description>
			<content:encoded><![CDATA[<div style="padding: 5px;">
<h2>Introduction</h2>
<p><a href="../">PowerShell Server</a> is a full-featured SSH 2.0 server that enables Windows Desktops and Servers with a secure remote entry point to a Windows PowerShell Host. This gives users the power to securely manage Windows remotely through PowerShell from any standard SSH client, including: PuTTY, OpenSSH, iPhone, Blackberry, Linux/Unix machines, as well as our own SSH client solutions.</p>
<p>This tutorial will guide you through setting up PowerShell Server and how to use many of the options.</p>
<p><strong>Chapter Listing</strong></p>
<ol>
<li><a href="#powershellserver">Setting up PowerShell Server</a>
<ul>
<li><a href="#windowsservice">Running as a Windows Service</a></li>
<li><a href="#scp">Secure Copy Protocol (SCP)</a></li>
<li><a href="#sshtunnel">SSH Tunnel</a></li>
<li><a href="#sftp">SFTP Server</a></li>
<li><a href="#profile">PowerShell Profile Execution</a></li>
</ul>
</li>
<li><a href="#authentication">Authentication</a>
<ul>
<li><a href="#password">Password Authentication</a></li>
<li><a href="#publickey">Public Key Authentication</a></li>
<li><a href="#gssapi">GSSAPI Authentication (NTLM/Kerberos)</a></li>
</ul>
</li>
<li><a href="#powershellasp">PowerShell ASP</a>
<ul>
<li><a href="#webserver">PowerShell ASP Web Server</a></li>
<li><a href="#asppages">Authoring PowerShell ASP Pages</a></li>
<li><a href="#powershellpanel">PowerShell Panel</a></li>
</ul>
</li>
<li><a href="#additionalinfo">Additional Information</a></li>
</ol>
<p><a id="powershellserver"></a><br />
<h2>Setting up PowerShell Server</h2>
<p>The first time you run PowerShell Server, you should first switch to the <em>Server Key</em> tab to select the X.509 Digital Certificate to be used by the server to protect the SSH connections. By default, the setup will install and configure the application to use the included test certificate, testcert.pfx. Alternatively, you can generate a new certificate, or select a previously generated one.</p>
<p>You will also need to configure the Security Group to be used to control which users can connect to the service. This can be done from the <em>Security</em> tab.</p>
<p>Once you have configured these options, press the <em>Save Changes</em> button in the toolbar to save your changes. At this point, you should be ready to start the server and listen for SSH connections. The <em>Start</em>, <em>Restart</em> and <em>Stop</em> buttons can be used to control whether the server is listening or not.</p>
<p style="text-align: center;"><a href="http://www.powershellserver.com/getting-started/powershellserverconnectiontab-5/" rel="attachment wp-att-2045"><img class="alignnone size-full wp-image-2045" title="PowerShellServerConnectionTab" src="http://www.powershellserver.com/wp-content/uploads/2012/12/PowerShellServerConnectionTab4.png" alt="" width="546" height="464" /></a></p>
<p style="text-align: center;"><a href="../wp-content/uploads/2012/12/PowerShellServerConnectionTab.png"><br />
</a></p>
<p><a id="windowsservice"></a><strong>Running as a Windows Service</strong></p>
<p>If the <em>Run as a Windows Service</em> option is NOT selected, the SSH listener will be run in-process inside the PowerShell Server application. This means that to be able to connect remotely to your machine, you must be logged in and the PowerShell Server application must be running (and the listener started). This mode of operation can be very convenient for desktop use.</p>
<p>However, for servers, it is better to enable the <em>Run as a Windows Service</em> option. In this mode of operation, the SSH listener (and any connected PowerShell sessions) are not run on the desktop. Instead, a Windows Service is configured, which can run all the time, even if no users are logged on at the server console. When this option is enabled, the Start/Restart/Stop buttons in the PowerShell user interface actually control the Windows Service.</p>
<p>The Windows Service can also be controlled from the command line by specifying the <em>servicestart</em> or <em>servicestop</em> command line parameters. For example, to start the service:</p>
<pre>  PowerShellServer.exe /servicestart</pre>
<p>And to stop the service:</p>
<pre>  PowerShellServer.exe /servicestop</pre>
<p><a id="scp"></a><strong>Secure Copy Protocol (SCP)</strong></p>
<p>The <em>Enable Secure Copy Protocol (SCP) Support</em> checkbox controls whether file transfer via SCP is enabled or not. This can be used with the Send-PowerShellServerFile and Get-PowerShellServerFile CmdLets, which are included in the community edition of <a href="http://www.netcmdlets.com">NetCmdLets</a>, or with other command line SCP clients.</p>
<p><a id="sshtunnel"></a><strong>SSH Tunnel</strong></p>
<p>By checking the <em>Enable SSH Tunnel Support</em>, you can allow SSH tunnels to be created through the server. This allows clients that support creating SSH Tunnels to establish a tunnel through PowerShell Server. This is a common approach to secure an otherwise unsecured connection to a resource.</p>
<p><a id="sftp"></a><strong>SFTP Server</strong></p>
<p>To enable the SFTP server, check the <em>Enable SFTP Support</em> checkbox. Using this, any SFTP client will be able to connect and transfer files to and from the server.</p>
<p>By default the SFTP root directory will use the &#8216;windir&#8217; environment variable. Typically this is &#8220;C:\&#8221;. You can set the SFTP root directory in the <em>SFTP Settings</em> section on the <em>Other</em> tab.</p>
<p><a id="profile"></a><strong>PowerShell Profile Execution</strong></p>
<p>PowerShell Profiles to be executed upon connecting can be specified via the <em>Execute PowerShell Profiles on Connection</em> setting on the <em>Other</em> tab. The following profiles can be specified:</p>
<ul>
<li>nsoftware.PowerShell_profile.ps1 &#8211; Used only for interactive sessions.</li>
<li>nsoftware.PSExec_profile.ps1 &#8211; Used only for exec and PowerShell Server cmdlet connections.</li>
</ul>
<p>Profiles will first be loaded from the &#8220;%SystemRoot%\System32\WindowsPowerShell\v1.0&#8243; location and then the &#8220;%UserProfile%\Documents\WindowsPowerShell&#8221; location.<br />
<a id="authentication"></a><br />
<h2>Authentication</h2>
<p>PowerShell Server supports three authentication mechanisms: Username/Password, GSSAPI, and Public Key Authentication.</p>
<p style="text-align: center;"><a href="http://www.powershellserver.com/getting-started/powershellserversecuritytab/" rel="attachment wp-att-2046"><img class="aligncenter size-full wp-image-2046" title="PowerShellServerSecurityTab" src="http://www.powershellserver.com/wp-content/uploads/2012/12/PowerShellServerSecurityTab.png" alt="" width="546" height="464" /></a><a href="http://www.powershellserver.com/wp-content/uploads/2012/12/PowerShellServerSecurityTab1.png"><br />
</a></p>
<p><a id="password"></a><strong>Password Authentication</strong></p>
<p>Clients connecting to the server need to provide a username and password combination. The credentials are then verified using Windows Authentication mechanisms to make sure they match a valid local account on the server or on a domain trusted by it.</p>
<p>Connecting clients are also authorized by checking membership of the specified user in a special Group. The local/domain security group used for authorization can be selected under the Connection tab in the server user interface.</p>
<p><a id="publickey"></a><strong>Public Key Authentication</strong></p>
<p>If Public Key Authentication is enabled in the server user interface, connections to the server can also authenticate using the standard public key authentication mechanism supported by the SSH protocol instead of presenting a password.</p>
<p>PowerShell Server supports file based public key authentication similar to OpenSSH. That is, you would specify a public key file generated using a tool such as PuTTYgen. This can be setup as follows:</p>
<ol>
<li>Check the <em>Enable Public Key Authentication</em> checkbox on the <em>Security</em> tab and select the <em>File Based Public Key Authentication</em> option.</li>
<li>Select a key file that contains a list of SSH public keys. The file must contain one key per line, and should be formatted as follows:
<pre>ssh-rsa AAAAB3NzaC1yc2EA...rPFBe7Pnc= rsa-key-20110822</pre>
</li>
<li>Connect using a private key that corresponds to one of the public keys in the specified file.</li>
</ol>
<p>Windows Store based public key authentication is also supported by selecting the <em>Windows Store Based Public Key Authentication</em> option and choosing the desired store type and name.</p>
<p>With Public Key Authentication, connecting clients only need to present a username and demonstrate that they have a private key matching a public key known by the server.</p>
<p><a id="gssapi"></a><strong>GSSAPI Authentication (NTLM/Kerberos)</strong></p>
<p>NTLM or Kerberos authentication can be enabled by checking <em>Enable GSSAPI Authentication</em> under the <em>Security</em> tab and choosing the desired <em>Supported Mechanisms</em>.</p>
<p>Note that when using Kerberos as an authentication mechanism, it is recommended that PowerShell Server be run as a service. When not running as a service and instead running under a user account, the default SPN (Service Principal Name) format of host/machine@domain used may result in errors. In that case, a new SPN should be registered (for instance ssh/machine) with the domain controller, and the KerberosSPN registry setting for PowerShell Server must be set. Additionally any connecting SSH client will need to be configured to use the newly defined SPN.<br />
<a id="powershellasp"></a><br />
<h2>PowerShell ASP</h2>
<p>PowerShell ASP is an ASP-like template language for Web Applications. PowerShell ASP templates contain a mixture of markup (HTML, XML or whatever you wish to generate) and inline PowerShell script. You can use PowerShell ASP inside your existing applications, or create complete applications from scratch based only on PowerShell ASP pages.</p>
<p>PowerShell ASP also allows you to generate and serve RSS and Atom feeds from PowerShell scripts executed on an ASP.NET Web Server. Feeds are generated automatically based on the objects returned by the execution of the PowerShell script in a PowerShell pipeline.</p>
<p><a id="webserver"></a><strong>PowerShell ASP Web Server</strong></p>
<p>You can enable the PowerShell ASP Web Server by checking <em>Enable PowerShell ASP</em> on the <em>PowerShell ASP</em> tab. Under this tab you can also specify the maximum number of connections that can be made to the server, as well as port numbers that the web server will listen on.</p>
<p><a href="http://www.powershellserver.com/getting-started/powershellasptab/" rel="attachment wp-att-2047"><img class="aligncenter size-full wp-image-2047" title="PowerShellASPTab" src="http://www.powershellserver.com/wp-content/uploads/2012/12/PowerShellASPTab.png" alt="" width="546" height="464" /></a></p>
<p>Once the Web Server is enabled, simply place pages in the root folder (i.e. the &#8216;www&#8217; folder located in your install directory) as you would any other web server.</p>
<p>PowerShell ASP pages can also be hosted using IIS instead of from the PowerShell Server. Please see the PowerShell Server reference file for more information.</p>
<p><a id="asppages"></a><strong>Authoring PowerShell ASP Pages</strong></p>
<p>PowerShell ASP pages are simple text files with the *.ps1x extension that contain both markup as well as snippets of regular PowerShell code interacting together. Unlike ASP.NET, there is no &#8216;code behind&#8217; model for PS1X pages; in this sense they resemble more the ASP classic model.</p>
<p>Here is a very simple PS1X page:</p>
<pre class="brush: powershell; html-script: true; title: ; notranslate">

  &lt;html&gt;
    &lt;body&gt;
      &lt;h1&gt; Hello
        &lt;%= $request['name'] %&gt;!
      &lt;/h1&gt;
    &lt;/body&gt;
  &lt;html&gt;

</pre>
<p>As you can see, everything is HTML markup right until the &lt;%= %&gt; section, which means &#8220;evaluate this PowerShell expression and print the result&#8221;. The expression, in this case, is using the intrinsic ASP.NET Request object to query data coming in the query string of the URL.</p>
<p>You can also create full code blocks that include any other kind of PowerShell expression or flow control construct, and even intermingle that with markup code. For example, here is a simple page that will present the list of running processes on the machine:</p>
<pre class="brush: powershell; html-script: true; title: ; notranslate">

  &lt;html&gt;
    &lt;body&gt;
      &lt;table&gt;
        &lt;tr&gt;
          &lt;td&gt;ID&lt;/td&gt;
          &lt;td&gt;Name&lt;/td&gt;
        &lt;/tr&gt;
        &lt;% get-process | %{ %&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;%=$_.Id%&gt;&lt;/td&gt;
            &lt;td&gt;&lt;%=$_.ProcessName%&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;% } %&gt;
      &lt;/table&gt;
    &lt;/body&gt;
  &lt;/html&gt;

</pre>
<p>RSS and Atom feeds can also be generated using PowerShell ASP pages. Please see the PowerShell Server reference file for more information.</p>
<p><a id="powershellpanel"></a><strong>PowerShell Panel</strong></p>
<p>PowerShell Panel is an easy-to-use ASP.NET Panel Web control for integrating PowerShell content into ASP.NET pages and applications. This allows you to use a mix of HTML and inline PowerShell script to rapidly create dynamic content regions.</p>
<p>To use the PowerShell Panel, simply add a reference to the <em>nsoftware.PowerShellASP.dll</em> assembly to your application, or copy it to your website&#8217;s ./bin folder. Then, in the ASP.NET page or control you want to use the PowerShell Panel, add the following code to register the control:</p>
<pre class="brush: powershell; html-script: true; title: ; notranslate">

  &lt;%@ Register Assembly=&quot;nsoftware.PowerShellASP&quot; Namespace=&quot;nsoftware&quot; TagPrefix=&quot;cc1&quot; %&gt;

</pre>
<p>Then, simply write your PowerShell ASP script directly into the panel:</p>
<pre class="brush: powershell; html-script: true; title: ; notranslate">

  &lt;cc1:PowerShellPanel ID=&quot;PSPanel1&quot; runat=&quot;server&quot;&gt;
    &lt;asp:Label ID=&quot;Label2&quot; ForeColor=&quot;Red&quot; runat=&quot;server&quot; Text=&quot;&amp;lt;%= $request.PhysicalApplicationPath %&amp;gt;&quot; /&gt;
    &lt;ol&gt;
   &amp;lt;% ls 'c:\' | %{ %&amp;gt;
      &lt;li&gt;&amp;lt;%= $_.Name %&amp;gt;&lt;/li&gt;
   &amp;lt;% } %&amp;gt;
    &lt;/ol&gt;
  &lt;/cc1:PowerShellPanel&gt;

</pre>
<p><strong>PowerShell Panel &#8211; Using Alternate Syntax</strong></p>
<p>Sometimes you might want to avoid having to do so much escaping of HTML when writing your PowerShell ASP scripts in PowerShellPanel controls, particularly of &lt; and &gt; characters. To facilitate this, you can set the UseAlternateDelimiters property of the PowerShellPanel control to true.</p>
<p>After doing this,PowerShellPanel will use the [% and %] sequences as delimiters for code blocks instead of thedelimiters normally used. With this, the example above could be written like this instead:</p>
<pre class="brush: powershell; html-script: true; title: ; notranslate">
&lt;cc1:PowerShellPanel ID=&quot;PSPanel1&quot; runat=&quot;server&quot;
      UseAlternateDelimiters='true'&gt;
   &lt;asp:Label ID='Label1' ForeColor=&quot;Red&quot; runat=&quot;server&quot; Text=&quot;[%= $request.PhysicalApplicationPath %]&quot; /&gt;
   &lt;ol&gt;
   [% ls 'c:\' | %{ %]
      &lt;li&gt;[%= $_.Name %]&lt;/li&gt;
   [% } %]
   &lt;/ol&gt;
&lt;/cc1:PowerShellPanel&gt;
</pre>
<p><a id="additionalinfo"></a><br />
<h2>Additional Information</h2>
<p>Additional documentation is available in the PowerShell Server V6 Reference file, which can be accessed through the <em>Contents</em> option under the <em>Help</em> dropdown in the top right corner of the UI.</p>
<p>We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at <a href="mailto:support@nsoftware.com">support@nsoftware.com</a>.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.powershellserver.com/getting-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing Remote Network Resources</title>
		<link>http://www.powershellserver.com/accessing-remote-network-resources/</link>
		<comments>http://www.powershellserver.com/accessing-remote-network-resources/#comments</comments>
		<pubDate>Wed, 19 Dec 2012 21:39:00 +0000</pubDate>
		<dc:creator>spencerb</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Technical Notes]]></category>

		<guid isPermaLink="false">http://e2/i/?p=1764</guid>
		<description><![CDATA[When authenticating connections with username/password, the server will attempt to logon the user to verify his/her credentials. By default, the server will attempt what is known as a &#8220;Network Logon&#8221;, which is more secure because it restricts the authenticated credentials&#8230;]]></description>
			<content:encoded><![CDATA[<p>
When authenticating connections with username/password, the server will attempt to logon the user to verify his/her credentials. By default, the server will attempt what is known as a &#8220;Network Logon&#8221;, which is more secure because it restricts the authenticated credentials to accessing local resources. This means that, by default, connections will very likely be allowed access only to resources in the local machine that PowerShell Server is running and not any remote network resources (like shared folders, or other servers).</p>
<p>If you want authenticated connections to have access to remote network resources under the credentials used for authentication, then the server needs to authenticate users in a different way, by doing an &#8220;Interactive Logon&#8221; instead. This can be enabled at the server level by setting the UseInteractiveLogon option to 1 (On) in the Windows registry and restarting the server process. To do this follow these steps:
</p>
<ol>
<li>
  From the registry editor navigate to &#8220;HKEY_LOCAL_MACHINE\SOFTWARE\nsoftware\PowerShellServer&#8221;</li>
<li>Create a new DWORD named &#8220;UseInteractiveLogon&#8221; with a value of 1</li>
</ol>
<p>
More details on configuring the PowerShell Server via registry settings can be found in the help documentation under the &#8220;Server Configuration&#8221; section.
</p>
<p>
For details on using Isolated Sessions and Impersonation with PowerShell Server, please see <a href="../powershell-runspace-user-accounts-and-impersonation/" title="Isolated Sessions, User Accounts, and Impersonation">this article</a>.</p>
<p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershellserver.com/accessing-remote-network-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell ASP: List Current Sessions of Machines on an Active Directory Domain</title>
		<link>http://www.powershellserver.com/list-current-sessions-of-machines-on-an-active-directory-domain/</link>
		<comments>http://www.powershellserver.com/list-current-sessions-of-machines-on-an-active-directory-domain/#comments</comments>
		<pubDate>Thu, 15 Nov 2012 14:15:25 +0000</pubDate>
		<dc:creator>andret</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Technical Notes]]></category>

		<guid isPermaLink="false">http://e2/i/?p=1406</guid>
		<description><![CDATA[Requirements: PowerShell Server PSTerminalServices Overview By combining several techniques, this article walks through creating a page that lists the current sessions for machines on an Active Directory domain. This article provides step by step instructions on how to create a&#8230;]]></description>
			<content:encoded><![CDATA[<div>
<img src="http://www.powershellserver.com/wp-content/uploads/2012/11/asp.png" alt="" title="asp" width="294" height="213" class="alignright size-full wp-image-1408" /><br />
</p>
<h4>Requirements:</h4>
<ul>
<li><a href="http://www.powershellserver.com/overview/web">PowerShell Server</a></li>
<li><a href="http://www.quest.com/powershell/activeroles-server.aspx" target="_blank">PSTerminalServices</a></li>
</ul>
<div>
<h3>Overview</h3>
<p>	By combining several techniques, this article walks through creating a page that lists the current sessions for machines on an Active Directory domain. This article provides step by step instructions on how to create a simple PowerShell ASP page to list the session information for machines on an Active Directory domain. There are two main steps to accomplishing this.</p>
<ol>
<li>List the machines on the domain</li>
<li>Get session information for each machine listed</li>
</ol>
<p>	To achieve these goals we will look to the world&#8217;s PowerShell enthusiasts who have already solved many of these problems and made the solutions freely available, then combine them and use them in a PowerShell ASP page to provide a simple and easy way of listing sessions of machines on the domain.</p>
<p>	Over at the <a href="http://blogs.technet.com/b/heyscriptingguy/">Hey, Scripting Guy!</a> blog, ScriptingGuy1 has given us a way in <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2006/11/09/how-can-i-use-windows-powershell-to-get-a-list-of-all-my-computers.aspx">this article</a> to list all the machines on a domain using the classes in the .NET System.DirectoryServices namespace from PowerShell. This will help us achieve our first goal.</p>
<p>	<a href="http://blogs.microsoft.co.il/blogs/scriptfanatic/">Shay Levy</a> has created a freely available module called <a href="http://blogs.microsoft.co.il/blogs/scriptfanatic/archive/2010/02/22/psterminalservices-powershell-module-for-terminal-services.aspx">PSTerminalServices &#8211; A PowerShell Module for Terminal Services.</a> This will aid us by allowing us to easily query each machine for session information.</p>
<h3>Prerequisites and Setup</h3>
<p>	Before diving into the code in the next section (which is actually very simple), there are a few requirements worth noting.</p>
<ol>
<li>The machines in the domain must have the &#8220;AllowRemoteRPC&#8221; setting enabled. This is a value in the registry that can either be set manually or set by a custom group policy. This allows sessions to be queried remotely. To enable this manually open the registry editor and navigate to</p>
<div>
<pre>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server</pre>
</div>
<p>	Now Locate the AllowRemoteRPC value and change the value data from 0 to 1 to enable this.
</li>
<li>	The PSTerminalServices module must be installed in a location where it is accessible from PowerShell ASP at runtime. Instead of installing to the user&#8217;s &#8220;Documents\WindowsPowerShell\Modules&#8221; folder the module will need to be installed to:
<div>
<pre>c:\windows\system32\windowspowershell\v1.0\modules</pre>
</div>
<p>	Note that you can simply copy the entire PSTerminalServices folder from the user&#8217;s &#8220;Documents\WindowsPowerShell\Modules&#8221; to the location above.</li>
<li>PowerShell ASP must be running under an account that is a member of the domain. In this article we will assume PowerShell ASP is being used in a site hosted in IIS. Since by default the application pool identity used is not a member of a domain, the easiest approach here is to create a new application pool for this application. In IIS 7 and IIS 7.5 create a new application pool, then in the advanced settings for the application pool specify a new Identify value as a domain user account. For instance:</li>
</ol>
<p><a href="http://www.powershellserver.com/wp-content/uploads/2012/11/powershellasp-listsessions-1.png"><img src="http://www.powershellserver.com/wp-content/uploads/2012/11/powershellasp-listsessions-1.png" alt="" title="powershellasp-listsessions-1" width="450" height="550" class="aligncenter size-full wp-image-1413" /></a></p>
<p>Lastly, modify the basic settings of the &#8220;PowerShellASP&#8221; application in IIS to use the new application pool.</p>
<h3>The Code</h3>
<p>	The code for this operation is actually relatively simple. First we will obtain a list of machines on the domain, then we will get session information for each machine and display it.</p>
<pre class="brush: powershell; html-script: true; title: ; notranslate">
&lt;h2&gt;Current session information&lt;/h2&gt;

&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;&lt;th&gt;Server&lt;/th&gt;&lt;th&gt;SessionID&lt;/th&gt;&lt;th&gt;State&lt;/th&gt;&lt;th&gt;UserName&lt;/th&gt;&lt;th&gt;WindowStationName&lt;/th&gt;&lt;/tr&gt;
&lt;%
Import-Module PSTerminalServices

#List machines on a domain
$strCategory = &quot;computer&quot;

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = (&quot;(objectCategory=$strCategory)&quot;)

$colProplist = &quot;name&quot;
foreach ($i in $colPropList){$null = $objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

#Iterate through the results and get session information for each machine
foreach ($objResult in $colResults)
{
	$objComputer = $objResult.Properties; 
	
	$sessionInfo = Get-TSSession -ComputerName $objComputer.name -ErrorAction SilentlyContinue -ErrorVariable myError

	if($sessionInfo)
	{
		foreach($tempInfo in $sessionInfo)
		{
		%&gt;
		&lt;tr&gt;&lt;td&gt;&lt;%= $tempInfo.Server.ServerName %&gt;&lt;/td&gt;&lt;td&gt;&lt;%= $tempInfo.SessionId %&gt;&lt;/td&gt;&lt;td&gt;&lt;%= $tempInfo.State %&gt;&lt;/td&gt;&lt;td&gt;&lt;%= $tempInfo.UserName %&gt;&lt;/td&gt;&lt;td&gt;&lt;%= $tempInfo.WindowStationName %&gt;&lt;/td&gt;&lt;/tr&gt;
		&lt;%
		}
	}
	else #an error occurred
	{
	%&gt;
	&lt;tr&gt;&lt;td&gt;&lt;% $objComputer.name; %&gt;&lt;td colspan=4&gt;Error: &lt;%= $myError[0] %&gt;&lt;/td&gt;&lt;/tr&gt;
	&lt;%
	}	
} %&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;	
</pre>
<p>When accessing this page you will then see a neat list of session information for each machine such as this:</p>
<p><a href="http://www.powershellserver.com/wp-content/uploads/2012/11/powershellasp-listsessions-2.png"><img src="http://www.powershellserver.com/wp-content/uploads/2012/11/powershellasp-listsessions-2.png" alt="" title="powershellasp-listsessions-2" width="560" height="289" class="aligncenter  wp-image-1412" /></a></p>
<p>That is all there is to it. The easiest way to test this is to download the .ps1x file below and place this in the &#8220;www&#8221; folder of the PowerShell ASP Installation alongside the other demos.</p>
<ul>
<li> <a href="http://www.powershellserver.com/wp-content/uploads/2012/12/powershellasp-listsessions-1.zip">Download code sample</a></li>
</ul>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.powershellserver.com/list-current-sessions-of-machines-on-an-active-directory-domain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell ASP: Automatically Converts PSObjects to RSS Items</title>
		<link>http://www.powershellserver.com/automatically-converts-psobjects-to-rss-items/</link>
		<comments>http://www.powershellserver.com/automatically-converts-psobjects-to-rss-items/#comments</comments>
		<pubDate>Wed, 14 Nov 2012 19:18:07 +0000</pubDate>
		<dc:creator>andret</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Technical Notes]]></category>

		<guid isPermaLink="false">http://e2/i/?p=1299</guid>
		<description><![CDATA[In the same way PowerShell ASP can be used to generate dynamic Web content, the PowerShell RSS component (included in PowerShell ASP) can be used to generate dynamic RSS feeds. PowerShell RSS provides the easiest way to create dynamic RSS&#8230;]]></description>
			<content:encoded><![CDATA[<p>In the same way PowerShell ASP can be used to generate dynamic Web content, the PowerShell RSS component (included in PowerShell ASP) can be used to generate dynamic RSS feeds. PowerShell RSS provides the easiest way to create dynamic RSS feeds from PowerShell scripts.</p>
<p>The Get-ChildItem command in PowerShell is used to get a listing of files to use as enclosures in the feed.</p>
<pre class="brush: powershell; html-script: true; title: ; notranslate">
&lt;%
# This example demonstrates how to generate an RSS Feed from a call to the Get-ChildItem cmdlet (dir). # To tailor to your specific needs, set the following values: $mediadir = 'C:\Testing\media';
$virtualdirectory = 'media';

# Check for user input $dir = $request['path']
if ( $dir -eq $null ) {
   $dir = $mediadir;
}

#Set the feed title and other basic feed attributes set-feedattr 'rss:title' &quot;PowerShellASP Get-RSS Sample&quot;;
set-feedattr 'rss:link' &quot;http://www.nsoftware.com&quot;;
set-feedattr 'rss:description' &quot;This example uses PowerShellASP to generate an RSS feed using PowerShell cmdlets.&quot;;

ls $dir | %{
   @{
      'rss:updated' = $_.LastWriteTime.ToString('R');
      'rss:title' = &quot;Podcast episode: $($_.Name)&quot;;
      'rss:enclosure@url' = &quot;http://&quot; + $request.servervariables[&quot;SERVER_NAME&quot;] + &quot;:&quot; + $request.servervariables[&quot;SERVER_PORT&quot;] + &quot;/$virtualdirectory/&quot; + $_.Name; 
      'rss:enclosure@length' = $_.Length;
      'rss:enclosure@type' = &quot;audio/mp3&quot;;
   }
}
%&gt;
</pre>
<p>That is all there is to it. A couple of lines of script produces an RSS formatted feed of data produced by PowerShell.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershellserver.com/automatically-converts-psobjects-to-rss-items/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Secure Copy Protocol (SCP) To Upload and Download Files</title>
		<link>http://www.powershellserver.com/using-secure-copy-protocol-scp-to-upload-and-download-files/</link>
		<comments>http://www.powershellserver.com/using-secure-copy-protocol-scp-to-upload-and-download-files/#comments</comments>
		<pubDate>Wed, 14 Nov 2012 19:01:30 +0000</pubDate>
		<dc:creator>andret</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Technical Notes]]></category>

		<guid isPermaLink="false">http://e2/i/?p=1289</guid>
		<description><![CDATA[When Secure Copy Protocol (SCP) is enabled on the PowerShell Server, an SCP client can connect and upload or download files. Below is a description of a variety of common methods used to send and receive files over SCP with&#8230;]]></description>
			<content:encoded><![CDATA[<p>When Secure Copy Protocol (SCP) is enabled on the PowerShell Server, an SCP client can connect and upload or download files. Below is a description of a variety of common methods used to send and receive files over SCP with the PowerShell Server.</p>
<p><strong><br />
<h4>Enabling SCP</h4>
<p></strong></p>
<p>By default, the PowerShell Server does not allow SCP connections. This is easily enabled in the server interface using the following steps:</p>
<p>On the Connection tab simply check the box that says &#8220;Enable Secure Copy Protocol (SCP) Support&#8221;.<br />
Then click Save Changes and Restart to restart the server with this change.<br />
That is all that is required to enable SCP support. Now you can connect using any of the methods described below.</p>
<p><strong><br />
<h4>SCP From PowerShell Server Cmdlets</h4>
<p></strong></p>
<p>The community edition of NetCmdlets (<a href="http://www.netcmdlets.com" title="netcmdlets.com" target="_blank">netcmdlets.com</a>) are several cmdlets designed to work with PowerShell Server, including Get-PowerShellServerFile and Send-PowerShellServerFile. These two cmdlets will allow you to send and receive files from PowerShell Server when SCP is enabled. The usage is very simple. For example:</p>
<p><strong>Uploading a File</strong></p>
<div class="console">
<pre>PS> Send-PowerShellServerFile -Server YourServer -RemoteFile C:\temp\test.txt 
-LocalFile C:\downloads\test.txt</pre>
</div>
<p><strong>Downloading a File</strong></p>
<div class="console">
<pre>PS> Get-PowerShellServerFile -Server YourServer -RemoteFile C:\uploads\test.txt 
-LocalFile C:\temp\test.txt
</pre>
</div>
<p><strong>Notes:</strong></p>
<p>The default authentication mechanism when using the Send-PowerShellServerFile and Get-PowerShellServerFile cmdlets is GSSAPI using NTLM and Kerberos.</p>
<p>When the client and server machine are on the same domain, and the user is a member of the appropriate security group, this means that no explicit authentication parameters are required. While this is convenient, if you need to use regular password authentication and specify the user and password when connecting this can be done by specifying the AuthMode, User, and Password parameters. For instance:</p>
<div class="console">
<pre>PS> Send-PowerShellServerFile -Server YourServer -AuthMode password -User MyUser
-Password MyPassword -RemoteFile C:\temp\test.txt -LocalFile C:\downloads\test.txt</pre>
</div>
<h4><strong>SCP From Linux</h4>
<p></strong></p>
<p>The command line SCP client in Linux can also be used to send and get files.</p>
<p><strong>Uploading a File</strong></p>
<div class="shell">
<pre>test@server:~/> scp -oUser=DOMAIN\\user ./test.txt hostname:c:\\temp\\test.txt</pre>
</div>
<p><strong>Downloading a File</strong></p>
<div class="shell">
<pre>test@server:~/> scp -oUser=DOMAIN\\user hostname:c:\\temp\\test.txt ./test.txt</pre>
</div>
<p><strong>Notes:</strong></p>
<p>In the above examples two special requirements are demonstrated.</p>
<ul>
<li>When using SCP on Linux and need to authenticate with a windows domain<br /> username you must explicitly set the username using -oUser as above.</li>
<li>Paths containing backslashes must be escaped with another backslash.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.powershellserver.com/using-secure-copy-protocol-scp-to-upload-and-download-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell ASP: Using Invoke-Command with New-PSSession</title>
		<link>http://www.powershellserver.com/using-invoke-command-with-new-pssession/</link>
		<comments>http://www.powershellserver.com/using-invoke-command-with-new-pssession/#comments</comments>
		<pubDate>Wed, 14 Nov 2012 19:00:18 +0000</pubDate>
		<dc:creator>andret</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Technical Notes]]></category>

		<guid isPermaLink="false">http://e2/i/?p=1287</guid>
		<description><![CDATA[In order to use the Invoke-Command with the New-PSSession cmdlet you will need to have the proper credentials set. The credential parameter in Powershell taks a PSCredential object. Normally you would prompt a user to enter the information in a&#8230;]]></description>
			<content:encoded><![CDATA[<p>In order to use the Invoke-Command with the New-PSSession cmdlet you will need to have the proper credentials set.</p>
<p>The credential parameter in Powershell taks a PSCredential object. Normally you would prompt a user to enter the information in a dialog and then save the response as a PSCredential object using the Get-Credential cmdlet. Of course in PowerShell ASP that&#8217;s not an option. We can get around this by just setting the credentials manually in a PowerShell script:</p>
<pre class="brush: powershell; title: ; notranslate">
$securePassword = ConvertTo-SecureString &quot;Password&quot; -AsPlainText -force 
$credential = New-Object System.Management.Automation.PsCredential(&quot;domain\username&quot;,$securePassword)
</pre>
<p>After speicfiying your credentails you can then use them in your call to create a New-PSSession Using the PowerShell script below.</p>
<pre class="brush: powershell; title: ; notranslate">
$session = New-PSSession -computername hostname -credential $cred</pre>
<p>Below is an example of a complete PowerShell ASP page:</p>
<pre class="brush: powershell; html-script: true; title: ; notranslate">

&lt;% 
$securePassword = ConvertTo-SecureString &quot;Password&quot; -AsPlainText -force 
$credential = New-Object System.Management.Automation.PsCredential(&quot;domain\username&quot;,$securePassword)  
$session = New-PSSession -computername hostname -credential $cred 
$command = {ls} 
$res = Invoke-Command -session $session -scriptblock $command 
foreach($item in $res){ 	
	Write-Host(&quot;Mode: &quot; + $item.Mode) 
	Write-Host(&quot;Last Write Time: &quot; + $item.LastWriteTime) 
	Write-Host(&quot;Length: &quot; + $item.Length) 
	Write-Host(&quot;Name: &quot; + $item.Name) 
	Write-Host(&quot;&lt;hr/&gt;&quot;) 
}	 
%&gt; 

</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.powershellserver.com/using-invoke-command-with-new-pssession/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Obtaining current user information in PowerShell Server.</title>
		<link>http://www.powershellserver.com/obtaining-current-user-information-in-powershell-server/</link>
		<comments>http://www.powershellserver.com/obtaining-current-user-information-in-powershell-server/#comments</comments>
		<pubDate>Wed, 14 Nov 2012 18:58:06 +0000</pubDate>
		<dc:creator>andret</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Technical Notes]]></category>

		<guid isPermaLink="false">http://e2/i/?p=1283</guid>
		<description><![CDATA[Depending on your PowerShell Server settings sometimes getting session user information from the server might return unexpected results. For example if you are running your server as a service where &#8220;Isolated Sessions&#8221; are disabled, making the call: PS> [Environment]::GetEnvironmentVariable("UserName") or&#8230;]]></description>
			<content:encoded><![CDATA[<p>Depending on your PowerShell Server settings sometimes getting session user information from the server might return unexpected results. For example if you are running your server as a service where &#8220;Isolated Sessions&#8221; are disabled, making the call:</p>
<div class="shell">
<pre>PS> [Environment]::GetEnvironmentVariable("UserName")</pre>
</div>
<p>or</p>
<div class="shell">
<pre>PS> $env:UserName</pre>
</div>
<p>May return the Machine name instead of the expected Username. The reason for this is that both of those calls check environment variables which may or may not have information on your particular session depending on server settings. Instead use:</p>
<div class="shell">
<pre>PS> [Environment]::UserName</pre>
</div>
<p>This will call the the <em>GetUserName()</em> api, which is aware of your particular session and will return the current user even when Impersonation is active.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershellserver.com/obtaining-current-user-information-in-powershell-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Server vs. PowerShell Remoting</title>
		<link>http://www.powershellserver.com/powershell-server-compared-to-powershell-v2-remoting-via-winrm/</link>
		<comments>http://www.powershellserver.com/powershell-server-compared-to-powershell-v2-remoting-via-winrm/#comments</comments>
		<pubDate>Thu, 30 Aug 2012 23:10:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Technical Notes]]></category>

		<guid isPermaLink="false">http://e2/i/?p=221</guid>
		<description><![CDATA[This article will explain the differences between PowerShell Server, and a remoting alternative: PowerShell Remoting via WinRM. With PowerShell Server, you are not limited to Windows machines and you do not need WinRM or any other software besides the PowerShell Server&#8230;]]></description>
			<content:encoded><![CDATA[<p>This article will explain the differences between <a title="Download" href="http://www.powershellserver.com/download/">PowerShell Server</a>, and a remoting alternative: PowerShell Remoting via WinRM.</p>
<p>With PowerShell Server, you are not limited to Windows machines and you do not need WinRM or any other software besides the PowerShell Server itself and any SSH client. The &#8220;client&#8221; machine (i.e. where the commands are being sent from) can be anything: a Linux machine, a handheld device in the field, your cell phone, a Windows machine, a PHP App, etc. If you are not familiar with SSH (&#8220;Secure Shell&#8221;), it is the most commonly used protocol for remote connections between computers since it is secure and flexible.</p>
<p>The community edition of NetCmdlets(<a href="http://www.netcmdlets.com" title="netcmdlets.com">netcmdlets.com</a>) includes a set of cmdlets designed to connect and execute commands on PowerShell Server. While any SSH client can connect and send commands to the PowerShell Server, these cmdlets bring another level of power to the user by enabling the receipt of actual PSObjects from the PowerShell Server through the SSH connection similar to WinRM remoting. These cmdlets are the Connect-PowerShellServer, Disconnect-PowerShellServer, and Invoke-PowerShellServer cmdlets. The first two are used to create and remove SSH protected runspaces, and the latter is used to execute PowerShell commands over that connection and receive PSObjects back from the PowerShell Server.</p>
<h3>PowerShell Remoting + WinRM</h3>
<p>With PowerShell Remoting via WinRM, you are limited to Windows machines communicating over the web services stack.</p>
<p><strong>Similarities</strong></p>
<ol>
<li>Both allow execution of PowerShell cmdlets on a remote Windows machine.</li>
<li>Both are encrypted and secure. PowerShell server operates over an SSH (Secure Shell) connection and PowerShell Remoting works over HTTPS.</li>
<li>Both require PowerShell to be installed on the remote Windows machine.</li>
<li>Both require security and authentication, albeit in different ways. In both cases a security certificate is used to identify the server. In the case of PowerShell server, connecting users securely authenticate using select Windows security groups defined on the server machine. When using WinRM, by default the credentials are the currently logged in user but these can also be changed to use a remote account.</li>
</ol>
<p><strong>Differences</strong></p>
<ol>
<li>As mentioned before, both require PowerShell on the remote machine but each requires a different &#8220;server piece&#8221;. PowerShell Remoting requires WinRM on the remote machine, and PowerShell Server requires itself to be installed on the remote machine.</li>
<li>The use of PowerShell Remoting requires PowerShell and WinRM to be installed on the client machine (the machine where the commands are being sent from). There is essentially no client-side software requirement for using PowerShell Server since SSH clients exist virtually everywhere: Windows, *nix, mobile devices, Web Applications, etc. As long as it can establish an SSH connection, a client machine can connect and cmdlets can be executed.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.powershellserver.com/powershell-server-compared-to-powershell-v2-remoting-via-winrm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enable FIPS 140-2 cryptography compliance.</title>
		<link>http://www.powershellserver.com/enable-fips-140-2-cryptography-compliance/</link>
		<comments>http://www.powershellserver.com/enable-fips-140-2-cryptography-compliance/#comments</comments>
		<pubDate>Thu, 30 Aug 2012 23:10:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Technical Notes]]></category>

		<guid isPermaLink="false">http://e2/i/?p=225</guid>
		<description><![CDATA[PowerShell Server complies with Federal Information Processing Standards (FIPS 140-2) cryptography requirements, enabling governments agencies to meet the strict security and compliance guidelines defined by NIST. This article will explain how to enable FIPS compliant mode for PowerShell Server. There are&#8230;]]></description>
			<content:encoded><![CDATA[<p>PowerShell Server complies with Federal Information Processing Standards (FIPS 140-2) cryptography requirements, enabling governments agencies to meet the strict security and compliance guidelines defined by NIST. This article will explain how to enable FIPS compliant mode for <a title="Download" href="http://www.powershellserver.com/?page_id=28">PowerShell Server</a>.</p>
<p>There are two steps to enabling FIPS compliant mode in the PowerShell Server.</p>
<ol>
<li><a href="#FIPSonOS">Enable FIPS mode on the Operating System</a></li>
<li><a href="#FIPSonPSServer">Enable FIPS mode for the PowerShell Server</a></li>
</ol>
<p>After performing both steps be sure to stop and restart the PowerShell Server for changes to take effect.</p>
<p>&nbsp;<br />
<a id="FIPSonOS"></a><br />
<h3>Enable FIPS mode on the Operating System</h3>
<p>To enable FIPS mode on the Operating System you will need to set the &#8220;System cryptography: Use FIPS compliant algorithms for encryption, hashing, and signing&#8221; setting. This can be enabled via a Group Policy, or via the Local Security Policy. For simplicity this article will only discuss enabling this setting in the Local Security Policy. Follow the steps below to enable this setting.</p>
<ol>
<li>Open the Control Panel</li>
<li>Within the Control Panel select Administrative Tools</li>
<li>Select Local Security Policy. This will open an editor.</li>
<li>In the editor expand the tree on the left to &#8220;Security Settings | Local Policies | Security Options&#8221;</li>
<li>In the policy list on the right find &#8220;System cryptography: Use FIPS compliant algorithms for encryption, hashing, and signing&#8221;. Double click this policy and change the value from &#8220;Disabled&#8221; to &#8220;Enabled&#8221;.</li>
</ol>
<p>Your setting should look like this:</p>
<p><center><br />
<img src="http://www.powershellserver.com/wp-content/uploads/2012/08/powershellssh-fips-1.png" alt="" title="powershellssh-fips-1" width="560" height="268" class="aligncenter wp-image-1426" /><br />
</center>This will enable FIPS mode on the system. For more information on the effects of this setting see<a href="http://support.microsoft.com/kb/811833" target="_blank">http://support.microsoft.com/kb/811833</a>.</p>
<p>&nbsp;<br />
<a id="FIPSonPSServer"></a><br />
<h3>Enable FIPS mode on the PowerShell Server</h3>
<p>To enable FIPS mode on the PowerShell server you will need to add a new registry key value to inform the PowerShell Server to run in FIPS mode. To do this follow these steps:</p>
<ol>
<li>Launch the registry editor (regedit)</li>
<li>Browse to the path:
<pre>HKEY_LOCAL_MACHINE\SOFTWARE\nsoftware\PowerShellServer</pre>
</li>
<li>Add a new DWORD value named &#8220;UseFIPSCompliantAPI&#8221;</li>
<li>Set the value data of the new DWORD value to &#8220;1&#8243; to enable FIPS compliant mode in the PowerShell Server</li>
</ol>
<p>Note: You may disable FIPS compliant mode by setting UseFIPSCompliant to &#8220;0&#8243; or by simply deleting the DWORD value.</p>
<h4>After performing both steps be sure to stop and restart the PowerShell Server for changes to take effect.</h4>
]]></content:encoded>
			<wfw:commentRss>http://www.powershellserver.com/enable-fips-140-2-cryptography-compliance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
