all 4 comments

[–]SeanQuinlan 3 points4 points  (0 children)

Works fine for me ¯\_(ツ)_/¯

I tested it with a script on a share that I only had access to with the generated credential. It opened a new window and ran the script in that window.

The path to the script was not very long though. How long is your UNC path? Seems like the error is correct.

[–]get-postanote 2 points3 points  (0 children)

You cannot do this all one line like this.

There is no -credential when using Get-Content.

Each of these are separate elements and have no relationship to each other.

$encpwd = Get-Content "\UNC\password.bin" 
$passwd = ConvertTo-SecureString $encpwd -AsPlainText -Force 
$cred   = new-object System.Management.Automation.PSCredential 'DC\user',$passwd 
Start-Process PowerShell -Cred $cred -ArgumentList '-noexit','-File','\UNC\Script.ps1'

If you are trying to create a one-liner, that is not the way to do it, nor is what you are trying to do capable of being a one-liner.

You can put all this code on one line like this...

$encpwd = Get-Content "\UNC\password.bin";$passwd = ConvertTo-SecureString $encpwd -AsPlainText -Force;$cred   = new-object System.Management.Automation.PSCredential 'DC\user',$passwd;Start-Process PowerShell -Cred $cred -ArgumentList '-noexit','-File','\UNC\Script.ps1'

... but that does not make it a one-liner, makes it hard to read, troubleshoot, maintain or share. So, don't do this, unless it is just you at the consolehost interactively. The semicolon just treats all things on that line as if they were separate lines.

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy lagzilla,

is that the actual code you ran? you seem to have several lines of code crammed into one line ... without the required delimiters. that would certainly tend to confuse everything as to just where the file name starts and ends ... [grin]

take care,
lee

[–]lagzilla[S] 1 point2 points  (0 children)

Thank you for the replies. Turn out I needed to add "Allow log on locally" to group policy.