|
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:
|
# ? Jan 30, 2018 19:14 |
|
|
# ? May 28, 2024 14:30 |
|
If you're simply trying to determine whether or not a server is responsive then a much better approach is to deploy a heartbeat script that runs on each server as a Scheduled Task and periodically writes to a file on an SMB share. Then you have a separate script on a dedicated monitoring host which parses the files in the SMB share and checks whether a single server has not logged a heartbeat recently. The general heartbeat function which would run on each server is as follows: code:
The function which checks the heartbeat files in the SMB share would be like this: code:
So yeah, implementing a client-side model is much more scalable and if you are trying to identify when servers become unresponsive checking heartbeats in this manner is far more reliable that trying to analyse resource utilisation. I should note that I just whipped those two functions up now and haven't tested them, let me know if you run into issues. Pile Of Garbage fucked around with this message at 19:54 on Jan 30, 2018 |
# ? Jan 30, 2018 19:50 |
|
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).
|
# ? Jan 30, 2018 19:53 |
|
Thanks. I think I may be getting a little too in-depth and a heartbeat option is probably fine.
|
# ? Jan 30, 2018 20:16 |
|
Anyone ever have the -whatif switch still execute the function you're trying to test? I'm writing my first function in powershell, passed the arguments with the -whatif switch and the dang thing still executed.
|
# ? Feb 9, 2018 16:26 |
|
Coredump posted:Anyone ever have the -whatif switch still execute the function you're trying to test? I'm writing my first function in powershell, passed the arguments with the -whatif switch and the dang thing still executed. You have to build support for whatif into your function. something like the below. php:<? Function Do-Stuff{ [CmdletBinding(SupportsShouldProcess=$true)] param([string[]]$Objects) ForEach($item in $Objects){ if ($pscmdlet.ShouldProcess("$item", "DoStuff")){ "Actually performing `$Action on $item" } } } ?>
|
# ? Feb 9, 2018 16:32 |
|
Ooooohhhh. poo poo. Thanks for that, I'll have to look into it.
|
# ? Feb 9, 2018 16:39 |
|
I think that Briantist was lobbying Microsoft to make -whatif work in a safer and more intuitive way or something a ways back.
|
# ? Feb 9, 2018 17:20 |
|
I'll admit up front what I'm trying to do is probably not the best way of doing things but work wants us to remove people from distribution groups that handle shared inbox permissions and add people directly to shared inboxes within office 365. Here's what I've come up with so far. I would welcome a sanity check.code:
|
# ? Feb 9, 2018 17:27 |
|
Dr. Arbitrary posted:I think that Briantist was lobbying Microsoft to make -whatif work in a safer and more intuitive way or something a ways back. IDK what idiot you're talking about but they didn't do poo poo because I've used plenty of first party cmdlets that "support" WhatIf but still just go and do their poo poo anyway. Coredump posted:I'll admit up front what I'm trying to do is probably not the best way of doing things but work wants us to remove people from distribution groups that handle shared inbox permissions and add people directly to shared inboxes within office 365. Here's what I've come up with so far. I would welcome a sanity check. That's an exceptionally hosed situation but still do-able. I didn't read what you posted but it'll probably work? Just test it in your own environment. You may want to push back hard on their reasoning for taking such an approach. If they have issues with reporting for compliance purposes then explain to them that perhaps you can work on those issues instead of reconfiguring everything. Edit: for the record I've implemented some extremely greasy hacks when it comes to O365 and Exchange hybrid. With EXO and AAD PowerShell the skies the limit really and you can implement a lot of crazy poo poo. Replicating on-premises distribution group members to EXO distribution group members? Yeah I thought on that recently and it's easy as piss. But it's turbo-hosed and would break with the slightest change by MSFT on the backend. Pile Of Garbage fucked around with this message at 21:21 on Feb 9, 2018 |
# ? Feb 9, 2018 21:17 |
|
Briantist posted:Please vote on this uservoice issue to fix glaring inconsistencies and bugs in the DnsServer module's handling of -Verbose, -WhatIf, and -ErrorAction. I think this is what I was misremembering.
|
# ? Feb 9, 2018 21:51 |
|
Wasn't(Isn't?) whatif broken entirely for the active directory cmdlets?
|
# ? Feb 10, 2018 04:34 |
I'm using New-ADGroup -WhatIf regularly as part of a script, works fine.
|
|
# ? Feb 10, 2018 10:56 |
|
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). 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.
|
# ? Feb 10, 2018 22:07 |
|
If it matters to you, using the SNMP client is way, way lighter than polling wmi.
|
# ? Feb 10, 2018 22:10 |
|
thebigcow posted:Wasn't(Isn't?) whatif broken entirely for the active directory cmdlets? Set-ADAccountPassword ignores -WhatIf . That was a fun one to find out, thank god that script worked right the first time. Supposedly fixed in Server 2016 and its RSAT.
|
# ? Feb 12, 2018 04:32 |
|
My boss has asked me to help protect people from their own mistakes by setting up hourly backups for our file server to supplement the usual daily backup. I've successfully been able to test a script to back up all files modified in the last hour. The one problem is that I haven't been able to figure out how to replicate the folder structure properly for files backed up. Either everything gets dumped in one single folder...code:
code:
|
# ? Feb 23, 2018 22:32 |
|
Eschatos posted:My boss has asked me to help protect people from their own mistakes by setting up hourly backups for our file server to supplement the usual daily backup. I've successfully been able to test a script to back up all files modified in the last hour. The one problem is that I haven't been able to figure out how to replicate the folder structure properly for files backed up. Either everything gets dumped in one single folder...
|
# ? Feb 23, 2018 22:36 |
|
anthonypants posted:Why can't you turn on volume shadow copy? Originally the requirement was to run the backup every 15 minutes, and I'm half expecting it to revert to that.
|
# ? Feb 23, 2018 22:53 |
Volume shadow copy on the file server gives you instant-to-take snapshots of the entire file system, and lets you/users restore files directly from File Explorer. It's the best thing ever for getting out of "oops data gone" situations. It's called Previous Versions in File Explorer.
|
|
# ? Feb 23, 2018 23:29 |
|
Eschatos posted:My boss has asked me to help protect people from their own mistakes by setting up hourly backups for our file server to supplement the usual daily backup. I've successfully been able to test a script to back up all files modified in the last hour. The one problem is that I haven't been able to figure out how to replicate the folder structure properly for files backed up. Either everything gets dumped in one single folder... This is a solved problem; RoboCopy ships with the OS.
|
# ? Feb 24, 2018 05:02 |
|
New Yorp New Yorp posted:This is a solved problem; RoboCopy ships with the OS. Basically this. Alternatively, get actual backup software?
|
# ? Feb 25, 2018 11:04 |
|
New Yorp New Yorp posted:This is a solved problem; RoboCopy ships with the OS. Robocopy was the first way I tried, but the /MAXAGE flag only can filter by individual days, not by hours.
|
# ? Feb 26, 2018 16:02 |
|
Eschatos posted:Originally the requirement was to run the backup every 15 minutes, and I'm half expecting it to revert to that. Shadow Copies can be run as often as you want, and they are the solution you should be using instead of kludging together a script that will break when you need it most.
|
# ? Feb 26, 2018 18:48 |
|
The Fool posted:Shadow Copies can be run as often as you want, and they are the solution you should be using instead of kludging together a script that will break when you need it most. The shadow copy configuration screen explicitly states not to run it more than once per hour. But ok, I see your point. In any case this isn't some business critical functionality, it's a more-frequent supplement to our existing daily backup scheme so that we can occasionally save the day after someone deletes files they shouldn't have. I'll stick to hourly volume shadow copies for the time being.
|
# ? Feb 26, 2018 20:37 |
|
What would you all consider the "best" SFTP module/implementation for Powershell? I'm working with some file automation and the current method is a bit clunky and could work better if I could step things in code to better allow for errors and such.
|
# ? Mar 5, 2018 16:53 |
|
Can you not just use SMB instead? Is there a specific reason that you need to use SFTP?
|
# ? Mar 5, 2018 17:21 |
|
Posh-SSH is useful.
|
# ? Mar 5, 2018 17:26 |
|
cheese-cube posted:Can you not just use SMB instead? Is there a specific reason that you need to use SFTP?
|
# ? Mar 5, 2018 18:09 |
|
No one said internet.
|
# ? Mar 5, 2018 18:16 |
|
cheese-cube posted:No one said internet.
|
# ? Mar 5, 2018 18:20 |
|
cheese-cube posted:No one said internet. This would be to access files on a remote network, yes.
|
# ? Mar 5, 2018 19:15 |
|
Is there a way to use a specific cmdlet in a specific module? Like how Get-Cluster exists in both VMware's PowerCLI and Microsoft's Failover Cluster modules, or how Get-VMHost exists in both VMware's PowerCLI and Microsoft's Hyper-V modules. The existing workaround is to just run Remove-Module for the one you don't want and/or Import-Module for the one you do, which I guess works, but imo if it would be great if I could just specify which one I want without having to worry about that.
|
# ? Mar 27, 2018 20:15 |
|
You should be able to specify the module namespace by typing ModuleName\CmdLetName ie, "ActiveDirectory\Get-Aduser" and "Get-AdUser" are the same The other option may be to pass session objects around. I don't have the vmware modules to be able to verify your specific use case though.
|
# ? Mar 27, 2018 20:28 |
https://mcpmag.com/articles/2013/08/20/powershell-name-duplicates.aspx talks about exactly that problem, you can specify a prefix in Import-Module that gets appended to the noun part: Import-Module Hyper-V -Prefix Hv Import-Module VMware.VimAutomation.Core -Prefix Vmw That should get you commands named Get-HvVMHost and Get-VmwVMHost instead. ^^^ but that module "namespace" prefix sounds like a perhaps better solution.
|
|
# ? Mar 27, 2018 20:33 |
|
The Fool posted:You should be able to specify the module namespace by typing ModuleName\CmdLetName code:
nielsm posted:https://mcpmag.com/articles/2013/08/20/powershell-name-duplicates.aspx talks about exactly that problem, you can specify a prefix in Import-Module that gets appended to the noun part:
|
# ? Mar 27, 2018 20:38 |
|
Is anyone aware of a better way to put a GUI wrapper around a powershell script? Even with poshgui.com, WinForms is a total loving nightmare.
|
# ? Mar 28, 2018 21:55 |
|
The Fool posted:Is anyone aware of a better way to put a GUI wrapper around a powershell script? Even with poshgui.com, WinForms is a total loving nightmare.
|
# ? Mar 28, 2018 22:48 |
|
anthonypants posted:Port your script to C#? If you're determined you can use vs to generate C# and rewrite it in powershell, or just use the c# from powershell but it's probably not worth the trouble. I guess if you already have a complete script and just want a UI for it you could also run the powershell script from c#. But basically everything is going to be more trouble than just rewriting it in c#.
|
# ? Mar 29, 2018 01:03 |
|
|
# ? May 28, 2024 14:30 |
|
anthonypants posted:Port your script to C#? Seconding this. Developing GUIs with PowerShell is dirty and IMO completely antithetical to how PowerShell is designed to be used.
|
# ? Mar 29, 2018 03:01 |