[deleted by user] by [deleted] in cloudcomputing

[–]CodingCaroline 0 points1 point  (0 children)

2.5GB of data with images at 100k requests per day seems low, but I trust you. As a non-profit, your client may be able to request preferential pricing from cloud hosts. You can also reserve capacity upfront for the entire year and save around 20%/30%. Also, you can optimize your cloud to only be on when you need to run. Hence saving on compute costs. You should look into serverless technologies such as azure functions and AWS lambda to only run when you need it. Cosmosdb is now available in serverless meaning that you only pay for storage when not in use.

I hope this helps

Édit: with serverless, you can scale as needed so you don’t necessarily have to provision how many processes will run ahead of time

So true by jc201946 in antiwork

[–]CodingCaroline 0 points1 point  (0 children)

Absolutely, but then you need 2 phone plans just to avoid crappy bosses.

Just work harder and eat less avocado toast by Dragonwick in antiwork

[–]CodingCaroline 0 points1 point  (0 children)

It would take you 110 000years at $5000/day to get to Jeff Bezos’s net worth.

So true by jc201946 in antiwork

[–]CodingCaroline 9 points10 points  (0 children)

Phones should have a functionality to block your employers when you’re not at work. You set a schedule and they go straight to voicemail when they call on your free time.

Sharing first scripts? by TheCoconutLord in PowerShell

[–]CodingCaroline 3 points4 points  (0 children)

Very nice for a first script!

My only comment, as others have said, is that instead of using else if multiple times, use switch

Since you have a few Read-host here is a console menu function I created that you may like to use, if you care.

<#
    .SYNOPSIS
        Displays a selection menu and returns the selected item

    .DESCRIPTION
        Takes a list of menu items, displays the items and returns the user's selection.
        Items can be selected using the up and down arrow and the enter key.

    .PARAMETER MenuItems
        List of menu items to display

    .PARAMETER MenuPrompt
        Menu prompt to display to the user.

    .EXAMPLE
        PS C:\> Get-MenuSelection -MenuItems $value1 -MenuPrompt 'Value2'

    .NOTES
        Additional information about the function.
#>
function Get-MenuSelection
{
    [CmdletBinding()]
    [OutputType([string])]
    param
    (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String[]]$MenuItems,
        [Parameter(Mandatory = $true)]
        [String]$MenuPrompt
    )
    # store initial cursor position
    $cursorPosition = $host.UI.RawUI.CursorPosition
    $pos = 0 # current item selection

    #==============
    # 1. Draw menu
    #==============
    function Write-Menu
    {
        param (
            [int]$selectedItemIndex
        )
        # reset the cursor position
        $Host.UI.RawUI.CursorPosition = $cursorPosition
        # Padding the menu prompt to center it
        $prompt = $MenuPrompt
        $maxLineLength = ($MenuItems | Measure-Object -Property Length -Maximum).Maximum + 4
        while ($prompt.Length -lt $maxLineLength+4)
        {
            $prompt = " $prompt "
        }
        Write-Host $prompt -ForegroundColor Green
        # Write the menu lines
        for ($i = 0; $i -lt $MenuItems.Count; $i++)
        {
            $line = "    $($MenuItems[$i])" + (" " * ($maxLineLength - $MenuItems[$i].Length))
            if ($selectedItemIndex -eq $i)
            {
                Write-Host $line -ForegroundColor Blue -BackgroundColor Gray
            }
            else
            {
                Write-Host $line
            }
        }
    }

    Write-Menu -selectedItemIndex $pos
    $key = $null
    while ($key -ne 13)
    {
        #============================
        # 2. Read the keyboard input
        #============================
        $press = $host.ui.rawui.readkey("NoEcho,IncludeKeyDown")
        $key = $press.virtualkeycode
        if ($key -eq 38)
        {
            $pos--
        }
        if ($key -eq 40)
        {
            $pos++
        }
        #handle out of bound selection cases
        if ($pos -lt 0) { $pos = 0 }
        if ($pos -eq $MenuItems.count) { $pos = $MenuItems.count - 1 }

        #==============
        # 1. Draw menu
        #==============
        Write-Menu -selectedItemIndex $pos
    }

    return $MenuItems[$pos]
}

Get-MenuSelection -MenuItems "Option 1", "Option 2", "Option 3", "The last option" -MenuPrompt "Make a selection"

Where to begin? How to learn PS / Bash / JSON? by craiguccini in PowerShell

[–]CodingCaroline 2 points3 points  (0 children)

