Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Pile Of Garbage
May 28, 2007



Antigravitas posted:

Bingo. It's a new day, just got into the office, did a git diff on a lark, and found this piece of code within the module:

code:
$DebugPreference = 
Here's how you, too, can suffer. Save this code as a .psm1 and import-module it:

code:
Set-StrictMode -Version "2.0"
$ErrorActionPreference = "Stop"
$DebugPreference =
function Write-Log {
    Write-Debug "Test"
} 
Then invoking Write-Log will throw the exception (PSVersion 5.1 FWIW)

Surprised that imported at all what with a glaring syntax error. Also I hope the module you're developing is only a collection of functions and nothing more.

Adbot
ADBOT LOVES YOU

Antigravitas
Dec 8, 2019

Die Rettung fuer die Landwirte:
It imports without any error whatsoever, indeed.

And yes, it's basically just some wrapper functions around the actual logging code that's written in a sane language.

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord
Does anyone know if it's possible to force O365 to sync with AD? I've got a script to provision an AD user, but I can't provision their service licensing until MSOL gets around to refreshing, which can be up to 30 minutes. I searched around and didn't see anything, but I figured I'd ask.

Pile Of Garbage
May 28, 2007



PierreTheMime posted:

Does anyone know if it's possible to force O365 to sync with AD? I've got a script to provision an AD user, but I can't provision their service licensing until MSOL gets around to refreshing, which can be up to 30 minutes. I searched around and didn't see anything, but I figured I'd ask.

From what you describe I'm assuming you're allocating licenses via groups in Azure AD and are syncing on-prem AD to Azure AD via AADC. If that's the case you can trigger an AADC sync cycle manually by running Start-ADSyncSyncCycle -PolicyType Delta from your AADC server.

Edit: it's not a good idea to run manual syncs super frequently as they can start backing-up.

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

Pile Of Garbage posted:

From what you describe I'm assuming you're allocating licenses via groups in Azure AD and are syncing on-prem AD to Azure AD via AADC. If that's the case you can trigger an AADC sync cycle manually by running Start-ADSyncSyncCycle -PolicyType Delta from your AADC server.

Edit: it's not a good idea to run manual syncs super frequently as they can start backing-up.

It’s for a team that gets 3-4 user adds per day, so it shouldn’t be too bad. Thanks for the quick response, I’ll give it a shot.

Pile Of Garbage
May 28, 2007



PierreTheMime posted:

It’s for a team that gets 3-4 user adds per day, so it shouldn’t be too bad. Thanks for the quick response, I’ll give it a shot.

You can modify the sync schedule, default is 30 minutes: https://docs.microsoft.com/en-us/azure/active-directory/hybrid/how-to-connect-sync-feature-scheduler

I'd recommend batching user adds if at all possible. Maybe establish a process where all currently requested users are processed at set times throughout the day?

The last customer I supported who ran AADC with O365 had their on-prem user provisioning automated by CA IAM which was triggered by SAP integrations. HR would request users via SAP and provisioning ran at midnight so users would always be ready to go by start-of-business. It was a giant fuckin pile of garbage (Especially the CA IAM stuff) but it worked like a charm.

Pile Of Garbage fucked around with this message at 15:44 on Jan 23, 2020

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

Pile Of Garbage posted:

You can modify the sync schedule, default is 30 minutes: https://docs.microsoft.com/en-us/azure/active-directory/hybrid/how-to-connect-sync-feature-scheduler

I'd recommend batching user adds if at all possible. Maybe establish a process where all currently requested users are processed at set times throughout the day?

The last customer I supported who ran AADC with O365 had their on-prem user provisioning automated by CA IAM which was triggered by SAP integrations. HR would request users via SAP and provisioning ran at midnight so users would always be ready to go by start-of-business. It was a giant fuckin pile of garbage (Especially the CA IAM stuff) but it worked like a charm.

The current ask I have is from an offshore client team that receives new user requests in the form on an Excel spreadsheet and they're driven by SLA and all that fun to get them done as soon as possible. So I've got a script that sorts their users into an OU bucket, applies various groups, sets their access, and then has the capability to provision licensing but as discussed has to wait for that. They also have a mess of other bespoke third party services they want included but most don't have an API so they're SOL on that angle; they've gone the route of having a "robotic process automation" scripted event to mouse-click their way through the other stuff.

Antigravitas
Dec 8, 2019

Die Rettung fuer die Landwirte:
Powershell more like Powers Hell, amirite? :haw:

Pile Of Garbage
May 28, 2007



PierreTheMime posted:

