Powershell

Sara 401 Reputation points
2021-07-10T08:47:31.943+00:00

I have the below code using Get-Winevent and running into the below error, Any idea what am I missing here?

ComputerName = $Server.Name
PasswordExpiration = [datetime]::FromFileTime($Server."ms-Mcs-AdmPwdExpirationTime")
line : 148 PasswordLastSet = (Get-WinEvent -ProviderName AdmPwd -ComputerName $Server.name | Where-Object {($.ID -eq 12)} | Sort-Object $.TimeCreated | Select-Object -Last1).TimeCreated

Error msg:
Get-WinEvent : The RPC server is unavailable
At \po\scripts\New-LSReport\New-LSReport.ps1:148 char:24

  • ... dLastSet = (Get-WinEvent -ProviderName AdmPwd -ComputerName $Server.n ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (:) [Get-WinEvent], EventLogException
  • FullyQualifiedErrorId : System.Diagnostics.Eventing.Reader.EventLogException,Microsoft.PowerShell.Commands.GetWi
    nEventCommand
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 31,976 Reputation points
    2021-07-10T13:56:15.397+00:00

    Please use the "Code Sample" icon to post your actual script. (The 101010 icon.)

    "RPC server unavailable" typically means that you've got a bad server name or are getting blocked by a firewall.

    It looks like you are setting $computername to $server.name but you are still using $server.name in the Get-WinEvent call. Was that intentional? Do you have a valid server name in those variables?

    0 comments No comments