i am trying to roll out user environment variables to a newly created user after its creation. to do this i want to do
Invoke-Command -ComputerName localhost -Credentials $credentials
however if i do so, i get an error message :
[localhost] Beim Verbinden mit dem Remoteserver "localhost" ist folgender Fehler aufgetreten: Zugriff verweigert Weitere Informationen finden Sie im Hilfethema
"about_Remote_Troubleshooting".
+ CategoryInfo : OpenError: (localhost:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken
my full script i try to execute is this:
Write-Host seting up Environment
$usernameIA = "NameOfUser"
$password = 'ThePassword'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($usernameIA, $securePassword)
Invoke-Command -ComputerName localhost -Credential $credential -ScriptBlock $ScriptBlock
i already figured out that i have to start WinRM service at least on some machines so i can do it that way, but this has only brougt me to that error message...