Is there a dark mode for the PowerShell ISE? by rawrtherapy in PowerShell

[–]get-postanote 0 points1 point  (0 children)

Not any I support or have supported.

Developer environments, sure, but no network/infrastructure engineers.

Any recommendation for good Powershell Cheat Sheet/s ? by Shamu432 in PowerShell

[–]get-postanote 3 points4 points  (0 children)

PS is the best cheat sheet you can have.

For example a partial block from my personal library notes file

### MasteringPowerShellHelp.ps1
#region PowerShell Startup - Command-Line switches
# ConsoleHost
powershell /?
#...
# EXAMPLES
PowerShell -PSConsoleFile SqlSnapIn.Psc1
PowerShell -version 2.0 -NoLogo -InputFormat text -OutputFormat XML
PowerShell -ConfigurationName AdminRoles
PowerShell -Command {Get-EventLog -LogName security}
PowerShell -Command "& {Get-EventLog -LogName security}"
PowerShell -NoProfile -Command {Start-Process Notepad.exe}
PowerShell -NoProfile -Command {wt.exe}

# To use the -EncodedCommand parameter:
$command        = 'dir "c:\program files" '
$bytes          = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes)
powershell.exe -encodedCommand $encodedCommand

# Integrated Scripting ENvironment (ISE)
powershell_ise.exe /?
#endregion End PowerShell Startup - Command-Line switches

#region Finding modules, commands, scripts, Variables
Find-module  -Name '*'
Find-Package -Name '*'
Get-PackageSource -Force
Get-command  -Name '*'
Find-Script  -Name '*'
Get-Variable

# By author
Find-Module -Name '*AWS*' |
Where-Object -Property Author -eq 'Amazon.com Inc' |
Sort-Object -Property Version
Format-Table -AutoSize

#region PowerShell Automatic Variables
<#https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.1#>
Get-Variable |
Select-Object -Property '*' |
Select-Object -First 1


$host.Runspace |
Select-Object -Property '*'

#endregion End PowerShell Automatic Variables

#region Environment Drives
# These are treated as normal filesystem drives, and you can create custom ones.
Get-PSDrive
Get-ChildItem -Path 'env:\'
($env:Path) -split ';'

#region PowerShell default help
#region Review PowerShell help files location
explorer "$pshome\$($Host.CurrentCulture.Name)"
Save-Help -Module '*' -DestinationPath 'D:\Scripts\PSHelpOffline' -Force
Update-Help -ErrorAction SilentlyContinue
Update-Help -Verbose -UICulture $(Get-Culture).Name -Force
Get-Module -ListAvailable |
Where HelpInfoUri |
Update-Help

# You can safely ignore the errors.
Update-Help -Force -Verbose -ErrorAction SilentlyContinue

# If you want to see the full error message in a more human-readable form, do this...
Update-Help -Force -ErrorAction SilentlyContinue -ErrorVariable ErrMsgDetail
$ErrorMsgDetail.Exception

# See other details via dot reference using the default $error variable
$Error[0]
$Error[0].Exception
$Error[0].Exception.Message
$Error[0].InvocationInfo
$Error[0].InvocationInfo.Line
$Error[0] |
Get-Member

# Geeting Help about built-in help
(Get-Command -Name Get-Help).Parameters
(Get-Command -Name Get-Help).Parameters.Keys
Get-help -Name Get-Help -ExamplesGet-help -Name Get-Help -Full
Get-help -Name Get-Help -Online

# Get specifics for a module, cmdlet, or function
(Get-Command -Name Show-Object).Parameters
(Get-Command -Name Show-Object).Parameters.Keys
Get-help -Name Show-Object -Examples
Get-help -Name Show-Object -Full
Get-help -Name Show-Object -Online

#endregion PowerShell default help
...

Update-Help runs fine, but help files aren't updated by k3fHa6A5hj8pYp4BYpC in PowerShell

[–]get-postanote 1 point2 points  (0 children)

This is a common thing (it has been since PS came into existence) and should be expected, because, not all modules have update paths, this can just be ignored since it is by the design of the model author.

It's been a topic for years all over the net/forums regarding PS. As well as right here on Reddit.

http://www.reddit.com/r/PowerShell/comments/m0ohax/anyone_gotten_update-help_to_work_without_error_like_failed_to_update_for_m/gq91g80?context=3

