Jump to content

Recommended Posts

{
    SetEnviromentVariable ("WGet", "$MyInvocation.MyCommand.Path", "Machine" )
}    
I've never coded in powershell but i do know a lot about batch. I would like some help with a toolkit i'm developing and i need a powershell script that will be in the install directory that will add the environment variable to the "Machine". I'm trying to automate the installation of Wget for Cmd as it's an essential for my toolkit. Any Help would be greatly appreciated 

Thanks, $tRiZzY

Link to post
Share on other sites
On ‎04‎/‎11‎/‎2017 at 12:09 AM, $tRizZy said:

I need a powershell script that will be in the install directory that will add the environment variable to the "Machine". I'm trying to automate the installation of Wget for Cmd.

I'm half-decent at PowerShell, but I don't understand what you are getting at here. Can you break down a little clearer what it is that you require the script to do?

Thanks.

Link to post
Share on other sites

Depends if you are making it temporary or permanent.  To make it simple I will complete the way you are trying to use it is call upon the .NET Environment class to make it permanent machine wide.

[Environment]::SetEnvironmentVariable("variable_name_here", "variable_value", "Machine")

To invoke this machine wide you must be admin.

Of course your command will just make the wget environment variable the current script that made it.  Will still need to prepend the powershell command and this would just run the script again to make the environment variable.

Link to post
Share on other sites

Just an FYI, powershell, has a built in feature, that works, much like wget, if not better, since it's built in and no need for third party tools. you can download files and push files with powershell. It also won't get picked up by malware scanners, as wget sometimes gets flagged. Google is your friend.

Edited by digip
Link to post
Share on other sites

Thanks to all whom replyed, I was making a CMD tool and needed to automatically install wget and setup the location of the enviroment variables. I was too far into the code when i realized PS has a wget feature... (actually wanted to die) Anyways if yall want to know the code was going to, Trace Ip's, an Auto Netcat feature, File downloader, and some other tools i was going to develop all for the windows command prompt... This tbh was a project to keep my mind busy at school but if you all want to see this become a thing ill convert everything to powershell friendly code (which will prob be wayyy easier) and post the finished product.

Link to post
Share on other sites

Powercat is a powershell version of netcat that can be used to avoid using the ncat binary that sometimes fire off the AV.

https://github.com/secabstraction/PowerCat

 

Powershell has 2 ways to invoke web requests.  If you are on 2.0 (if you can control the environment you should be on 4+ already since MS announced the deprecation of PS 2.0) the you will need to tap into the .NET assemblies.  Reference to it is here:

https://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.110).aspx

 

Example usage to download a string is:

# Create webclient object
$wb = New-Object System.Net.WebClient

#use it to download some from web as string
$stuff = $wb.DownloadString("web_url_here_with_port_if_not_80_and_path")

 

If > 2.0 then you can use "Invoke-WebRequest".  Usage is here:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-5.1

 

Invoke-Webrequest uses the application type from the server so if the server is serving anything other than text then Invoke-Webrequest will only download it as a file.  That is why if you want text, you want to either make sure the server sends the item as text or the item has a text like extension that the server will autosend as text.  The item it gets is a webrequest object and what you want is in the $webrequestobject.Content section.

I can keep going on but this can turn into a blog.  The links should give you reference to how to use the commands.  Have fun.

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...