Stuck in String or wrong data being passed

Tagged: 

This topic contains 4 replies, has 2 voices, and was last updated by  rambog cnonline.net 3 years, 11 months ago.

  • Author
    Posts
  • #10164

    rambog cnonline.net
    Participant

    I am attempting to gather the system logs from a license server to eventually get the IP addresses of all its clients. The commands I would like to execute are:
    #command 1
    $c=get-eventlog -Computer Serverx -LogName "KeyManagement Service" -After (Get-Date).AddDays(-7).ToShortDateString()|Where {$_.eventid -eq "12290"}
    #command 2
    $e=$c|%{$stuff=[regex]::split($_.ReplacementStrings,',');Write-Output "$($stuff[2])"}
    #command 3
    $g=$e|%{[Net.DNS]::GetHostAddresses('$_')|Select-Object -ExpandProperty IPAddressToString}

    Unfortunately, the output of the third command is:
    Exception calling "GetHostAddresses" with "1" argument(s): "No such host is kno
    wn"
    At line:1 char:36
    + $g=$e|%{[Net.DNS]::GetHostAddresses < <<< ('$_')|Select-Object -ExpandProperty IPAddressToString} + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException This is because, for some reason, it does not accept what is being passed to it as a server name. When I explicitly input the server name into command 3, I get: PS C:\> $g=[Net.DNS]::GetHostAddresses('clientserver.domain.com')|Select-Object -ExpandProperty IPAddressToString
    PS C:\> $g
    192.168.32.60

    How do I amend command 2 or 3 to get a list of IP addresses?

    BTW,
    Here is the data type for command 1,
    PS C:\> $c.GetType()

    IsPublic IsSerial Name BaseType
    ——– ——– —- ——–
    True True Object[] System.Array

    PS C:\> $c|gm

    TypeName: System.Diagnostics.EventLogEntry#Key Management Service/KmsRequest
    s/1073754114

    Name MemberType Definition
    —- ———- ———-
    Disposed Event System.EventHandler Disposed(System...
    CreateObjRef Method System.Runtime.Remoting.ObjRef Crea...
    Dispose Method System.Void Dispose()
    Equals Method bool Equals(System.Diagnostics.Even...
    GetHashCode Method int GetHashCode()
    GetLifetimeService Method System.Object GetLifetimeService()
    GetType Method type GetType()
    InitializeLifetimeService Method System.Object InitializeLifetimeSer...
    ToString Method string ToString()
    Category Property System.String Category {get;}
    CategoryNumber Property System.Int16 CategoryNumber {get;}
    Container Property System.ComponentModel.IContainer Co...
    Data Property System.Byte[] Data {get;}
    EntryType Property System.Diagnostics.EventLogEntryTyp...
    Index Property System.Int32 Index {get;}
    InstanceId Property System.Int64 InstanceId {get;}
    MachineName Property System.String MachineName {get;}
    Message Property System.String Message {get;}
    ReplacementStrings Property System.String[] ReplacementStrings ...
    Site Property System.ComponentModel.ISite Site {g...
    Source Property System.String Source {get;}
    TimeGenerated Property System.DateTime TimeGenerated {get;}
    TimeWritten Property System.DateTime TimeWritten {get;}
    UserName Property System.String UserName {get;}
    EventID ScriptProperty System.Object EventID {get=$this.ge...

    PS C:\>$c[0]|fl *

    EventID : 12290
    MachineName : licensesrvr1.domain.com
    Data : {0, 0, 4, 0...}
    Index : 221478
    Category : (0)
    CategoryNumber : 0
    EntryType : Information
    Message : The description for Event ID '1073754114' in Source 'KmsRe
    quests' cannot be found. The local computer may not have
    the necessary registry information or message DLL files to
    display the message, or you may not have permission to ac
    cess them. The following information is part of the event
    :'0x0,25,ClientServer.domain.com,9a81c9be-d032-47ca-8eb0-7
    2a644477b4e,2013/09/16 12:30,1,2,43200,ae2ee509-1b34-41c0-
    acb7-6d4650168915', '0x0', '25', 'ClientServer.domain.com'
    , '9a81c9be-d032-47ca-8eb0-72a644477b4e', '2013/09/16 12:3
    0', '1', '2', '43200', 'ae2ee509-1b34-41c0-acb7-6d46501689
    15'
    Source : KmsRequests
    ReplacementStrings : {0x0,25,ClientServer.domain.com,9a81c9be-d032-47ca-8eb0-72
    a644477b4e,2013/09/16 12:30,1,2,43200,ae2ee509-1b34-41c0-a
    cb7-6d4650168915, 0x0, 25, ClientServer.domain.com...}
    InstanceId : 1073754114
    TimeGenerated : 9/16/2013 8:30:24 AM
    TimeWritten : 9/16/2013 8:30:24 AM
    UserName :
    Site :
    Container :

    And here is the information type for command 2,

    PS C:\> $e.gettype()

    IsPublic IsSerial Name BaseType
    ——– ——– —- ——–
    True True Object[] System.Array

    PS C:\> $e|gm

    TypeName: System.String

    Name MemberType Definition
    —- ———- ———-
    Clone Method System.Object Clone()
    CompareTo Method int CompareTo(System.Object value), i...
    Contains Method bool Contains(string value)
    CopyTo Method System.Void CopyTo(int sourceIndex, c...
    EndsWith Method bool EndsWith(string value), bool End...
    Equals Method bool Equals(System.Object obj), bool ...
    GetEnumerator Method System.CharEnumerator GetEnumerator()
    GetHashCode Method int GetHashCode()
    GetType Method type GetType()
    GetTypeCode Method System.TypeCode GetTypeCode()
    IndexOf Method int IndexOf(char value), int IndexOf(...
    IndexOfAny Method int IndexOfAny(char[] anyOf), int Ind...
    Insert Method string Insert(int startIndex, string ...
    IsNormalized Method bool IsNormalized(), bool IsNormalize...
    LastIndexOf Method int LastIndexOf(char value), int Last...
    LastIndexOfAny Method int LastIndexOfAny(char[] anyOf), int...
    Normalize Method string Normalize(), string Normalize(...
    PadLeft Method string PadLeft(int totalWidth), strin...
    PadRight Method string PadRight(int totalWidth), stri...
    Remove Method string Remove(int startIndex, int cou...
    Replace Method string Replace(char oldChar, char new...
    Split Method string[] Split(Params char[] separato...
    StartsWith Method bool StartsWith(string value), bool S...
    Substring Method string Substring(int startIndex), str...
    ToCharArray Method char[] ToCharArray(), char[] ToCharAr...
    ToLower Method string ToLower(), string ToLower(Syst...
    ToLowerInvariant Method string ToLowerInvariant()
    ToString Method string ToString(), string ToString(Sy...
    ToUpper Method string ToUpper(), string ToUpper(Syst...
    ToUpperInvariant Method string ToUpperInvariant()
    Trim Method string Trim(Params char[] trimChars),...
    TrimEnd Method string TrimEnd(Params char[] trimChars)
    TrimStart Method string TrimStart(Params char[] trimCh...
    Chars ParameterizedProperty char Chars(int index) {get;}
    Length Property System.Int32 Length {get;}

    PS C:\documents and settings\xx48555\My Documents\scripts> $e[0]|fl *
    ClientServer.domain.com

  • #10166

    Richard Siddaway
    Moderator

    $g=$e|%{[Net.DNS]::GetHostAddresses(‘$_’)|Select-Object -ExpandProperty IPAddressToString}

    has single quotes (highlighted)
    You can't substitute into single quotes – they have to be double quotes

  • #10169

    rambog cnonline.net
    Participant

    Richard,
    I still get the same result by using double quotes.

    PS C:\> $g=$e|%{[Net.DNS]::GtHostAddresses("$_")|Select-Object -ExpandProperty IPAddressToString}
    Exception calling "GetHostAddresses" with "1" argument(s): "No such host is known"
    At line:1 char:36
    + $g=$e|%{[Net.DNS]::GetHostAddresses <<<< ("$_")|Select-Object -ExpandProperty IPAddressToString} + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException Exception calling "GetHostAddresses" with "1" argument(s): "No such host is kno wn" At line:1 char:36 + $g=$e|%{[Net.DNS]::GetHostAddresses <<<< ("$_")|Select-Object -ExpandProperty IPAddressToString} + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException Exception calling "GetHostAddresses" with "1" argument(s): "No such host is kno wn" At line:1 char:36 + $g=$e|%{[Net.DNS]::GetHostAddresses <<<< ("$_")|Select-Object -ExpandProperty IPAddressToString} + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

  • #10174

    Richard Siddaway
    Moderator

    try this

    PS C:\> $g=$e|%{[Net.DNS]::GtHostAddresses(“$($_)”)|Select-Object -ExpandProperty IPAddressToString}

  • #10178

    rambog cnonline.net
    Participant

    Richard,
    You were right..I had some entries in my output that DNS could not resolve but the majority were resolvable and contained in my output. Thank you for your help.

You must be logged in to reply to this topic.