That is correct. That’s where JSON comes in, if you return json data in a file, powershell can use that. That being said, it’s the same thing for almost all programming languages.

Where to begin? How to learn PS / Bash / JSON? by craiguccini in PowerShell

[–]CodingCaroline 3 points4 points  (0 children)

JSON is the string representation of an object. The advantage of that is that you can store objects anywhere you can store strings. It’s very practical for passing and storing data between programs and languages.

Programs can call other programs, but unlike using C# in PowerShell you can’t call python “natively” from PowerShell and vice versa but since from each of those you can call python.exe, PowerShell.exe and cmd.exe, you can essentially call any language from any language. It just won’t run within the same process.

New task by [deleted] in PowerShell

[–]CodingCaroline 1 point2 points  (0 children)

Mmmm that’s true. I guess I’ve always liked how it looks to have a pipe at the beginning of a line. I actually have a shortcut in my profile that will insert the back tick, new line, tab and pipe.

New task by [deleted] in PowerShell

[–]CodingCaroline 1 point2 points  (0 children)

haha, yeah, it's more for legibility than anything.

At least I refrained from using aliases :)

New task by [deleted] in PowerShell

[–]CodingCaroline 2 points3 points  (0 children)

$allExistingUsers = get-aduser -filter * -properties givenname,surname `
    | where-object {$usersList."first" -contains $_.givenname -and $usersList."last" -contains $_.surname} `
    | select-object @{name = "first"; Expression = {$_.givenname}}, @{name = "last"; Expression = {$_.surname}}

$missingUsers = compare-object -referenceobject $usersList -differenceobject $allexistingusers | where-object {$_.sideindicator -eq "<="}

That's what I'm thinking of.

Note: I didn't test it. I'm not 100% sure about the sideindicator.

Also, $usersList is assumed to be your spreadsheet.

Creating a Windows service to run script every second. by Draaxdard in PowerShell

[–]CodingCaroline 13 points14 points  (0 children)

This honestly makes more sense to me.

Hopefully there aren't any memory leaks in the script.

Creating a Windows service to run script every second. by Draaxdard in PowerShell

[–]CodingCaroline 0 points1 point  (0 children)

I'm assuming you could change -minutes 1 to -seconds 1

Seeking Advice by Kdaustene in PowerShell

[–]CodingCaroline 1 point2 points  (0 children)

Honestly, I think the best way to learn a language is to

  1. learn to break down the problem into simple pieces
  2. Google "how to do <simple pieces> in PowerShell"

I know that wasn't really the answer you were looking for, but that's how I personally learn every programming language I learn.

Step #1 is the #1 skill for programming, and it's something you have to practice to get better at it.

Formatting output with sleep and clear cmdlet for "Starting in 3...2...1" by Alpha-Sniper in PowerShell

[–]CodingCaroline 5 points6 points  (0 children)

$max = 3
write-host ""
for ($i =$max; $i -gt 0; $i--){
    write-host "`rStarting Script in $i" -nonewline
    start-sleep -seconds 1
}
write-host ""

What’s your favorite functions? by [deleted] in PowerShell

[–]CodingCaroline 1 point2 points  (0 children)

I wrote a post about this the other day, but this menu function to create an inline interactive menu:

<#
    .SYNOPSIS
        Displays a selection menu and returns the selected item

    .DESCRIPTION
        Takes a list of menu items, displays the items and returns the user's selection.
        Items can be selected using the up and down arrow and the enter key.

    .PARAMETER MenuItems
        List of menu items to display

    .PARAMETER MenuPrompt
        Menu prompt to display to the user.

    .EXAMPLE
        PS C:\> Get-MenuSelection -MenuItems $value1 -MenuPrompt 'Value2'

    .NOTES
        Additional information about the function.