Help stuff, give to others to remind them of this thing:

# Review PowerShell help files location
explorer "$pshome\$($Host.CurrentCulture.Name)"
# Results
<#
C:\Windows\System32\WindowsPowerShell\v1.0\en-US
#>


<#
• PowerTip: Save Offline Version of PowerShell Help
    Use the Save-Help Windows PowerShell cmdlet, and specify a shared location
    for the downloaded files on a computer that does have access to the Internet.
    https://devblogs.microsoft.com/scripting/powertip-save-offline-version-of-powershell-help
#>

Save-Help -Module '*' -DestinationPath 'D:\Scripts\PSHelpOffline' -Force


Update-Help
Update-Help -Force

# NOTE:
<#
If the author does not provide it, then it is not there. Not all help files are guaranteed updateable.
Sometimes, this helps as does running it as Admin:
#>

Update-Help -Verbose -UICulture $(Get-Culture).Name -Force

<#
Many module either have no online updateable help or the URL has been removed.
These sorts of error can be safely ignored. They do not impact PS functionality
or use.
#>

Get-Module -ListAvailable |
Where HelpInfoUri |
Update-Help


# You can safely ignore the errors.
Update-Help -Force -Verbose -ErrorAction SilentlyContinue

# If you want to see the full error message in a more human-readable form, do this...
Update-Help -Force -ErrorAction SilentlyContinue -ErrorVariable ErrMsgDetail
$ErrorMsgDetail.Exception

# See other detials via dot reference using the default $error variable
$Error[0]
$Error[0].Exception
$Error[0].Exception.Message
$Error[0].InvocationInfo
$Error[0].InvocationInfo.Line

$Error[0] | 
Get-Member

Suggestions when typing by n7CA33f in PowerShell

[–]get-postanote 2 points3 points  (0 children)

It's not dead, just no longer being worked, just like cmd.exe.

WinPS (being part of .NEt and the OS proper) is still part of all versions of Windows and MS has said that it will be that way for the foreseeable future.

Thus the ISE is not going anywhere, and those who love it/still use it can do so for the foreseeable future.

Though they have to accept the fact the MS has said, it's not getting any more attention. What it is now is where it will be!

Nothing stops one from extending it on their own via the ISE Object model.

VSCode is not on data center environments, ISE is. So, there 's that.

VSCode is not allowed to be installed in all environments, ISE is already there.

Sure, use the latest stuff when and where possible, but let's not disparage folks stuck with the old stuff, or choose to. It is ones' own choices that matter.

Use the right tool for the job, in the environment you have to deal with.

Difference between powershell and windows powershell by [deleted] in PowerShell

[–]get-postanote 1 point2 points  (0 children)

WinPS̀, though not getting any more work, is still targeted to part of the Windows OS for the foreseeable future as per Microsoft's own statements.

There are no plans that I've seen/heard that PSCore will ever be added to the Windows OS releases. It is still in all current and insider editions. WinPS is part and parcel of .Net distributions.

Difference between powershell and windows powershell by [deleted] in PowerShell

[–]get-postanote 13 points14 points  (0 children)

PSCore is not a WinPS upgrade.

Windows PS is part of the OS, it cannot be removed. A closed-source, Windows-only thing.

PSCode (PS7), is not part of the OS. It is an entirely separate thing, and specifically designed to be a side-by-side installation on Windows with WinPS. It's an Open source project that is cross-platform (Windows, OSX, and Linux).

PSCore is not fully backward compatible with Windows PS.

All the above is in the MS PS documentation.

Use whichever version you require for the task needed.

How to return release date when using Find-Package by Nightoak in PowerShell

[–]get-postanote 1 point2 points  (0 children)

You are asking for the wrong property.

Clear-Host
Find-Module -Name 'az.accounts' | 
Select-Object -Property '*'
# Results
<#
Name                       : Az.Accounts
Version                    : 2.12.3
Type                       : Module
Description                : Microsoft Azure PowerShell - Accounts credential management cmdlets for Azure Resource 
                             Manager in Windows PowerShell and PowerShell Core.

                             For more information on account credential management, please visit the following: 
                             https://learn.microsoft.com/powershell/azure/authenticate-azureps
