I want to enabled winrm CredSSP from remotely to run the ansible script.
if I run this commands one by one in powershell window it works. but when I put all these in powershell script it not working.
Enter-PSSession -ComputerName $ComputerName
Enable-WSManCredSSP -Role Server -Force
Set-Item -Path "WSMan:\localhost\Service\Auth\CredSSP" -Value $true
Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1'))
Exit-PSSession
Any help to make this work as powershell script?
Updated
I copied the file remote server c:\temp dir. when I run the below code its giving this error.
Invoke-Command -session $session -Command {powershell.exe -NoProfile -ExecutionPolicy ByPass -File c:\temp\ConfigureRemotingForAnsible.ps1 -CertValidityDays 3650 -EnableCredSSP -ForceNewSSLCert -Verbose}
Error message
VERBOSE: Enabling basic auth support.
Set-Item : The config setting Basic cannot be changed because is controlled by policies. The
policy would need to be set to "Not Configured" in order to change the config setting.
At C:\temp\ConfigureRemotingForAnsible.ps1:384 char:9
+ Set-Item -Path "WSMan:\localhost\Service\Auth\Basic" -Value $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-Item], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.SetI
temCommand
I know this error message coming from the script, any help to fix this error message?
Thanks SR