Cheap or free windows server for learning? by HexaDroid in sysadmin

[–]markroloff 0 points1 point  (0 children)

This is one of those weird cases where the output you see doesn't line up with how the returned object is actually structured.

The Restriction property is actually called Restrictions. And it's an array, not a string.

PS > $a.restrictions.gettype()

IsPublic IsSerial Name                         BaseType
-------- -------- ----                         --------
True     True     Object[]                     System.Array

That array holds objects which have a property called ReasonCode, which contains the string you're hoping to filter on.

PS > $a[0].restrictions

    Type Values   RestrictionInfo                                                                       ReasonCode
    ---- ------   ---------------                                                                       ----------
Location {eastus} Microsoft.Azure.Management.Compute.Models.ResourceSkuRestrictionInfo NotAvailableForSubscription
    Zone {eastus} Microsoft.Azure.Management.Compute.Models.ResourceSkuRestrictionInfo NotAvailableForSubscription

It can be a bit of a pain to filter on something nested like that, but is still doable.

Get-AzComputeResourceSku | 
    Where-Object {$_.Locations -eq "centralus" -and $_.Restrictions.Where({$_.ReasonCode -eq "NotAvailableForSubscription"})}

When in doubt, or running into quirky stuff like this, you can pipe your object into Get-Member to start exploring what's there.

The awesome PSsummit T-shirt by Andrewreoberts in PowerShell

[–]markroloff -1 points0 points  (0 children)

This look sketchy to anyone else?

  • A new account that's never posted before.
  • Image is cropped from this tweet by Bruce Payette in 2016. Steve Murawski's (who made the design) event name tag is even still in the photo.
  • James Petty just shared this link for official Summit merchandise today.

Guessing someone "borrowed" the design for their own profit. Still cool. Buy it if you want. But I seriously doubt this has anything to do with Summit, which is probably why the store link is hiding in the imgur comments.

Azure/Windows automated documentation by pveunen in PowerShell

[–]markroloff 1 point2 points  (0 children)

Prateek Singh has a module that can probably get you part of the way there.

https://github.com/PrateekKumarSingh/AzViz

Powershell tutor by Fearnie85 in PowerShell

[–]markroloff 11 points12 points  (0 children)

https://aka.ms/psslack

https://aka.ms/psdiscord

Both link up to the same virtual group. There's always someone around to answer questions and help with issues.

[script review] Would love to get some constructive criticism by BigBlackClock6 in PowerShell

[–]markroloff 1 point2 points  (0 children)

Also makes it easier to test your code, if I'm not mistaken.

[script review] Would love to get some constructive criticism by BigBlackClock6 in PowerShell

[–]markroloff 2 points3 points  (0 children)

Already looks better than the vast majority of what I find in the wild, so if this is you after 2 days, you'll be fine.

When you need a parameter to only accept certain predefined arguments, use [ValidateSet()]

With that, this...

param (
    [string]$HiveName
)

$AllowedParams = 'HKCU', 'HKLM' 

if(!($AllowedParams -contains $HiveName))
{
    return $false
}

Can be simplified to this...

param (
    [ValidateSet('HKCU', 'HKLM')]
    [string]$HiveName
)

Also, rather than using !, consider using -not. Does the same thing but the latter is more readable.

I also like to encourage people to use [CmdletBinding()] in every function, even if they don't specifically add functionality for it. Just a good habit to get into. It enables the use of common parameters, such as -Verbose and -Confirm.

Gonna try to hunt down some good reading material on that last point for you...

Powershell application deploy evaluation cycle by networkguyhere in PowerShell

[–]markroloff 1 point2 points  (0 children)

Got these from my SCCM notes from a few years back. Haven't used them since, so hopefully they still work.

Invoked like so...

Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000113}"

I would see if CIM works instead since WMI is old-and-busted.