The current ask I have is from an offshore client team that receives new user requests in the form on an Excel spreadsheet and they're driven by SLA and all that fun to get them done as soon as possible. So I've got a script that sorts their users into an OU bucket, applies various groups, sets their access, and then has the capability to provision licensing but as discussed has to wait for that. They also have a mess of other bespoke third party services they want included but most don't have an API so they're SOL on that angle; they've gone the route of having a "robotic process automation" scripted event to mouse-click their way through the other stuff.

:lol: that sounds just like the setup I described: the SAP to CA IAM integration was literally just SAP HRIS writing a CSV to an SMB share and then CA IAM ingests that file, reconciles it against its own databases and then does the needful in AD. poo poo's a minefield of garbage, good luck.

Edit: oh yeah make sure to appropriately adjust the sync scope of AADC so that it only includes containers/OUs that you need to sync. By default it'll sync all containers/OUs in the domain which is cooked and well worth adjusting.

Antigravitas posted:

Powershell more like Powers Hell, amirite? :haw:

I prefer PissHell

Pile Of Garbage fucked around with this message at 17:27 on Jan 23, 2020

Inspector_666
Oct 7, 2003

benny with the good hair
Ok this is probably a dumb question that I am not googling correctly but: Is there a way I can get the Exchange Online cmdlets to populate in VSCode so I can tab-complete them/the parameters while working on scripts? For example Get-CalendarProcessing or Get-User and the like?

Toast Museum
Dec 3, 2005

30% Iron Chef

Inspector_666 posted:

Ok this is probably a dumb question that I am not googling correctly but: Is there a way I can get the Exchange Online cmdlets to populate in VSCode so I can tab-complete them/the parameters while working on scripts? For example Get-CalendarProcessing or Get-User and the like?

I tried it just now. After running Install-Module ExchangeOnline from PowerShell, Intellisense includes the module's cmdlets in VSCode without any additional configuration. Do you have the PowerShell extension installed in VSCode?

Inspector_666
Oct 7, 2003

benny with the good hair

Toast Museum posted:

I tried it just now. After running Install-Module ExchangeOnline from PowerShell, Intellisense includes the module's cmdlets in VSCode without any additional configuration. Do you have the PowerShell extension installed in VSCode?

Yep, that did it. I knew it was something dumb I wasn't thinking of. I seldom use the integrated PS terminal so I always forget about it.

Fhistleb
Dec 31, 2008

Tell me more about your sandwiches.
Hope this is the right place, I just got tasked with learning powershell and using it in our environment.

Does anyone know a good place to start off?

The Fool
Oct 16, 2003


Powershell in a month of lunches is widely recommended

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

Fhistleb posted:

Hope this is the right place, I just got tasked with learning powershell and using it in our environment.

Does anyone know a good place to start off?

It really depends on what exactly you’re looking to do, as it’s a fairly broad language. Generally Microsoft’s own documentation is very solid. There’s a good number of tutorials out there; what are you planning to use it for?

adaz
Mar 7, 2009

The resources on Pluralsight are all great too. The channel 9 team did a good jump start series on powershell 3 awhile back. Powershell 3 is a few versions old but the basics of the language itself havent changed that much since then.

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

adaz posted:

The resources on Pluralsight are all great too. The channel 9 team did a good jump start series on powershell 3 awhile back. Powershell 3 is a few versions old but the basics of the language itself havent changed that much since then.

Coming from an OOP angle I will say I’ve ended up using classes a lot and would recommend them if they suit your post v5 needs.

adaz
Mar 7, 2009

PierreTheMime posted:

Coming from an OOP angle I will say I’ve ended up using classes a lot and would recommend them if they suit your post v5 needs.

Yeah fair - but technically classes have always existed they just added some syntax sugar around to make it easier to use inside the shell instead of falling back to more native .NET constructs.

Always a good point (and not sure where Fhistleb is coming from) learning powershell is very different depending on your background. If you come from a C# .NET background it's very important to realize that under the hood you can just inline C# if you care to or use stuff like classes now. If you're a linux admin used to bash learning cmdlets / pipe syntax / powershell core is probably more important.

Fhistleb
Dec 31, 2008

Tell me more about your sandwiches.

PierreTheMime posted:

It really depends on what exactly you’re looking to do, as it’s a fairly broad language. Generally Microsoft’s own documentation is very solid. There’s a good number of tutorials out there; what are you planning to use it for?

One of the first things I was tasked with was moving archive logs to another server. I'm just going to jump from there.

adaz
Mar 7, 2009

Fhistleb posted:

One of the first things I was tasked with was moving archive logs to another server. I'm just going to jump from there.

https://devblogs.microsoft.com/scripting/

