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
Potato Salad
Oct 23, 2014

nobody cares


PierreTheMime posted:

I'm trying to write a basic set of checks in Powershell to make sure that any given server isn't pegged on resources. We've had a few times recently where servers hung but didn't get reported to us for a long time which held up processing. What would be the best way to monitor CPU/RAM in a way that won't false-report (mostly)? Basically at the end of it I just need the script to return either "Failure" if a server is pegged for a prolonged period (I used 5 minutes) or "Success" if it's fine (I'm using Write-Host because the result is captured in a log).

This is what I have currently, but I'm sure there's a better method:
code:
Function PollResources ([Collections.Arraylist]$LoadArray) {
	$CPULoads = @((Get-WmiObject win32_processor).LoadPercentage)
	$Repoll = $False
	For ($i = 0; $i -lt $CPULoads.Count; $i++) {
		$CPULoad = $CPULoads[$i]
		if ($CPULoad -gt 95) {
			Write-Host "CPU $i processing capacity at <5% remaining ($CPULoad%).  Repolling in 5 seconds"
			$Repoll = $True
		} else {Write-Host "CPU $i processing capacity normal ($CPULoad%)."}
	}
	$Memory = (GWMI -Class win32_operatingsystem)
	$MemoryUsage = &#8220;{0:N2}&#8221; -f  $((($Memory.TotalVisibleMemorySize - $Memory.FreePhysicalMemory) * 100) / $Memory.TotalVisibleMemorySize)
	$TotalMemory = [math]::Round($Memory.TotalVisibleMemorySize/1MB)
	If ($MemoryUsage -gt 95) {
		Write-Host "Memory utilization at <5% remaining ($MemoryUsage% of $TotalMemory GB)."
		$Repoll = $True
	} else {Write-Host "Memory use normal ($MemoryUsage% of $TotalMemory GB)."}
	If ($Repoll) {Write-Host "One or more resources exceeded 95% utilization!  Repolling server resources in 30 seconds..."}
	return $Repoll
}

$Loop = 0
Do {
	If ($Loop -gt 0) {Start-Sleep -s 30; Write-Host ""}
	$Repoll = PollResources
	$Loop++
} While ($Repoll -And $Loop -lt 10)
If ($Loop -eq 10) {
	Write-Host "One or more resources have remained at 95%+ utilization for 5 minutes.  Sending notification."
	Return "Failure"
}
Return "Success"
I'd prefer to collect the various CPU results into an array per processor and RAM to make sure the flags aren't just jumping around, but at the current time I haven't implemented that. Appreciate any suggestions. If anyone would be willing to critique my script that'd be great, I'm still fairly new to PS and always love pointers.

Frankly, the most reliable way to do this might be on an ancient tech, SNMP.

I've never checked whether server core has the windows SNMP client available.

Adbot
ADBOT LOVES YOU

Potato Salad
Oct 23, 2014

nobody cares


If it matters to you, using the SNMP client is way, way lighter than polling wmi.

Potato Salad
Oct 23, 2014

nobody cares


Posh-SSH is useful.

Potato Salad
Oct 23, 2014

nobody cares


The answer, in another language, might be to use a hashtable. To my knowledge PS has nothing like this.


Use python? PS is a control and orchestration language; it's not really intended to crunch data quickly.

Potato Salad
Oct 23, 2014

nobody cares


cheese-cube posted:

PS does have hashtables but this sounds like a data transform problem. I'll agree, there's some data crunching that PS just can't do well and should be moved to a DB but I've processed some pretty large piles of garbage using PS quite efficiently.

!!!!!

Systems.Collections.Hashtable

Hello, handsome :shlick:

Potato Salad
Oct 23, 2014

nobody cares


Yeah, thanks to you and Cheese for pointing that out. There is some deeply convoluted poo poo I'm looking forward to fixing/simplifying Monday :)

Potato Salad
Oct 23, 2014

nobody cares


:five: this thread. Every time someone posts a solution I learn something helpful.

Python doesn't open an entire file when preappending text does it?

Potato Salad
Oct 23, 2014

nobody cares


Sounds like it should put it in both

Potato Salad
Oct 23, 2014

nobody cares


How do you intend to authenticate as an administrator to Windows Remote Management on these machines?

Additionally, do you know whether dns in your environment will actually let you resolve those machine names?

Lastly, for asynchronous execution with retry/wait options, look at submitting these as powershell "jobs"

Potato Salad fucked around with this message at 04:03 on Sep 12, 2018

Potato Salad
Oct 23, 2014

nobody cares


Got it, that's much more clear. So...less Shadow IT :drac: and more "Hey this is p easy"

Next time you're in, do the following to determine whether you're in a domain environment (you almost certainly are)

Right mouse click on the Computer icon (in Windows 10, you'll reliably find This PC in a file browser's left column)

Select Properties

Look under the Computer name, domain



In cmd, from another computer, run
nslookup thefullnameofthefirstcomputer

For example,
nslookup rm304-dell8080.ad.happyschool.co.uk

That'll tell you whether computers (1) are in a domain (2) have suitable DNS records

Potato Salad fucked around with this message at 05:16 on Sep 12, 2018

Potato Salad
Oct 23, 2014

nobody cares


server or o365

Potato Salad
Oct 23, 2014

nobody cares


The Fool posted:

This one-liner should get you a list of everyone with ENTERPRISEPACK.

code:
# Get all azure ad members with specific skuid in AssignedLicenses property
$EnterprisePackUsers = get-azureaduser -All $true -Filter "UserType eq 'Member'" | Where-Object { $_.AssignedLicenses.SKUID -eq "6fd2c87f-b296-42f0-b197-1e91e994b900" }
From there, I would wrap your code to disable Yammer in a ForEach.
code:
# license object generation goes here

# for each objectid of $EnterprisePackUsers, set the generated license object
ForEach ($AzureADUserObjectId in ($EnterprisePackUsers.ObjectId)) {
    Set-AzureADUserLicense -ObjectId $AzureADUserObjectId -AssignedLicenses $LicensesToAssign
}

:five:

Potato Salad
Oct 23, 2014

nobody cares


The Oracle application isn't using weblogic + Oracle security wallet?

Potato Salad
Oct 23, 2014

nobody cares


New Yorp New Yorp posted:

That's what I thought. Can't use the IP directly, so I guess I'll either deal with it or build something to safely manipulate entries in the hosts file. Bummer.

do you happen to have dsc push or sccm?

Potato Salad
Oct 23, 2014

nobody cares


Google Create a forwarding rule and scroll past the Outlook resulta

Potato Salad
Oct 23, 2014

nobody cares


Bug #2607 on cyclic dependences probably isn't going to be fixed in ps5.1


It's okay, I I love making weird hacky module manifests :smithicide:

Potato Salad
Oct 23, 2014

nobody cares


fishmanpet are you a pester contributor

Potato Salad
Oct 23, 2014

nobody cares


Submarine Sandpaper posted:

This is a silly one but how can you determine all the stores on a machine eg sqlserver, certificates, registry

Like, detect all common locations for storing configurations or data?

Potato Salad
Oct 23, 2014

nobody cares


are you basically looking for MS expect ?

Potato Salad
Oct 23, 2014

nobody cares


Irritated Goat posted:

timeouts on VPN for AD queries

consider maintaining your infrastructure from a vm at the relevant site

Potato Salad
Oct 23, 2014

nobody cares


Man, gently caress whoever got rid of sccm in an environment where you need weekly patching assurance

epm is there to help you MEET compliance requirements, what doofus did that?

Potato Salad
Oct 23, 2014

nobody cares


Wizard of the Deep posted:

How is the WinRM trusted hosts list distributed? Can you verify that they're the same on all servers?

I lean on dsc with [insert any popular config/security management solution here]

Potato Salad
Oct 23, 2014

nobody cares


it's kind of cool that people will organically walk into the need for the kinds of structures that people learn in CS classes, where a kid who learns what a hashtable is in CS might never actually use such a structure in their life

Potato Salad
Oct 23, 2014

nobody cares


:itwaspoo:

Potato Salad
Oct 23, 2014

nobody cares


NPR Journalizard posted:

Im trying to use the PowerBI cmdlet to do a survey of the datasets in my tenant. I can get a list of datasets fairly easily with Get-PowerBIDataset, but I also want to get a list of what tables each dataset uses. Supposedly Get-PowerBITable does this, but no matter what parameters I pass, or what login I use, including a service admin account, I cant get anything out of it other than an error message saying not found.

Have tried searching the web for this but cant really find an answer from a reliable source, other than one post on the community forums that I hope is wrong.

out of curiosity, are you the owner proper of any of these datasets?

Adbot
ADBOT LOVES YOU

Potato Salad
Oct 23, 2014

nobody cares


I think you're overthinking this? If you want to make a new user, you cast New-AzureADUser. It....does that.

edit: I see what you're asking. Yes, install the graph module and get it connected with your tenant

I scrolled through these directions; they look like they should get you installed and connected

https://www.alitajran.com/install-microsoft-graph-powershell/

Potato Salad fucked around with this message at 22:16 on Dec 13, 2023

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