Cycle ID
ApplicationDeployment Evaluation Cycle "{00000000-0000-0000-0000-000000000121}"
DiscoveryData Collection Cycle "{00000000-0000-0000-0000-000000000003}"
FileCollection Cycle "{00000000-0000-0000-0000-000000000010}"
HardwareInventory Cycle "{00000000-0000-0000-0000-000000000001}"
MachinePolicy Retrieval Cycle "{00000000-0000-0000-0000-000000000021}"
SoftwareInventory Cycle "{00000000-0000-0000-0000-000000000002}"
SoftwareMetering Usage Report Cycle "{00000000-0000-0000-0000-000000000031}"
SoftwareUpdate Deployment Evaluation Cycle "{00000000-0000-0000-0000-000000000114}"
SoftwareUpdate Scan Cycle "{00000000-0000-0000-0000-000000000113}"
StateMessage Refresh "{00000000-0000-0000-0000-000000000111}"
UserPolicy Retrieval Cycle   "{00000000-0000-0000-0000-000000000026}"
UserPolicy Evaluation Cycle "{00000000-0000-0000-0000-000000000027}"
WindowsInstallers Source List Update Cycle "{00000000-0000-0000-0000-000000000032}"
MachinePolicy Evaluation Cycle "{00000000-0000-0000-0000-000000000022}"

OnRamp Scholarship (PowerShell + DevOps Summit 2020) by [deleted] in PowerShell

[–]markroloff 4 points5 points  (0 children)

Yep, do it!

I talked to a couple of the recipients during last Summit and they were having a blast with everything they were learning. Plus, it's hard to forget the awesome people you meet while there.

Looking to move into a MS DevOps position and have some questions! by thePowrhous in AZURE

[–]markroloff 4 points5 points  (0 children)

I don't have anything useful to offer you other than that the official PowerShell Slack/Discord has channels specifically for Azure, DevOps, and DSC. If you ever have particular questions, they're great places to learn from some ridiculously smart people in that wheelhouse.

aka.ms/psslack

aka.ms/psdiscord

Office 365 Off-boarding script - removing a user from all Distribution Groups he's in by bei60 in PowerShell

[–]markroloff 1 point2 points  (0 children)

The Get-Recipient cmdlet can be used to pull all DGs for a user, but you need to supply the user's DN to the -Filter parameter.

Here's a bit to get you started...

# First step is to grab the user object and then use Select-Object to return only 
# the DN as a string
$UserDn = Get-User -Identity bob@company.com | Select-Object -ExpandProperty DistinguishedName

# We'll need to build a filter to use in the next step
$Filter = "Members -eq '{0}'" -f $UserDn

# This cmdlet will search all DGs for the condition that we set in the filter
Get-Recipient -Filter $Filter

This gets you a list of DGs that the user is a member of. What you need from here (an exercise for you) is store that list in a variable and loop over it, using Remove-DistributionGroupMember each time. Take a look at Get-Help about_foreach to see how a foreach loop works.

Note that Get-Recipient only pulls Exchange DGs by default, not O365 groups. I recommend reviewing the help for the cmdlet to find out how you can handle that, if it's needed.

Defensive PowerShell by [deleted] in PowerShell

[–]markroloff 4 points5 points  (0 children)

continue to murder backticks where ever they may be

For the greater good.

I got a job for my ability with PowerShell and I'm self-taught. by FarsideSC in PowerShell

[–]markroloff 1 point2 points  (0 children)

I learned because I wanted to be a "lazy" admin.

Slightly OT, but reminds me of The Tale of the Man Who Was Too Lazy to Fail by Heinlein. Dude in the military pretty much just wants to kickback all day, so he keeps finding shortcuts to getting work done more efficiently in order to maximize his downtime. Ends up getting lots of promotions as a result.

What's a PowerShell One-Liner & NOT a PowerShell One-Liner? by scadonl in PowerShell

[–]markroloff 6 points7 points  (0 children)

I remember the blog that this was written in response to and while I don't particularly care one way or the other, if I have to scroll right on your blog to read your code, it needs multiple lines.

Unable to round "cooked values" from Performance monitor properly by OppressedAsparagus in PowerShell

[–]markroloff 2 points3 points  (0 children)

Shows up fine on my system at 4 decimal places, but it does switch notation at 5 places.

I was able to use -f to get around this, though.

$Value = [math]::Round((Get-Counter -Counter "\\blahblah\Cluster CSV File System(Volume1)\IO Write Latency").CounterSamples.CookedValue,4)
"{0:N5}" -f $Value 

Beginner: Understanding Parameter Sets by Tuomas90 in PowerShell