The scripting guys blog is, in general, a great place for stuff like this. Few paragraphs on how to do common powershelly things like moving files and so forth.

Fhistleb
Dec 31, 2008

Tell me more about your sandwiches.

adaz posted:

https://devblogs.microsoft.com/scripting/

The scripting guys blog is, in general, a great place for stuff like this. Few paragraphs on how to do common powershelly things like moving files and so forth.

Awesome! Thank you!

Toast Museum
Dec 3, 2005

30% Iron Chef

I think you meant to link this one. PowerShell Scripting in a Month of Lunches is by the same authors and also good, but it's a lot less introductory. I hope that both books get updated for PowerShell 7, but 5.1 is similar enough (and still so widespread) that it's not a huge loss just yet.

One of the Month of Lunches authors (I forget which) also did a lot of the the PluralSight tutorials on PowerShell. I don't love video tutorials for this sort of thing, but the content is good, if that's a format that works for you.

Whatever training resources you end up using, supplement it by trying to find ways to incorporate PowerShell into your actual work. Immediate applicability definitely helped the concepts stick for me.

adaz
Mar 7, 2009

I really should update the OP with all this, a lot has changed since I started this thread.

Toshimo
Aug 23, 2012

He's outta line...

But he's right!

adaz posted:

I really should update the OP with all this, a lot has changed since I started this thread.

You could always.... start a new thread.

The Fool
Oct 16, 2003


Toast Museum posted:

I think you meant to link this one. PowerShell Scripting in a Month of Lunches is by the same authors and also good, but it's a lot less introductory. I hope that both books get updated for PowerShell 7, but 5.1 is similar enough (and still so widespread) that it's not a huge loss just yet.

One of the Month of Lunches authors (I forget which) also did a lot of the the PluralSight tutorials on PowerShell. I don't love video tutorials for this sort of thing, but the content is good, if that's a format that works for you.

Whatever training resources you end up using, supplement it by trying to find ways to incorporate PowerShell into your actual work. Immediate applicability definitely helped the concepts stick for me.

You are correct, I was phone posting and didn't look closely.

adaz
Mar 7, 2009

Toshimo posted:

You could always.... start a new thread.

I could've! but I did update the OP a bit with more up to date links. WIll add some better code examples too

Toast Museum
Dec 3, 2005

30% Iron Chef

PierreTheMime posted:

Coming from an OOP angle I will say I’ve ended up using classes a lot and would recommend them if they suit your post v5 needs.

How do you tend to use them?

PowerShell classes feel like a trap to me. I like them and use them where I can, but using them in modules is so poorly supported. I was hoping that PowerShell 7 would bring module manifests that can handle classes, but I haven't seen that in any changelogs.

On the bright side, "gently caress it, I'll figure out how to make a compiled module" is why I'm starting to learn C#

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

Toast Museum posted:

How do you tend to use them?

PowerShell classes feel like a trap to me. I like them and use them where I can, but using them in modules is so poorly supported. I was hoping that PowerShell 7 would bring module manifests that can handle classes, but I haven't seen that in any changelogs.

On the bright side, "gently caress it, I'll figure out how to make a compiled module" is why I'm starting to learn C#

My needs are pretty simple, but for complex operations I find its helpful to organize related actions and encapsulate things into their appropriate place so you can return a resulting value or object with just what you want, hiding/discarding everything else. Passing multiple values around in a class is a lot simpler than functions, which is something I do often. I'm sure there's other things I can't think of at the moment, but I use them primarily because I have OOPoisoning and any time I look at scripts that require multiple steps I think "how can I make a class out of this".

Antigravitas
Dec 8, 2019

Die Rettung fuer die Landwirte:
Trying to use Powershell as a general purpose programming language is a trap and classes are one example. When you are writing a Powershell class you enter the twilight zone between Powershell and writing a good language. The syntax is suddenly different and things are strongly-ish typed and that's a recipe for disaster. It's like you are suddenly writing a severely oxygen deprived C#.

Just implement a type in C# and write the glue in Powershell.

Toast Museum
Dec 3, 2005

30% Iron Chef

PierreTheMime posted:

My needs are pretty simple, but for complex operations I find its helpful to organize related actions and encapsulate things into their appropriate place so you can return a resulting value or object with just what you want, hiding/discarding everything else. Passing multiple values around in a class is a lot simpler than functions, which is something I do often. I'm sure there's other things I can't think of at the moment, but I use them primarily because I have OOPoisoning and any time I look at scripts that require multiple steps I think "how can I make a class out of this".

