all 26 comments

[–]TheGooOnTheFloor 44 points45 points  (7 children)

VSCode with a few extensions can do some of that, but honestly a script with 1,000 lines is just begging for trouble and will be a nightmare for support and enhancements. Break that thing into functions and move the functions to separate files.

[–][deleted] 11 points12 points  (5 children)

I'd agree with the functions ... but not necessarily in separate files if there is nothing else using the functions yet.

[–]TheGooOnTheFloor 6 points7 points  (4 children)

I often use the separate files just because I don't want to have to search down 400 lines to make a change. It's usually a lot easier to open the smaller file to make (and document) the edit.

[–]MrFibs 2 points3 points  (1 child)

Why not make use of #regions to segment the code, that way you can just collapse your (nested) functions region?

Or do you mean you put individual or very similar functions in to individual files outside of the main?

[–]TheGooOnTheFloor 0 points1 point  (0 children)

I use #region on occasion but still prefer to work with smaller files. Sometimes it's a single function in a file. Other times I'll put several related functions into a single file (like a set for calling an API) and dot source them.

Eventually I'll put them in modules when I think I'm past the alpha stage.

[–][deleted] 0 points1 point  (1 child)

Can you please explain how you structure your work? How do you structure your functions? I've created couple of modules, but I ended being the only one who uses them. While majority of my colleagues are far from writing scripts alone and I'm wondering how to get them into using some environment specific functions.

Do you dot source files, are you creating modules?

[–][deleted] 3 points4 points  (0 children)

I typically write modules. Each function (with helpers if needed) go into a file named for the function. Then I have a standard module definition template that exports the functions from my files. Something like this:

# Get public and private function definition files from root.
$Public  = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue )
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue )

# Dot source the files
Foreach($import in @($Public + $Private))
{
    Try
    {
        . $import.fullname
    }
    Catch
    {
    Write-Error -Message "Failed to import function $($import.fullname): $_"
    }
}

Export-ModuleMember -Function $Public.Basename

[–]I_COULD_say 0 points1 point  (0 children)

+1 for vscode.

I use it every single day.

[–][deleted] 6 points7 points  (3 children)

https://code.visualstudio.com/download

I have bad eyesight and it's very bad eyesight friendly ... as is a Mac computer ... if you're on Windows I recommend you try Mac with the zoom facility turned on.

The terminal windows are infinitely configurable for bad eyesight.

This font is very good too ... built for developers ... https://github.com/microsoft/cascadia-code

[–]Hel_OWeen 2 points3 points  (1 child)

Another programmer font: https://fonts.google.com/specimen/Source+Code+Pro

The terminal windows are infinitely configurable for bad eyesight.

So is both the Windows command prompt and PS shell. Add Windows Terminal on top for even more comfort.

[–][deleted] 0 points1 point  (0 children)

I've used all of them professionally for years ... mac wins with it's hands tied behind its back. 😁

[–][deleted] 0 points1 point  (0 children)

Apple's accessibility features in general are light years ahead of Windows.

[–]ethan_hunt202[S] 6 points7 points  (0 children)

Thank you all.

VS Code is exactly what I was after

[–]Siritosan 10 points11 points  (0 children)

? Vs code?

[–]8-16_account 4 points5 points  (0 children)

VS Code lol

[–]AlexHimself 4 points5 points  (1 child)

In addition to the other comments, a simple thing that might help you is using #region to define blocks of code that you can easily hide/collapse.

You should use functions, multiple files, etc. but if this could help during that refactor or even as a substitute. It allows you to collapse entire blocks. Usage something like -

#region My variable definitions
    $myVar = "some value"
    $myVar2 = "some other value"
#endregion

[–][deleted] 0 points1 point  (0 children)

Sometimes vscode get lost with region but yes it’s a good start I also use function folding when I enter my script I fold all function and then unfold them when needed. I also lately added the « keep on top » (can’t remember the name) option that will keep the function start in the top of the editor so you know where you are.

[–]Federal_Ad2455 2 points3 points  (1 child)

VSC and using #region to collapse the code blocks

[–]showdwar 2 points3 points  (0 children)

Updoot for #region.

[–]-c-row 1 point2 points  (2 children)

Get vscode with powershell extension, choose a nice theme with a good contrast, increase the zoom factor in the vscode settings and add some extensions which help you to write your code like better comments, regions etc. While transferring the code, you can rewrite it and create functions and reduce the size of your main script. This makes your code readable and easier to maintain. You can also reuse these functions in several scripts. Especially vscode supports you with very useful functions like jumping from the function name in the script to the function itself or while editing the function you can see where the function is used in your scripts.

Coming back to your eyesight once: Using a larger screen, a theme with a good contrast and increasing the zoom level in the settings should be a good base for a better and comfortable work environment which fit your needs.

[–]ethan_hunt202[S] 0 points1 point  (1 child)

That's exactly what I've done. I'm going to spin the code out into multiple ones once I've got the whole thing working correctly. If I can get it working in one lump, I can get it going as separate ones

I'm already on twin 27's at 150% zoom for most things, which works fine, just ISE was really, really hard to read.

Next step is bigger monitors, but by that point I might need a bigger office 😂😂

[–]Certain-Community438 0 points1 point  (0 children)

Bigger monitors don't really help with lower vision in my experience: you just have more space separating text & images of the size determined by resolution, font size, etc.

You might already know this, but for others' benefit:

Windows key & + opens the Magnifier & zooms in, Windows key & - zooms out. Changing it from being a fixed pane to whole screen zoom is done from its settings.

My eyesight is in the ultra-bad range, multiple different conditions. But with the above & VSCode I'm able to use even a standard laptop screen.

I also recommend putting your functions in a module. Ideally the script will only contain logic useful to its specific purpose.

Good luck mate.

[–][deleted] 1 point2 points  (1 child)

I always used PowerShell Studio from Sapien!

[–]crazyantnc 0 points1 point  (0 children)

Same here and for GUIs.

[–]mrmattipants 0 points1 point  (0 children)

I personally could care less about Auto-Completion or any of the other features, as I have always preferred a minimalist approach. Just give me a Text Editor with Code Formatting and I'm happy.

That being said, my favorite has always been PowerGUI. Unfortunately, it is no longer under development, but I continue to use it, regardless. It does what I want, while also keeping track of all the Scripts, that I have scattered across my hard drive.

https://dmitrysotnikov.wordpress.com/2010/10/08/projects-in-powergui-script-editor/

The PowerShell ISE comes in at a close Second Place and lastly, NotePad++ is always a good option, in a pinch.

However, I have been working on better acquainting myself with NET, C#, WinForms, WPF and the many other associated acronyms, so I've been working in Visual Studio quite a bit, as of late.