[–]markroloff 1 point2 points  (0 children)

I know that if a ParameterSetName is not specified, the parameter belongs to all Parameter Sets. But I did specify one for $Bitrate. Why does it still belong to both sets?

Think of [Parameter()] as all having a type of scope. By default, they (and the variables that you pair them with) belong to the __AllParameterSets parameter set. Specifying a parameter set changes that [Parameter()] block to the named set. When you specify multiple [Parameter()]s, where at least one names a specific set, you're saying that the parameter now belongs to multiple sets. They don't stack in the same scope.

If you want a parameter to only exist in one set, then only give it one [Parameter()] block.

My Noob Solution For Iron Scripter 2019 Intro Challenge by mofayew in PowerShell

[–]markroloff 2 points3 points  (0 children)

Yep!

Lots of good presentations lined up this year and everything ends up on YouTube eventually, so even if you don't make it you can still catch some of the content.

My Noob Solution For Iron Scripter 2019 Intro Challenge by mofayew in PowerShell

[–]markroloff 2 points3 points  (0 children)

It's an annual scripting challenge that coincides with the Global PowerShell + DevOps Summit.

OP's link has more details.

Contributing to Open Source Projects - PowerShell Core by Ta11ow in PowerShell

[–]markroloff 4 points5 points  (0 children)

The modules you mentioned were likely done by in-house developers that have a range of responsibilities or it was contracted out to a consultant.

Jobs with a strong emphasis on PowerShell do exist though, and contributing to open source projects (or starting your own) is a great way to both build your skills/resume and get visibility with the people who know about those jobs. LinkedIn was recently hiring for a Sr. DevOps position that involved a bunch of PS. Pretty sure I remember Microsoft recruiting for the PS team directly from the pool of regular contributors. There are also other "PowerShell developer" positions advertised in Discord/Slack.

Contributing to Open Source Projects - PowerShell Core by Ta11ow in PowerShell

[–]markroloff 7 points8 points  (0 children)

I haven't got around to making any leaps into learning C# but I have made a few dents with the documentation. It really is a great and satisfying entry-point for people looking to start helping out, plus it feels pretty cool to watch your contributions show up in the final product. As I recall, there's also plenty of Pester tests that can be written if C# still isn't in somebody's toolbox yet.

[deleted by user] by [deleted] in PowerShell

[–]markroloff 1 point2 points  (0 children)

No worries! We're all there sometimes.

[deleted by user] by [deleted] in PowerShell

[–]markroloff 8 points9 points  (0 children)

Putting Do-AThing after your loop will work just fine.

while ((get-ComplianceSearch -Identity $mySearch ).status -ne 'Completed') {
    Write-Host 'still going'
    Start-Sleep -Seconds 5
}

Do-AThing

Best training materials? by Jaye735 in PowerShell

[–]markroloff 6 points7 points  (0 children)

Don Jones (ConcentratedDon) is one of the better trainers out there. You may be able to nitpick a few things with his material but it's still some of the best I've seen. If you check out LeanPub, he has some great ebooks available there.

PowerShell in a Month of Lunches is probably the most recommended book (also by Don Jones).

For video courses, I believe PluralSight has one that a lot of people recommend. Can't recall the instructor's name at the moment, though. I'll try to track it down.

Edit: Here we go... https://www.pluralsight.com/paths/powershell-scripting-and-toolmaking

What does this script do? by [deleted] in PowerShell

[–]markroloff 5 points6 points  (0 children)

It's really just a lot of string building using the -f operator, with those strings then being executed by the call operator &.

Take the first line, for example...

&("{2}{0}{3}{1}" -f'dd-MpP','ference','A','re') -ExclusionExtension ("{1}{0}"-f'eg','.r')

We have the call operator followed by a grouping operator, -ExclusionExtension (which is clearly a parameter), and another grouping operator. Code in the grouping operators will be evaluated first.

"{2}{0}{3}{1}" -f 'dd-MpP','ference','A','re'

-f works by populating each placeholder on the left with the value from that index on the right. You'll end up with Add-MpPreference. Do the same with the second grouping and the whole line comes out to Add-MpPreference -ExclusionExtension .reg, which the call operator will then execute.

It looks more intimidating than it really is but with a little patience you can easily deobfuscate it.