Skip to main content

r/PowerShell


Stop using [System]
Stop using [System]
Script Sharing

I'm getting old enough that my fingers hate my lifetime of programming.

I'll save a few keystrokes where I can.

There's something simple most people don't seem to know about PowerShell syntax.

It saves seven characters of typing every you use this, and runs a tiny bit faster.

You never need to specify stuff is in the [System] namespace.

Stop Using [System]

.NET is a huge framework with tons of useful stuff in it. There's a lot of stuff in the System namespaces. Built-in framework functionality often exists in one of the many namespaces in System.

By the time PowerShell was being built, it was pretty clear that leveraging .NET was worth it, and that most people wouldn't want to type six to seven more characters every time.

So, since PowerShell v1, you haven't had to.

You can omit the [System] in any type in any system namespace

So instead of:

 [system.collections.generic.list[string]]

We can write:

 [collections.generic.list[string]]

Instead of:

 [System.Collections.IDictionary]

We can write:

 [Collections.IDictionary]

This is true for every system type. On my machine, there are 4722 public types in the system namespace. That's 33054 characters I will never have to type.

It makes scripts shorter and simpler to read.

Also, when PowerShell resolves types, it checks for the shorter names first. This saves a very tiny amount of time in each of your scripts. (I was corrected)

Yet, sadly, I see the system namespace everywhere in people's scripts.

I beg of you all:

  • Save your fingers

  • Make scripts shorter

Stop Using [System]


Advertisement: The 4-4-2? Long throws? Superstar subs? Analyse your team’s potential winning tactics with ChatGPT.
The 4-4-2? Long throws? Superstar subs? Analyse your team’s potential winning tactics with ChatGPT.
The 4-4-2? Long throws? Superstar subs? Analyse your team’s potential winning tactics with ChatGPT.


Try to set the Org SharePoint Sharing Link Retention
Try to set the Org SharePoint Sharing Link Retention
Question

As per title really I want to set a few values for these settings

Set-SPOTenant -CoreOrganizationSharingLinkMaxExpirationInDays 365

Set-SPOTenant -OneDriveOrganizationSharingLinkMaxExpirationInDays 365

And a couple for Link recommendations as an example.

Questions:

    1. Is SPO still active? And if yes, should I install the module and use that over PNP?

  • 1a) I thought I read it was going to be removed shortly.

  • I have PNP installed correctly and can log in to it, so can I set this with PNP?

  • 2) I tried Set-PNPTenant -CoreOrganizationSharingLinkMaxExpirationInDays 365 and it throws an error for the Set-PNPTenant

So I'm not sure if it's possible with PNP.

  • 3) Also If I use Get-SPOTenant and Get-PNPTenant are they settings the same?

Im very amateur at code, so quite possibly I'm doing it wrong.

Thoughts?