Ramon TAN

Forum Replies Created

Viewing 15 posts - 106 through 120 (of 138 total)
  • Author
    Posts
  • in reply to: How do I get the $RESULT from this function #105779
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Thank you Sam, but when I tried to “get” the [DateTime] as follows:

    $V = Test-DateTimePattern …. (parms omitted)

    I got an error message that says I cannot assign $True to $V. It seems to me there is a chicken-and-egg situation here:

    1 – to see first if my inputs were valid, I must have a IF statement on $V after the method call.
    2 – If valid, then I access $V as the “returned valid parse”, i.e., the desired [dateTime] object … but in this case I get an error because $V according to PS is boolean.

    My question again is, How can I “get to” the RETURNED [DateTime] object? Where is it sitting? Is it via assignment to a variable? I know I get the correct [DateTime] returned when it prints on the screen but that’s when I run it directly. What I want is to get hold of that [DateTime] object so I can perform more validity checks such as how old, etc.
    Hope this clarifies my dilemma/question/lack of understanding.
    Many thanks.

    in reply to: CHAR and STRING classes – how to be consistent #105043
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    You hit on the crux of the issue: I reversed / confused the check of whether a single character
    was one of several characters in the “valid list”,i.e., I meant to have

        $ValidList = '0123456789'
        $singlechar = ...  # ---- 
        $a = $ValidList.Contains($singlechar)
        If ($a -EQ $True) { # $singlechar is valid numeric char ... }
    

    But instead, I wrote the opposite: reversing $ValidList with $singlechar, which as you pointed out, makes no sense.
    Many thanks Mr Sallow for taking the time to help me realize where I went wrong.
    Best,

    in reply to: The InputBox function #104920
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    OK, sincere thanks … this is very useful to me.

    in reply to: Can a hash table be inside a variable? #104836
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Many thanks Mr Sallow. I have just tried it and it works beautifully. The documentation suggests the command can do a lot more, I’m happy to have come across this piece of know-how.

    My sincerest gratitude for your help.
    Best,

    in reply to: Can a hash table be inside a variable? #104828
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Hello,

    Thanks for your reply. The Contents of my hash table are sitting in an external file.
    Short of typing the contents (rather long, about 500 entries) of that file into my PS script, I would like to know if those contents can be read into a variable as described in my initial post.

    in reply to: Going from Get-ACEData to CSV #104699
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Fantastic, this is very useful.
    My sincerest thanks Mr. Simmers.

    in reply to: Checking for NULL in PS #104011
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Thank you all Messrs. Barnetson, Sallow and Soyk. Your replies shed a lot of light and provide many interesting highlights. I have performed your examples hands-on, and I am extremely grateful for your posts. In the course of my “immersion” with NULL, I came across a very informative and interesting site/post, with a short article on the same subject:
    https://www.codykonior.com/2013/10/17/checking-for-null-in-powershell/
    I thought it interesting to extract that portion of the article to share this author’s “all in one” NULL function:
    #—————————————————–
    function IsNull($objectToCheck) {
    if ($objectToCheck -eq $null) { return $true }

    if ($objectToCheck -is [String] -and $objectToCheck -eq [String]::Empty) { return $true }

    if ($objectToCheck -is [DBNull] -or $objectToCheck -is [System.Management.Automation.Language.NullString]) { return $true }
    return $false
    }
    #—————————————————-
    Sincerest thanks to you all for sharing your expertise.

    in reply to: Checking for NULL in PS #103990
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Many thanks, much appreciated.

    in reply to: Powershell and MS-ACCESS (2013) #103327
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Hello Rob,
    Following the website references you provided, I have tested the statements (I am running PS 5.1) —
    1 – $objConnection = New-Object -comobject ADODB.Connection
    2 – $objRecordset = New-Object -comobject ADODB.Recordset
    3 – $objConnection.Open(“Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\XXC\Documents\MyAccessDB.mdb”)

    I keep getting the error message: ” Provider cannot be found. It may not be properly installed. ”
    I ran each statement individually and #1 and #2 always run fine.
    It is always at #3 that I get the error. I must be missing something behind the scenes?

    I have ACCESS 2007 installed and running fine on my Win 7 (64-bit) PC for many years now.
    It was installed as part of Office 2007 Pro, which includes Word,Excel,PPoint,Outlook,Access & 1 or 2 other products which I don’t use (Publisher). Would be grateful for any advice or suggestions.

    in reply to: Powershell and MS-ACCESS (2013) #103280
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Many thanks Rob, much appreciated.

    in reply to: Running Powerscript in the "enduser" environment #103198
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Thank you very much, your inputs are very helpful.
    Much appreciated.

    in reply to: Running Powerscript in the "enduser" environment #103195
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Many thanks Mr Jones, much appreciated.

    in reply to: Is this a "Powershell Way" of counting? #102629
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Thank you again, Mr Crompton. I “played” with the commands you gave as examples, read and re-read your explanations, and am pleased that a few things are beginning to make sense. Without bothering you with more details, I am, saying to myself the ff:

    As explained by you, Get-Member returns those properties, methods, etc.. on each line/record (you call them ‘items’, the book of Hicks and Jones calls them ‘rows’) as they “come down the pipe” one-by-one, denoted by the “$_” symbol. So Get-Member in expectation of a “count” on a single line/record makes no sense: at least not in the context of my stated problem, which is to count all these lines/records (items). But it wasn’t until your example command: {Get-Member -INPUTOBJECT $values} in your reply that “something finally made sense”. This command displayed COUNT as an AliasProperty, and in comparing its results with just $values | GM, it gave me an understanding of the difference between objects that are collections/arrays versus objects that are lines/records (you call them items).

    I cannot thank you enough for your generous sharing of Powershell knowledge and concepts.
    Sincerely,

    in reply to: Is this a "Powershell Way" of counting? #102617
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Hello Mr Crompton,

    I am extremely grateful for your creative suggestion/solution.
    I tried it and it works perfectly.
    To follow-up for my own education, I executed your script one step further, which is to run:

    > $values | Get-Member

    and was rather surprised that Count did not appear as a method. I am definitely missing some “principle of PS operation”.
    I was of the understanding that piping any object or collection from a command to Get-Member would yield a list of methods, properties, etc. that are relevant to that object. Naturally, I think there must be a “common” or “universal” set of methods that exist for each item (variable, cmdlet, object, etc.) in Powershell as long as the context is semantically valid, mcuh like the 9 to all cmdlets.

    Any hints or advice would be highly appreciated.
    Sincerely,

    in reply to: Is this a "Powershell Way" of counting? #102616
    Participant
    Topics: 86
    Replies: 138
    Points: 677
    Rank: Major Contributor

    Yes, Mr L-Bo, it works beautifully … and thanks to you for your generous help.
    As a follow-up, I ran the same command but without the .Count and piped it to get-member:

    (Import-Csv -Path Path\To\Somefile.csv) | Get-Member

    and got a listing of methods and properties — something I learned early on from the book of Jones & Hicka, which has proven to be extremely useful. But to my surprise, the listing did NOT include ‘Count’ as a method. I was expecting it.

    I must be missing something. I am asking this because so far, I’ve found the Get-member cmdlet, as advised in that book, to be a very useful source of discovering what can and cannot be done with the “data in the pipeline” as a script progresses through a series of commands.

    Would be grateful for any advice, tips or hints.

Viewing 15 posts - 106 through 120 (of 138 total)