Options

Oh Powershell...

the_Grinchthe_Grinch Member Posts: 4,165 ■■■■■■■■■■
Loving Powershell more and more every time I use it. A few weeks ago I wrote a script to go to a website, copy the text into a text file, and then convert the text file to a csv. From there (for now anyway) I copy a column into a master spreadsheet to compare values to look for changes. Now this script has literally worked for two weeks without issue and then suddenly (on the page with the largest amount of text) it starts to fail. I started to manually copy the text since I didn't have time to troubleshoot, but today I swore to fix it. Started reviewing the output and saw that it was timing out on the one page. In a manual test I saw it takes about two minutes to load so I tried a manual pause, but it didn't work.

So I Google "invoke-webrequest timing out" only to low and behold find out there is a timeout option for it! Entered in -TimeoutSec 120 and it's working without a hitch once again!
WIP:
PHP
Kotlin
Intro to Discrete Math
Programming Languages
Work stuff

Comments

  • Options
    cgrimaldocgrimaldo Member Posts: 439 ■■■■□□□□□□
    I really want to learn powershell...Threads like these remind me I need to do that..
  • Options
    DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    I love that feeling when a job that to manual carry out takes 2 hours, but after a few hours toying with a scrip, you hit the return key and seconds later it completes perfectly, and you know never again will you have to do it the long way.

    I still have a soft spot for one of my fist scripts, which took a list of switch/port/vlan/speed/duplex.

    sorted them in to order by switch, logged on to the first switch, checked the current configuration and status of the port and saved the information, applied the new standard config from the list of valules, rechecked the port status, if it had changed then rolled back the config, or if it was acceptable saved the new config, and then either moved on to the next port or saved the config and logged of. Then once it go to the end of the list created a report with which port had passed or failed.

    On average it could do about 900 ports in 15min, compared to the best part of 4 hours to do by hand, and it never made mistakes like configuring the wrong port, or atering the config of a port currently connected.

    Mine you that was in VBa :)
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • Options
    the_Grinchthe_Grinch Member Posts: 4,165 ■■■■■■■■■■
    Devil that is awesome! I'm definitely falling more into scripting and it is great. Once we start our Nagios setup, it's really going to get big!
    WIP:
    PHP
    Kotlin
    Intro to Discrete Math
    Programming Languages
    Work stuff
  • Options
    NotHackingYouNotHackingYou Member Posts: 1,460 ■■■■■■■■□□
    Scripting leads to Automation. Automation leads to coding. And coding leads to the dark side...



    Welcome!!!
    When you go the extra mile, there's no traffic.
  • Options
    CrikeyCrikey Member Posts: 59 ■■□□□□□□□□
    Having spent some time using VB scripting, I can say without a doubt that Microsoft actually did something right with PS.
  • Options
    lsud00dlsud00d Member Posts: 1,571
    The ol' invoke-restmethod eh?

    It helps coming from a linux background moving to PoSH...For instance in this case I would think "how can I wget or curl?" and then find the PoSH equivalent. It helps that many of the commands are linux aliased but I've been trying to break that habit and learn the PoSH syntax of the command.
  • Options
    Architect192Architect192 Member Posts: 157 ■■■□□□□□□□
    Same here... Been dabbling with PS for a while but nothing serious. In my current mandate we needed to reconfigure 200 VMs that had e1000 adapters to VMXNET3. I wasn't about to ask the sysadmins to do it manually so I wrote a script that goes through the whole process.
    - Get the current IP information
    - shutdown the VM
    - change the adapter type (retaining the mac address)
    - set the "update vmware tools at startup" while at it ;)
    - start the VM
    - purge the ghost devices
    - rename the network connection
    - update the IP information, disable IPv6 (their requirements...), setup some specific network parameters etc...
    - reboot the machine one last time.

    All this? One simple command line. ReconfigVM "vmname" :) oh and if you specify a cluster, it processes all the VMs in the cluster.

    Really fun stuff to do.

    Right now I'm working on basic scripts to do the initial configs I do on servers after installation that I can't put in the template. Would even work on physical systems :)

    Fun stuff! hardest part is to figure out what do to, not how to do it...
    Current: VCAP-DCA/DCD, VCP-DCV2/3/4/5, VCP-NV 6 - CCNP, CCNA Security - MCSE: Server Infrastructure 2012 - ITIL v3 - A+ - Security+
    Working on: CCNA Datacenter (2nd exam), Renewing VMware certs...
  • Options
    the_Grinchthe_Grinch Member Posts: 4,165 ■■■■■■■■■■
    I love automation! Much less room for error and I can setup the scripts to run without me being there (a big plus). Great hearing all the stories from the trenches!
    WIP:
    PHP
    Kotlin
    Intro to Discrete Math
    Programming Languages
    Work stuff
Sign In or Register to comment.