locked
A beginner to powershell with a problem retrieving a paramater RRS feed

  • Question

  • I have a variables but the key is readable but the value sould be a string how can a retrieve that string.

    PS C> $Global:Server.Jobs.getAll()[5].Variables[0]

    Key      ValueObject
    ---      -----------
    Database {212, 60, 249, 246...}


    PS C> $Global:Server.Jobs.getAll()[5].Variables | get-member


       TypeName: VisualCron.JobVariableClass

    Name         MemberType Definition
    ----         ---------- ----------
    CalcVariable Method     string CalcVariable()
    Clone        Method     System.Object Clone(), System.Object ICloneable.Clone()
    CloneType    Method     VisualCron.JobVariableClass CloneType()
    Equals       Method     bool Equals(System.Object obj)
    GetHashCode  Method     int GetHashCode()
    GetType      Method     type GetType()
    ToString     Method     string ToString()
    Key          Property   string Key {get;set;}
    ValueObject  Property   byte[] ValueObject {get;set;}

    Wednesday, February 5, 2020 11:29 AM

All replies

  •  $Global:Server.Jobs.getAll()[5].Variables[0].ValueObject


    \_(ツ)_/

    Wednesday, February 5, 2020 11:55 AM
  • When i $Global:Server.Jobs.getAll()[5].Variables[0].ValueObject i get some numbers not text what i am expecting


    PS > $Global:Server.Jobs.getAll()[5].Variables[0].ValueObject.ToString 

    OverloadDefinitions
    -------------------
    string ToString()

    -------------------------------------------------------------------------------------------------------------------
    PS > $Global:Server.Jobs.getAll()[5].Variables[0].ValueObject | get-member


       TypeName: System.Byte

    Name        MemberType Definition
    ----        ---------- ----------
    CompareTo   Method     int CompareTo(System.Object value), int CompareTo(byte value), int IComparable.CompareTo(System.Object obj), int IComparable[byte].CompareTo(byte other)
    Equals      Method     bool Equals(System.Object obj), bool Equals(byte obj), bool IEquatable[byte].Equals(byte other)
    GetHashCode Method     int GetHashCode()
    GetType     Method     type GetType()
    GetTypeCode Method     System.TypeCode GetTypeCode(), System.TypeCode IConvertible.GetTypeCode()
    ToBoolean   Method     bool IConvertible.ToBoolean(System.IFormatProvider provider)
    ToByte      Method     byte IConvertible.ToByte(System.IFormatProvider provider)
    ToChar      Method     char IConvertible.ToChar(System.IFormatProvider provider)
    ToDateTime  Method     datetime IConvertible.ToDateTime(System.IFormatProvider provider)
    ToDecimal   Method     decimal IConvertible.ToDecimal(System.IFormatProvider provider)
    ToDouble    Method     double IConvertible.ToDouble(System.IFormatProvider provider)
    ToInt16     Method     int16 IConvertible.ToInt16(System.IFormatProvider provider)
    ToInt32     Method     int IConvertible.ToInt32(System.IFormatProvider provider)
    ToInt64     Method     long IConvertible.ToInt64(System.IFormatProvider provider)
    ToSByte     Method     sbyte IConvertible.ToSByte(System.IFormatProvider provider)
    ToSingle    Method     float IConvertible.ToSingle(System.IFormatProvider provider)
    ToString    Method     string ToString(), string ToString(string format), string ToString(System.IFormatProvider provider), string ToString(string format, System.IFormatProvider provider), string IFormattable.ToString(string format, ...
    ToType      Method     System.Object IConvertible.ToType(type conversionType, System.IFormatProvider provider)
    ToUInt16    Method     uint16 IConvertible.ToUInt16(System.IFormatProvider provider)
    ToUInt32    Method     uint32 IConvertible.ToUInt32(System.IFormatProvider provider)
    ToUInt64    Method     uint64 IConvertible.ToUInt64(System.IFormatProvider provider)


    Wednesday, February 5, 2020 1:36 PM
  • The property is not a string.  It is a byte array.  What do you expect it to be?  A byte array can be almost anything.  It can only be turned into a string if it is a string represented as a byte array.

    ValueObject  Property   byte[] ValueObject {get;set;}


    \_(ツ)_/

    Wednesday, February 5, 2020 1:40 PM
  • PS C:\scripts> $bytes = [byte[]]'hello world'.ToCharArray()
    PS C:\scripts> [char[]]$bytes -join ''
    hello world
    PS C:\scripts>
    


    \_(ツ)_/

    Wednesday, February 5, 2020 1:43 PM