Nah, that all makes sense, and it's a lot of the same reasons I keep reaching for them. If I recall correctly, Microsoft introduced PowerShell classes mostly with DSC in mind, which I guess explains some of the weird feature gaps.


Antigravitas posted:

Trying to use Powershell as a general purpose programming language is a trap and classes are one example. When you are writing a Powershell class you enter the twilight zone between Powershell and writing a good language. The syntax is suddenly different and things are strongly-ish typed and that's a recipe for disaster. It's like you are suddenly writing a severely oxygen deprived C#.

Just implement a type in C# and write the glue in Powershell.

I can't really disagree, and I'm kinda kicking myself for not considering the hybrid approach you suggest. That can still represent a big jump in complexity, though. Like, trading Invoke-RestMethod for System.Net.Http feels like running into a wall.

adaz
Mar 7, 2009

Toast Museum posted:

Nah, that all makes sense, and it's a lot of the same reasons I keep reaching for them. If I recall correctly, Microsoft introduced PowerShell classes mostly with DSC in mind, which I guess explains some of the weird feature gaps.


I can't really disagree, and I'm kinda kicking myself for not considering the hybrid approach you suggest. That can still represent a big jump in complexity, though. Like, trading Invoke-RestMethod for System.Net.Http feels like running into a wall.

Dot net core make both of those easier - the newish HTTPClient interface is much easier for .net and HTTP REPL is in many cases easier than invoke-restmethod although YMMV etc

Antigravitas
Dec 8, 2019

Die Rettung fuer die Landwirte:

Microfuckingsoft posted:

"For computer's [sic!] without any version of PowerShellGet installed, a computer with PowerShellGet installed is needed to download the [PowerShellGet] modules"

The Fool
Oct 16, 2003


While lovely, isn't it only really an issue for ancient versions of powershell?

Antigravitas
Dec 8, 2019

Die Rettung fuer die Landwirte:
Anyone competent would just have a discoverable package index you could download a package from. I was looking into providing Powershell modules for airgapped systems. Setting up a controlled Debian mirror is trivial, but this is just typical Microsoftian bullshit.

There's decades worth of accumulated knowledge around package management and MS is ignoring all of it.

Zaepho
Oct 31, 2013

Antigravitas posted:

Anyone competent would just have a discoverable package index you could download a package from. I was looking into providing Powershell modules for airgapped systems. Setting up a controlled Debian mirror is trivial, but this is just typical Microsoftian bullshit.

There's decades worth of accumulated knowledge around package management and MS is ignoring all of it.

Save-Module or Save-Package works on non-airgapped systems to download something.

Beyond that you can setup your own repo with something a simple as a fileshare or as complicated with nuGet as you want to get.

Toast Museum
Dec 3, 2005

30% Iron Chef
Since it looks like it's only an issue for PowerShell 4 and older, I wouldn't be shocked if the hassle were intended as a nudge to update WMF/PowerShell.

Junkiebev
Jan 18, 2002


Feel the progress.

Antigravitas posted:

Anyone competent would just have a discoverable package index you could download a package from. I was looking into providing Powershell modules for airgapped systems. Setting up a controlled Debian mirror is trivial, but this is just typical Microsoftian bullshit.

There's decades worth of accumulated knowledge around package management and MS is ignoring all of it.

look up BaGet - it can even run in a Docker container

FISHMANPET
Mar 3, 2007

Sweet 'N Sour
Can't
Melt
Steel Beams
It is kind of shocking how much it sucks managing PowerShell modules, and especially how instead of one big obvious sucky part, it feels like death by a thousand cuts where every little bit sucks just a little bit.

Inspector_666
Oct 7, 2003

benny with the good hair
I'm back again with a dumb question I can't properly articulate into Google.

I'm trying to generate a list of all of our groups in O365 along with their owner(s). That's easy enough:

code:
PS C:\Users> Get-Group -Identity * -ResultSize Unlimited | select DisplayName,SamAccountName,WindowsEmailAddress,ManagedBy | Export-Csv -Path "C:\Users\Documents\PSReporting\AllGroupsManagedBy.csv"
But the issue is that if there are multiple group owners, the array gets converted into a string and just gets slapped into a single cell in the CSV. I realize I can't have it keep the comma between them when it Exports even with a different delimiter, but is there any way to get it to just put them in separate cells?


The output is Full Name Full Name, so I guess it might just be easier to convert the CSV into a proper Excel file and just do the string manipulation there.

Adbot
ADBOT LOVES YOU

The Fool
Oct 16, 2003


Maybe a calculated property?

E: https://4sysops.com/archives/add-a-calculated-property-with-select-object-in-powershell/

Phone posting, but maybe I’ll write up an example when I get back to my desk.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply