bash to powershell

Home Forums Scripting PowerShell bash to powershell

This topic contains 2 replies, has 2 voices, and was last updated by Avatar vickynet 1 month, 3 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • Avatar
    vickynet
    Participant
    #620166

    Hi all,

    I have bash script that i need to want to convert into powershell or write into powershell script can u someone help on below script , because am new to powershell so kindly help me.

    #!/bin/bash

    DESC=$1
    HOSTNAME=$2
    DATE=$3
    REPLACE=”-”
    DATE=${DATE//”.”/$REPLACE}
    TIME=$4
    SEV=$5
    SEV=${SEV^^}
    IP=$6
    TIME=date -d "$DATE $TIME" +%s

    NOTES=”SEV : $SEV\tDESC: $DESC\tHOSTNAME: $HOSTNAME\tDATE: $DATE $TIME”
    COMP=””

    echo “Started at $TIME with $NOTES” >> /tmp/push.log
    if [[ $DESC =~ .*load.* || $DESC =~ .*CPU.* ]]
    then
    COMP=”Load”
    fi

    if [[ $DESC =~ .*Service.* || $DESC =~ .*running.* ]]
    then
    COMP=”Service”
    fi

    if [[ $DESC =~ .*PROCS.* || $DESC =~ .*processes.* ]]
    then
    COMP=”Process”
    fi

    if [[ $DESC =~ .*SWAP.* || $DESC =~ .*Swap.* ]]
    then
    COMP=”Swap”
    fi

    if [[ $DESC =~ .*DISK.* || $DESC =~ .*inode.* || $DESC =~ .*folder.* ]]
    then
    COMP=”Disk”
    fi

    if [[ $DESC =~ .*Memory.* || $DESC =~ .*MEMORY.* ]]
    then
    COMP=”Memory”
    fi

    if [[ $DESC =~ .*Logins.* || $DESC =~ .*Login.* ]]
    then
    COMP=”Security”
    fi

    if [[ $DESC =~ .*docker.* || $DESC =~ .*Container.* ]]
    then
    COMP=”Docker”
    fi

    if [[ $DESC =~ .*bandwidth.* || $DESC =~ .*RX.* ]]
    then
    COMP=”Interface”
    fi

    curl -i -X POST ‘http://x.x.x.x:8000/evm/api1.0/endpoints/eventreceiver’ -d “{\”ci_name\”: \”$HOSTNAME\”, \”component\”: \”$COMP\”, \”description\”: \”$DESC\”, \”notes\”: \”$NOTES\”, \”severity\”: \”$SEV\”, \”event_created_time\”: \”$TIME\”, \”source\”: \”ZABBIX\”}” -H “Content-Type: Application/json” >> /tmp/curl.log 2>> /tmp/curl.log

    echo “Finished with $?” >> /tmp/push.log

    Avatar
    wullieb1
    Moderator
    #620264

    Ok i’ll bite.

    Whats stopping you from putting in the same time that everyone else who has had to learn PowerShell to assit you completeing this task?

    Here’s something that should get you going

    https://www.phillipsj.net/posts/bash-to-powershell-simple-scripts

    Avatar
    vickynet
    Participant
    #620265

    Thanks wullieb

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.