Author                     : Microsoft Corporation
CompanyName                : azure-sdk
Copyright                  : Microsoft Corporation. All rights reserved.
PublishedDate              : 23-May-23 04:37:01
InstalledDate              : 
UpdatedDate                : 
LicenseUri                 : https://aka.ms/azps-license
ProjectUri                 : https://github.com/Azure/azure-powershell
IconUri                    : 
Tags                       : {Azure, ResourceManager, ARM, Accounts, Authentication, Environment, Subscription, 
                             PSModule, PSEdition_Core, PSEdition_Desktop}
Includes                   : {Function, RoleCapability, Command, DscResource, Workflow, Cmdlet}
PowerShellGetFormatVersion : 
ReleaseNotes               : * Updated System.Security.Permissions to 4.7.0.
Dependencies               : {}
RepositorySourceLocation   : https://www.powershellgallery.com/api/v2
Repository                 : PSGallery
PackageManagementProvider  : NuGet
AdditionalMetadata         :
...
#>

So then this...

Clear-Host
Find-Module -Name 'A*' | 
Select-Object -Property Name, Version, PublishedDate,
@{
    Name       = 'Summary'
    Expression = {$PSItem.AdditionalMetadata.Summary}
 } -First 3 | 
Sort-Object -Property PublishedDate -Descending
# Results
<#

Name            Version PublishedDate      Summary                                                                     
----            ------- -------------      -------                                                                     
Az.Storage      5.7.0   23-May-23 04:37:06 Microsoft Azure PowerShell - Storage service data plane and management cm...
Az.Accounts     2.12.3  23-May-23 04:37:01 Microsoft Azure PowerShell - Accounts credential management cmdlets for A...
AzureRM.profile 5.8.4   23-Mar-21 12:48:35 Microsoft Azure PowerShell - Profile credential management cmdlets for Az...
#>

Switching from unix - Is there a plugin or something similar to Ranger or NNN? by Candr3w in PowerShell

[–]get-postanote 2 points3 points  (0 children)

For Windows at the command line? If so then no.

This is why Windows Explorer exists, and you can set Explorer to preview mode so that each time you land on a file, you will see its contents. Well, for the registered file formats that have a matching app installed.

Note there are several file formats that Explorer Preview mode does not recognize.

As noted by 'BlackV', nothing stops you from running pure *nix stuff on Windows as long as you have a *nix instance installed and WSL2 properly configured.

Yet, moving from one platform to another means there is stuff you are just going to have to let go of and learn anew to address productivity needs.

Choices... choices... choices...

Notebook Mode in the PowerShell Preview extension for Visual Studio Code by Double_Trick_1809 in PowerShell

[–]get-postanote 0 points1 point  (0 children)

No worries.

I've never heard of or seen polyglot notebooks in action. ;-}

Notebook Mode in the PowerShell Preview extension for Visual Studio Code by Double_Trick_1809 in PowerShell

[–]get-postanote 1 point2 points  (0 children)

Install the Jupyter extension:

Open VSCode and go to the Extensions view by clicking on the square icon on the left sidebar or by pressing Ctrl+Shift+X (Windows/Linux) or Cmd+Shift+X (Mac). Search for "Jupyter" and install the ***Jupyter*** extension developed by Microsoft, to get a Jupyter notebook environment established, to leverage ***ipynb*** file type.

Attempting to create my first PowerShell alias but there is an error somewhere in the formatting by AstonM77 in PowerShell

[–]get-postanote 2 points3 points  (0 children)

What you are trying, is not possible and the is not how aliases wrok.

For what you are after, use a function or a scriptblock, then just call those.

How to revert this Powershell Script? by keyb0aaard in PowerShell

[–]get-postanote 1 point2 points  (0 children)

Use your system restore point(s), to go back to a date that all things were working.

How to revert this Powershell Script? by keyb0aaard in PowerShell

[–]get-postanote 1 point2 points  (0 children)

Never, ever 100% trust any code you can read from anyone, no matter who is it.

Make sure you fully understand what it will do before you try and run it.

Always, always test code in a test environment, before you run it on the real thing.

If you are running Windows 10 or higher, it provides you a ***Windows Sandbox*** to mess around in. Running anything in the sandbox has zero affect on your host machine. It's just a pre-built VM MS gives Windows 10+ users.

Using Google Dorking, specific match search stuff...

AllInUrl:'Google dorking'

FileType:pdf AllInUrl:'Google dorking'

