Remote PS Scripting Question/Problem

BatchPatch Forums Home Forums BatchPatch Support Forum Remote PS Scripting Question/Problem

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #8790
    kscurloc
    Participant

    I’m new to BatchPatch and even more so to PowerShell scripting. So I apologize in advance for my lack of knowledge on the subject.

    I’m trying to clean out all my server’s event logs. I can achieve I can run this directly on each server without issue:

    wevtutil el | Foreach-Object {Write-Host “Clearing $_”; wevtutil cl “$_”}

    I also know you need to put this in front of it first, with the above surrounded by double quotes.

    cmd.exe /c echo . | powershell.exe -ExecutionPolicy Bypass -command

    But I’m not sure what the entire syntax needs to look like when I put it into remote command 3. I think I’m having issues using double quote vs single quote, etc. Can anyone help? Thanks in advance!

    #10028
    kscurloc
    Participant

    I was able to figure this out… here’s what I did:

    cmd.exe /c echo . | powershell.exe -ExecutionPolicy Bypass -command “wevtutil el | Foreach-Object {Write-Host “Clearing $_”; wevtutil cl “$_”}”

    #10029
    doug
    Moderator

    Glad you got it figured out. This should also work:

    powershell.exe -command "wevtutil el | Foreach-Object {Write-Host "Clearing $_"; wevtutil cl "$_"}"

    #10030
    kscurloc
    Participant

    So that’s a good question, now that you mention it. =)

    In your tutorials, it says to use the “cmd.exe /c echo . | powershell.exe -ExecutionPolicy Bypass -command”. Why is this necessary, or isn’t it?

    Thanks again… really like this tool!!!

    #10031
    doug
    Moderator

    Some things have changed since that tutorial was written. In some cases it may be necessary to use the syntax from the tutorial whereas in other cases it might not be needed anymore.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.