Powershell remoting – Policy does not allow the delegation of user credentials

Do the following on the server: Enable-WSManCredSSP -Role Server Do the following on the client: set-item wsman:localhost\client\trustedhosts -value * Enable-WSManCredSSP -Role Client –DelegateComputer * Use gpedit.msc on the client to enable Delegating Fresh Credentials to WSMAN/*: Expand Local Computer Policy, expand Computer Configuration, expand Administrative Templates, expand System, and then click Credential Delegation. In the … Read more

Stop Powershell from exiting

You basically have 3 options to prevent the PowerShell Console window from closing, that I describe in more detail on my blog post. One-time Fix: Run your script from the PowerShell Console, or launch the PowerShell process using the -NoExit switch. e.g. PowerShell -NoExit “C:\SomeFolder\SomeScript.ps1” Per-script Fix: Add a prompt for input to the end … Read more

How do I include a locally defined function when using PowerShell’s Invoke-Command for remoting?

You need to pass the function itself (not a call to the function in the ScriptBlock). I had the same need just last week and found this SO discussion So your code will become: Invoke-Command -ScriptBlock ${function:foo} -argumentlist “Bye!” -ComputerName someserver.example.com -Credential someuser@example.com Note that by using this method, you can only pass parameters into … Read more

how to edit a file in powershell remoting session (powershell)

If you are using Powershell 5, you can use command called PSEdit. It only works from ISE. So first, open PowerShell ISE Then open remote session to the remote computer using Enter-PSSession Then edit the file using PsEdit ‘filename’ The remote file will be opened in a new tab in your (local) ISE window. Actually … Read more

How to import custom PowerShell module into the remote session?

There were some great comments to the question, and I’ve spent some time investigating various ways to approach the problem. To begin with, what I’ve initially asked for is not possible. I mean, if you go the module way, then the module should be physically present on a target machine to be able to Import-Module … Read more

Enter-PSSession is not working in my Powershell script

Not sure if it is a timing issue. I suspect it’s more like Enter-PSSession is invoking something like a nested prompt and your subsequent commands are not executing within it. Anyway, I believe Enter/Exit-PSSession is meant for interactive use – not scripting use. For scripts use New-PSSession and pass that session instance into Invoke-Command e.g.: … Read more

Using PowerShell credentials without being prompted for a password

The problem with Get-Credential is that it will always prompt for a password. There is a way around this however but it involves storing the password as a secure string on the filesystem. The following article explains how this works: Using PSCredentials without a prompt In summary, you create a file to store your password … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)