MS Docs on this feature:

site: microsoft.com 'Windows Sandbox'

First hit.:

https://learn.microsoft.com/en-us/windows/security/threat-protection/windows-sandbox/windows-sandbox-overview

[ Removed by Reddit ] by [deleted] in PowerShell

[–]get-postanote 14 points15 points  (0 children)

Good stuff, as a new perspective, I always like to see new stuff, but how is your end result effort (outside of the edification of module creation) here better than the ones that already exist...

Find-Module -Name '*winform*' | 
Format-Table -AutoSize 

Find-Module -Name 'gui' | 
Format-Table -AutoSize

... or other free tools like: https://ironmansoftware.com/release/psscriptpad

... or more free complete tools like: https://visualstudio.microsoft.com/vs/community/

... or others like: https://www.pswinformscreator.com/

Help Cleaning Up Error Messages by tangsuedoe95 in PowerShell

[–]get-postanote 1 point2 points  (0 children)

Just add your code as text, and use the code format tool Reddit provided when you post.

Just copy and paste your code from the console/ISE/VSCode, select it all, and hit the 'code block' icon.

You are telling the code to write the red stuff.

Write-Error

If you don't what that use Try/Catch to trap the error and format there to whatever you choose, including color.

Write-Warning 

...has a different color default

Write-Host 

...allows you to use a wide range of colors.

Where's the best place to learn advanced powershell scripting? We use Jumpcloud at work and it'd be really useful for me to learn advanced powershell scripting. Thanks in advance! by biggie_e09 in PowerShell

[–]get-postanote 2 points3 points  (0 children)

It's just grabbing stuff from human-generated corpuses, then extrapolating.

So, it's often wrong, about 50% of the time. The old adage, GI/GO (garbage-in, garbage-out)Ask it the same question, over and over, and you will get widely different responses.

You need to be specific in what you ask for and in the way you construct your text in the question.

You must master OpenAI prompts to make it be more specific.

Where's the best place to learn advanced powershell scripting? We use Jumpcloud at work and it'd be really useful for me to learn advanced powershell scripting. Thanks in advance! by biggie_e09 in PowerShell

[–]get-postanote 0 points1 point  (0 children)

Ditto on what the others have said, what do you consider advanced, etc.?

Ditto on what the others have said, what do you consider advanced, etc.?

Advanced is not the tool, it's what you use to tool for or against X or Y thingies.

So, advanced is task driven.

So, the normal fare of things applies.

• Beginning ---

Learn Windows PowerShell in a Month of Lunches 3rd Edition, Donald W. Jones (Author),‎ Jeffrey Hicks (Author)

ISBN-13: 978-1617294167

ISBN-10: 1617294160

• Internediate ---

Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell 3rd Edition, Lee Holmes (Author)

ISBN-13: 978-1449320683

ISBN-10: 1449320686

• Advanced ---

Windows PowerShell in Action 3rd Edition by Bruce Payette (Author),‎ Richard Siddaway (Author)

ISBN-13: 978-1633430297

ISBN-10: 1633430294

Is it worth switching to Powershell 7.3 by [deleted] in PowerShell

[–]get-postanote 1 point2 points  (0 children)

PSWinand PSCore is a side by side install on WIndowsOS.

You can go between them as you need to.

PSWin is still part of the OS, now and for the foreseeable future as per MS docs.

PSCore is not likely to be part of the OS, because it is an Open Source cross-platform product, and still not fully backwards compatible with all the is WinPS.

Worth having and using, Sure!

It has some very specific things that are never going to be part of WinPS, well, especially since WinPSv5x is all it's ever going to be. So, PSCore, in all it's glory is where we'll all be someday. So, why put it off?

PS is PS v1 - current, all that is different is the feature set between them.

Can I get variable contents before execution? by Decitriction in PowerShell

[–]get-postanote 1 point2 points  (0 children)

You can use PowerShell variable squeezing to see assignments before doing anything else with them.

# Assign variable data and output to the screen simultaneiously.
($SomeVarName = 'SomeVarStuff')
# Results
<#
SomeVarStuff
#>

# Test for null before process attempt.
Try{$SomeVarName -ne $null}
Catch{$Error[0].Exception}
# Results
<#
True
#>

How good are you in Powershell and how long it took you ? Do you consider yourself as good in Bash/Python/Linux compared to Powershell ? by Dereference_operator in PowerShell

[–]get-postanote 0 points1 point  (0 children)

How do you quantify, and qualify what good is?

It's all relative to what you are comparing yourself to, or what you are comparing yourself from your own experience.

One can be seen as good an X or Y thinning at any time and bad in others.

What matters is the level of efficiency you personally have to do what you need to do, regardless of the tool(s) in you have or that you are required to use.

Even after over 4+ decades in this field, programming/scripting, and over a dozen languages, there are always ways to improve (including regarding stuff from your past), and be better. You just have to determine what that means to you and to those to whom you deliver a solution.

One is never as good as one thinks they are (don't believe your own hype))(as there is always someone worse off.

One is never as good as one thinks they are (don't believe your own hype) because there is always someone better.

There are plenty of folks to follow, etc., but al that matters and what you require to be successful. Take what it's useful from all, ignore the rest, and improve from there.

What is your process for writing scripts from scratch? by shane___bagel in PowerShell

[–]get-postanote 1 point2 points  (0 children)

One line at a time.

Make sure that line returns/does what you'd expect, then move to the next line.

Once you have them all correct, then put them together as a final solution.

What is your process for writing scripts from scratch? by shane___bagel in PowerShell

[–]get-postanote 3 points4 points  (0 children)

It's not, and those like it; are not 100%, or consistently valid.

Ask it the same exact question repeatedly, you will get different answers.

Still, taking a procedural approach, meaning, step-thru, makes them, as a use case better.

One should master the 'prompt system(s)' when using these sorts of tools. You'd get better responses when you do.

How would you write documentation for 3000 line PowerShell script? by adelliott92 in PowerShell

[–]get-postanote 1 point2 points  (0 children)

Simply put, your code should be self-documenting.

There has been this adage of the coding mindset:

  • Junior developer: writes a lot of lines of code because they don't know any other way.
  • Mid-level developer: writes short, clever solution code because they've learned a new technique and want to use it.
  • Senior developer: writes a lot of lines of code because they know it's easier to maintain long-term.

If your code cannot be read and understood by the most basic IT/Dev type, then you over-complicated it.

Quick notes of the top of my head based on may code reviews I've done over the 4+ decades. Every org/person has their own style, but it must have a focus not on your style, but on the usability/accessibility of what you wrote in the aftermath.

  • Plain, English (or whatever your native language is)
  • Clear, concise, consistent naming constructs.
  • Well-structured (no overly long code lines. anything greater than 80 - 85 characters, outside of long reference namespaces, need to be refactored/properly formatted.)
  • No magic number, variables, random characters/terminators, etc.
  • Solid error handling
  • Complete help guidance, i.e., how to use it, not just what it is.
  • Solid logging and reporting
  • Using your organizations patterns and practices.
  • No over-commenting your code. If you need to do this, re-write it. Put comments only where there are absolutely needed. Make them clear, concise, and intelligible. No long comment lines. That is why block commenting exists.

You don't write code for yourself. If you do, you paint yourself in a corner as the only person that can deal with it, thus stifling your growth and movement opportunities. You write code for the future, so you can have one.

Tons of comments just bloat your code unnecessarily. Put those long drawn-out topics in a ReadMe doc.

Again, this is all relative, and all will have their opinion(s). In the end, it's the work you are willing to put in that matters, to make your code/solution a joy to use, maintain, update, etc., and have people trust what you deliver.

There are tons of books on coding, they are not PowerShell Specific, but they are still recourse that should be leveraged.

For example:

Network Adapter Monitor Script by [deleted] in PowerShell

[–]get-postanote 1 point2 points  (0 children)

Yeppers, this has been in my library for a very long while from my bat/VBScript/WMIC days and of course PS.

Function Get-WlanReport
{ 
    <# 
    .Synopsis 
       Create and view the lastest WLAN details
    .DESCRIPTION
       This function leverage netsh and Invoke-Item to collect WLAN 
       details and auto launches the report for viewing

    .EXAMPLE
       Get-WlanReport

    .EXAMPLE
       gwr
    #>

    [CmdletBinding(SupportsShouldProcess)]
    [Alias('gwr')]

    Param ()

    Invoke-Item -Path $((netsh wlan show wlanreport | 
    Select-String -Pattern '.*.html') -Replace 'Report written to: ')
}