locked
output a file in a txt file with a specific condition RRS feed

  • General discussion

  • hi

    I have a URL that show me a number such as 1294060845:

    Invoke-WebRequest "http://******" | select content | ft -HideTableheaders

    I want to save this number to a file "if the number lower than a number".

    how can I do that?


    • Changed type Bill_Stewart Monday, September 11, 2017 3:21 PM
    • Moved by Bill_Stewart Monday, September 11, 2017 3:22 PM This is not "teach me basics step-by-step" forum
    Thursday, July 6, 2017 4:48 AM

All replies

  • You can use an if condition to check if the number is lower and if it's the case you pipe the number to Out-File. What's the deal?

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Thursday, July 6, 2017 6:08 AM
  • thanks,

    I use this:

    $web = Invoke-WebRequest "http://******" | select content | ft -HideTableHeaders

    $web | out-file 123.txt

    whis is worked for me. but when how can I set lower than in script?

    this dont work for me:

    if ($web -lt 10000) {out-file 123.txt)

    Thursday, July 6, 2017 7:16 AM
  • hi

    $web = Invoke-WebRequest "http://******" | Select-Object -ExpandProperty content | ft -HideTableHeaders

    when I used that worked for me. and now how can use condition for lowerthan for out-file command?

    Thursday, July 6, 2017 7:53 AM
  • It depends pretty much on what's in your variable $web.  If it is really just some numbers you could try casting it to the apropriate type like this:

    [INT]$web -lt 10000
    BTW: You should not use format cmdlets when you want to store something in a variable. It's only for the output to the console.

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Thursday, July 6, 2017 11:15 AM
  • hi.

    I dont know about integer or variables. can you describe clearly.

    or can you tell me what can I do for doing this.

    Thursday, July 6, 2017 2:47 PM
  • Sorry but we cannot teach you how to script with Powershell or scripting in general at all. You should take a little time and start to learn the basics of Powershell. Here you can find some good ressources to start from: Top Beginner Sites and Tutorials.

    Good luck.


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Thursday, July 6, 2017 5:35 PM
  • thanks.

    but I cant wait for learning that.

    can anyone write that script?

    I search an go half of the way, please help me to complete that.

    Friday, July 7, 2017 7:39 PM
  • but I cant wait for learning that.

    Please keep in mind that the help here is free and there is no service-level agreement.

    If you need someone to write a solution for you, we recommend hiring a consultant.


    -- Bill Stewart [Bill_Stewart]

    Friday, July 7, 2017 8:00 PM
  • but I cant wait for learning that.

    I assume that's a typo and you meant "... but I cant wait to learn that." !!  ;-)

    If you start right now with at least one of the ressources linked in the site I posted you could be able to accomplish what you've asked for on Monday.

    Or you simply hire a trained IT personnel to do it for you as Bill already recommended.

    Have a nice Weekend and a lot of fun.


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Friday, July 7, 2017 8:21 PM