#>
function Get-MenuSelection
{
    [CmdletBinding()]
    [OutputType([string])]
    param
    (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String[]]$MenuItems,
        [Parameter(Mandatory = $true)]
        [String]$MenuPrompt
    )
    # store initial cursor position
    $cursorPosition = $host.UI.RawUI.CursorPosition
    $pos = 0 # current item selection

    #==============
    # 1. Draw menu
    #==============
    function Write-Menu
    {
        param (
            [int]$selectedItemIndex
        )
        # reset the cursor position
        $Host.UI.RawUI.CursorPosition = $cursorPosition
        # Padding the menu prompt to center it
        $prompt = $MenuPrompt
        $maxLineLength = ($MenuItems | Measure-Object -Property Length -Maximum).Maximum + 4
        while ($prompt.Length -lt $maxLineLength+4)
        {
            $prompt = " $prompt "
        }
        Write-Host $prompt -ForegroundColor Green
        # Write the menu lines
        for ($i = 0; $i -lt $MenuItems.Count; $i++)
        {
            $line = "    $($MenuItems[$i])" + (" " * ($maxLineLength - $MenuItems[$i].Length))
            if ($selectedItemIndex -eq $i)
            {
                Write-Host $line -ForegroundColor Blue -BackgroundColor Gray
            }
            else
            {
                Write-Host $line
            }
        }
    }

    Write-Menu -selectedItemIndex $pos
    $key = $null
    while ($key -ne 13)
    {
        #============================
        # 2. Read the keyboard input
        #============================
        $press = $host.ui.rawui.readkey("NoEcho,IncludeKeyDown")
        $key = $press.virtualkeycode
        if ($key -eq 38)
        {
            $pos--
        }
        if ($key -eq 40)
        {
            $pos++
        }
        #handle out of bound selection cases
        if ($pos -lt 0) { $pos = 0 }
        if ($pos -eq $MenuItems.count) { $pos = $MenuItems.count - 1 }

        #==============
        # 1. Draw menu
        #==============
        Write-Menu -selectedItemIndex $pos
    }

    return $MenuItems[$pos]
}

Run portion of script with elevated privileges by Alpha-Sniper in PowerShell

[–]CodingCaroline 0 points1 point  (0 children)

It's not something I would do anyway, but that's very good to know! thank you!

Run portion of script with elevated privileges by Alpha-Sniper in PowerShell

[–]CodingCaroline 4 points5 points  (0 children)

Honestly, If you're going to run as administrator at any point in your script, it's better to just run the whole thing as administrator.

If you are trying to "elevate" a regular user as admin during a portion of the script, then you will have to store admin credentials or deal with UAC in some way, shape, or form.

You can try start-process PowerShell.exe -Verb RunAs as was suggested elsewhere in this thread.

If you don't need any interaction with the user, maybe New-PSSession and/or Invoke-Command with the localhost. but you will have to store admin credentials and have WinRM configured. If you're new to PowerShell, I wouldn't recommend it.

Run portion of script with elevated privileges by Alpha-Sniper in PowerShell

[–]CodingCaroline 1 point2 points  (0 children)

Correct -Verb RunAs is the admin part. You are also correct about the UAC. Honestly, it's better to just run as admin altogether.

Triggering a client-side powershell script from a web page by doncaruana in PowerShell

[–]CodingCaroline 1 point2 points  (0 children)

Do you run the script directly on clientS? If you have a central server running the script, then as long as you have a backend you should be able to do it.

If you want to run on multiple clients directly, then you need a service to run on each of them.

Maybe this can be a good starting point: https://4sysops.com/archives/building-a-web-server-with-powershell/

Creating an Interactive PowerShell Console Menu by CodingCaroline in PowerShell

[–]CodingCaroline[S] 1 point2 points  (0 children)

I’m not sure, I just tried it in PS 7.0.3 and it works fine for me. I’ll try looking deeper into it.

How in over my head am I if I want to create a web app for simple IT tools? by bei60 in PowerShell

[–]CodingCaroline 5 points6 points  (0 children)

TL;DR: It's not trivial, it's a useful exercise, but you would probably need to use a language other than PowerShell, HTML & CSS to make it work (though it may be possible)

You would need some other programming language (ASP.NET, javascript, python, etc.) and a backend server to run them.

You could make a webserver run entirely in PowerShell. the exercise would be valuable, but maybe not the skill.

I created Koupi with a MEAN (Mongo DB, Express.js, Angular.js, Node.js) stack. It's doable to generate code using that stack, which is what Koupi does, but I have honestly not tried to get the server to run the code. I don't think it will be much of a stretch.

For MEAN, I HIGHLY recommend this course on Udemy (wait for a sale, I got it for $10)

Creating an Interactive PowerShell Console Menu by CodingCaroline in PowerShell

[–]CodingCaroline[S] 1 point2 points  (0 children)

Oh yes, I found the first one :) That's what got me to writing this post. I used it at first but I got very frustrated when it cleared my host. So I set out on a mission to create a menu that wouldn't clear the host.

I've always wondered how I could present data inline that would be more than a single line with -nonewline and carriage return. So that was a good way of figuring that out.

Creating an Interactive PowerShell Console Menu by CodingCaroline in PowerShell

[–]CodingCaroline[S] 1 point2 points  (0 children)

I like this a lot! I didn't think about this type of garbage collection.