Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigureRemotingForAnsible.ps1 fails when called from github with Invoke-Expression #20512

Closed
lcostea opened this issue Jan 20, 2017 · 2 comments · Fixed by #20527
Closed

ConfigureRemotingForAnsible.ps1 fails when called from github with Invoke-Expression #20512

lcostea opened this issue Jan 20, 2017 · 2 comments · Fixed by #20527
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug. windows Windows community

Comments

@lcostea
Copy link

lcostea commented Jan 20, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ConfigureRemotingForAnsible.ps1

ANSIBLE VERSION
2.1.2
OS / ENVIRONMENT

Windows Server 2012
Windows Server 2016

SUMMARY

Run this in a powershell console

Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1'))

The error is:

New-EventLog : The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:124 char:47
New-EventLog -LogName Application -Source $EventSource
~~~~~~~~~~~~
CategoryInfo : InvalidData: (:) [New-EventLog], ValidationMetadataException
FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.NewEventLogCommand

And points to the problem, $MyInvocation.MyCommand.Name is an empty string when called like this

$EventSource = $MyInvocation.MyCommand.Name
If ($EventSource -eq $Null)
{
    $EventSource = "Powershell CLI"
}

so the above could be easily changed to

$EventSource = $MyInvocation.MyCommand.Name
If ([String]::IsNullOrEmpty($EventSource))
{
    $EventSource = "Powershell CLI"
} 
@ansibot ansibot added affects_2.1 This issue/PR affects Ansible v2.1 bug_report needs_triage Needs a first human triage before being processed. labels Jan 20, 2017
@dagwieers
Copy link
Contributor

dagwieers commented Jan 20, 2017

Can you try to do:

$EventSource = $MyInvocation.MyCommand.Name
If (-Not $EventSource)
{
    $EventSource = "Powershell CLI"
}

That should work the same. Let me know, I will make a PR for this.

Thanks for reporting !

@lcostea
Copy link
Author

lcostea commented Jan 20, 2017

Yes, this also worked

Thanks

@s-hertel s-hertel added windows Windows community and removed needs_triage Needs a first human triage before being processed. labels Jan 20, 2017
dagwieers added a commit to dagwieers/ansible that referenced this issue Jan 20, 2017
A small fix suggested by a user for running ConfigureRemotingForAnsible.

This fixes ansible#20512
mattclay pushed a commit that referenced this issue Jan 26, 2017
A small fix suggested by a user for running ConfigureRemotingForAnsible.

This fixes #20512
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug. windows Windows community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants