<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic When trying to run a PowerShell script with New-PSDrive and PSCredentials, why am I getting the following error?: &amp;quot;A specified logon session does not exist. It may already have been terminated&amp;quot; in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/When-trying-to-run-a-PowerShell-script-with-New-PSDrive-and/m-p/406482#M72136</link>
    <description>&lt;P&gt;I have Windows Server 2008 R2 SP1.&lt;/P&gt;

&lt;P&gt;I'm able to run a ps1 script with Get-Process just fine.&lt;/P&gt;

&lt;P&gt;But, when I try to use New-PSDrive with PSCredentials, I get an error. I tried to google and got some references to remote execution policies etc  (for example: Enable-WSManCredSSP Server and Enable-PSRemoting) and I tried to enable those as well, but it did not help.&lt;/P&gt;

&lt;P&gt;As far as I have understood, the Splunk forwarder is running a 'wrapper' script from splunk_home/bin/splunk-powershell.ps1, which has a ref:&lt;/P&gt;

&lt;H1&gt;this script is launched with the following command from splunk-powershell.exe:&lt;/H1&gt;

&lt;H1&gt;powershell.exe -command  "&amp;amp; {get-content "C:\Users\AppData\Local\Temp\input.tmp" | "c:\splunk_build\bin\splunk-powershell.ps1"  }"&lt;/H1&gt;

&lt;P&gt;I'm wondering is there any way to manually mimic the forwarder execution from the cmd with some proper inputs?&lt;/P&gt;

&lt;P&gt;My configs are below:&lt;/P&gt;

&lt;P&gt;inputs.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [powershell://CIFSUsage]
    script = . "$SplunkHome\etc\apps\myapp\scripts\getCIFSUsage.ps1"
    schedule = 0 * * * * ?
    sourcetype = CIFSUsage
    index = sandbox
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS1-script:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$User = "looser"
$PWord = ConvertTo-SecureString -String "verystrongandlongfoobarpwdhere" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
New-PSDrive -Name X -PSProvider FileSystem -Root \\cifs-server1\mount -Credential $Credential -Persist | Select-Object Used,Free
# Disconnect the mount
Remove-PSDrive X
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ERROR User script exception: : A specified logon session does not exist. It may already have been terminated
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 03 Oct 2018 17:58:37 GMT</pubDate>
    <dc:creator>JykkeDaMan</dc:creator>
    <dc:date>2018-10-03T17:58:37Z</dc:date>
    <item>
      <title>When trying to run a PowerShell script with New-PSDrive and PSCredentials, why am I getting the following error?: "A specified logon session does not exist. It may already have been terminated"</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/When-trying-to-run-a-PowerShell-script-with-New-PSDrive-and/m-p/406482#M72136</link>
      <description>&lt;P&gt;I have Windows Server 2008 R2 SP1.&lt;/P&gt;

&lt;P&gt;I'm able to run a ps1 script with Get-Process just fine.&lt;/P&gt;

&lt;P&gt;But, when I try to use New-PSDrive with PSCredentials, I get an error. I tried to google and got some references to remote execution policies etc  (for example: Enable-WSManCredSSP Server and Enable-PSRemoting) and I tried to enable those as well, but it did not help.&lt;/P&gt;

&lt;P&gt;As far as I have understood, the Splunk forwarder is running a 'wrapper' script from splunk_home/bin/splunk-powershell.ps1, which has a ref:&lt;/P&gt;

&lt;H1&gt;this script is launched with the following command from splunk-powershell.exe:&lt;/H1&gt;

&lt;H1&gt;powershell.exe -command  "&amp;amp; {get-content "C:\Users\AppData\Local\Temp\input.tmp" | "c:\splunk_build\bin\splunk-powershell.ps1"  }"&lt;/H1&gt;

&lt;P&gt;I'm wondering is there any way to manually mimic the forwarder execution from the cmd with some proper inputs?&lt;/P&gt;

&lt;P&gt;My configs are below:&lt;/P&gt;

&lt;P&gt;inputs.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [powershell://CIFSUsage]
    script = . "$SplunkHome\etc\apps\myapp\scripts\getCIFSUsage.ps1"
    schedule = 0 * * * * ?
    sourcetype = CIFSUsage
    index = sandbox
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS1-script:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$User = "looser"
$PWord = ConvertTo-SecureString -String "verystrongandlongfoobarpwdhere" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
New-PSDrive -Name X -PSProvider FileSystem -Root \\cifs-server1\mount -Credential $Credential -Persist | Select-Object Used,Free
# Disconnect the mount
Remove-PSDrive X
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ERROR User script exception: : A specified logon session does not exist. It may already have been terminated
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Oct 2018 17:58:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/When-trying-to-run-a-PowerShell-script-with-New-PSDrive-and/m-p/406482#M72136</guid>
      <dc:creator>JykkeDaMan</dc:creator>
      <dc:date>2018-10-03T17:58:37Z</dc:date>
    </item>
  </channel>
</rss>

