I'm trying to automate some WSUS stuff using powershell!
When I run this command:
Get-WSUSClassification -WSUSserver MyServer
The result is as expected: We have all these classifications:
Title ID
----- --
Applications 5c9376ab-8ce6-464a-b136-22113dd69801
Critical Updates e6cf1350-c01b-414d-a61f-263d14d133b4
Definition Updates e0789628-ce08-4437-be74-2495b842f43b
Driver Sets 77835c8d-62a7-41f5-82ad-f28d1af1e3b1
Drivers ebfc1fc5-71a4-4f7b-9aca-3b9a503104a0
Feature Packs b54e7d24-7add-428f-8b75-90a396fa584f
Security Updates 0fa1201d-4330-4fa8-8ae9-b877473b6441
Service Packs 68c5b0a3-d1a6-4553-ae49-01d3a7827828
Tools b4832bd8-e735-4761-8daf-37f882276dab
Update Rollups 28bc880e-0592-4cbf-8f95-c79b17911d5f
Updates cd5ffd1e-e932-4e3a-bf74-18bf0b1bbd83
Upgrades 3689bdc8-b205-4af4-8d4a-a63924c5e9d5
However: If I try to use any other than "All", "Critical", "Security", or "WSUS",
get-wsusUpdate -approval UnApproved -Classification "Drivers" -status Needed -updateserver MyWSUS
I get the following error:
Get-WsusUpdate : Cannot bind parameter 'Classification'. Cannot convert value "Feature Packs" to type "Microsoft.UpdateServices.Commands.WsusUpdateClassifications". Error: "Unable to match the identifier name Feature Packs to a valid enumerator name. Specify one of the following enumerator names and try again: All, Critical, Security, WSUS"
Any ideas?
This is a case of poor terminology. There is WSUS Classifications, and WSUS Update Classifications, and they are different things. You already know how to see the options for the first using Get-WsusClassification. You can see valid options for the latter using [enum]::GetNames(<EnumType>) such as:
PS C:\Windows\system32> [enum]::GetNames([Microsoft.UpdateServices.Commands.WsusUpdateClassifications])
All
Critical
Security
WSUS
So, can we get updates classified as Feature Packs? We can, but the only way I know of to do it takes a hair more footwork. Here's how I'd do it:
$WSUS = Get-WsusServer
$FPClass = $WSUS.GetUpdateClassifications()|Where{$_.Title -eq 'Feature Packs'}
$FPClass.GetUpdates()
Now, you do know the GUID for the classification you want, so you can shorten that if you want using the GUID:
$WSUS.GetUpdateClassification('b54e7d24-7add-428f-8b75-90a396fa584f').GetUpdates()
That will get you all of the Feature Pack updates. From there you can filter out updates based on if they are superseded or not needed.
Personally I find the objects themselves much more useful than the cmdlets for WSUS, such as $WSUS above getting update classifications from which you can get the updates for that classification.
Related
I am trying to find the best way to use the notes field to set a shutdown order of virtual machines. At the moment, I have a note in my VM's as "Startup: X" where X is the number I want to use for startup, but the reverse being what I want for shutdown. The goal is to put this into a workflow so that machines complete their startup/shutdown before the next machine comes up.
Currently, I can get the info from the VMs by doing:
Get-VM | Where-Object {$_.Notes -contains "Startup:"} | Select-Object name,notes
It's my understanding that I want to put this into an object, then loop through that object based on the value after the ":" (e.g. 1, 2, 3, 4, 5, etc.) in either ascending or descending order. However, I'm not sure if that's the best method to work on this or not. All I know is that I want to look for the Startup: line in the VM Notes field, then use that alone to determine order. Some VMs might have other notes in them that I want to ignore, so I only want the Startup: string to show.
Could anyone give me some assistance? Or, let me know if I'm on the wrong path?
I have tried using multiple methods to parse, but I keep getting null errors that I cannot figure out. I'm fairly new to using PS in this way, so that doesn't help.
I have some questions about a PowerShell script I need to write:
My script gets a list of servers' IP and it's output has to be the status of each server's WakeOnLan parameter.
The output also has to include the time it took my function to return all the statuses of all the servers.
Measure-Command does not work in this case, because my function is pretty long and it gets a list of hundreds IPs.
Does anyone know how to make my function write the following output:
"The total time of providing WakeOnLan status for ___(number) servers is ___(minutes).
After writing my function in some cases it can not run the Connect-HPEBIOS
command (when the output is more than one IP): It prints that it can not connect because of credentials (even though they are being written in my function correctly), but after trying to call my function with (only that specific IP - and not a list of IPs) the function works properly without printing an error about the credentials.
Does anyone have an idea what should I do in the cases where my output is more than one IP? How can I fix it?
One more question- Do I have to refer in my function to the different possibilities of different ILO versions? Can there be problems performing the Connect-HPEBIOS command in the different versions?
Thanks a lot!
Working on a side project where I use a set of views to identify contention of records within an iSeries set of physical files.
What I would like to do once identified is pull the user profile locking the record, and then send a break message to their terminal as an informational break message.
What I have found is the QEZSNDMG API. Simple enough to use interactively, but I'm trying to put together a command that would be used in conjunction with QCMDEXC API to issue the call to QEZSNDMG and alert the user that they are locking a record.
Reviewing the IBM documentation of the QEZSNDMG API, I see that there are two sets of option parameters, but nothing as required (which seems odd to me, but another topic for another day). But I continue to receive the error "Parameters passed on CALL do not match those required."
Here are some examples that I have tried from the command line so far:
CALL PGM(QEZSNDMG) PARM('*INFO' '*BREAK' 'TEST' '4' 'DOUGLAS' '1' '1' '-4')
CALL PGM(QEZSNDMG) PARM('*INFO' '*BREAK' 'TEST' '4' 'DOUGLAS')
CALL PGM(QEZSNDMG) PARM('*INFO' '*BREAK' 'TEST' '4' 'DOUGLAS' '1')
Note: I would like to avoid using a CL or RPG program if possible but understand it may come to that using one of many examples I found before posting. Just want to exhaust this option before going down that road.
Update
While logged in, I used WRKMSGQ to see the message queues assigned to my station. There were two: QSYS/DOUGLAS and QUSRSYS/DOUGLAS. I then issued SNDBRKMSG with no affect on my workstation (IE, the message didn't break my session):
SNDBRKMSG MSG(TESTING) TOMSGQ(QSYS/DOUGLAS)
SNDBRKMSG MSG(TESTING) TOMSGQ(QUSRSYS/DOUGLAS)
I realized if I provide the workstation session name in the TOMSG parameter it worked:
SNDBRKMSG MSG(TESTING) TOMSGQ(*LIBL/QPADEV0003)
Using SNDBRKMSG was what I was looking for.
Some nudging in the right direction lead me to realize that the workstation session ID is located within QSYS2.RCD_LOCK in field JOB_NAME (job number/username/workstation).
Extracting the workstation ID allowed me to create a correctly formatted SNDBRKMSG command to QCMDEXC and alert the user that they are locking a record needed by another process.
I'm writing a Powershell runbook that will scale up a VM ScaleSet until an Application Insights alert is resolved.
To do this, I need to query the status of the alert in my Powershell script, ie no if an alert has been triggered or resolved.
I have tried to use Get-AzureRmAlertRule and Get-AzureRmAlertHistory, but this only gives me respectively the disabled/enabled state of the alert rule, or the actions that were perform on the rule itself (ie updating the rule, or deleting the alert, etc).
Is there any way to simply know if an alert is currently being triggered or resolved?
So I'm actively working through this issue too and thought I would share what I found.
The following was pulled from Microsoft documentation:
The Get-AzureRmAlertHistory cmdlet gets the history of alerts as they are enabled, disabled, fired, resolved, and so on.
While messing around with this command, I found that if you don't give it any parameters, it will only return history for the current day; however, when you use the -StartTime and -EndTime parameters you can obtain details of alerts from further in the past.
While this doesn't give you the current status of an alert in a single command, can throw together some logic that will grab the latest alert within a given time range and check the status there.
For my purposes, this code with check the status of a sibling alert from within a runbook that was called from the alert webhook. So I can gather the time ranges based on the data provided in the webhook. I know this isn't a perfect solution for all cases, but at least it could be used as a starting point.
Note: The version of the AzureRM.Insights module I'm working with is 3.2.1 behavior may differ depending on the version of this module you're using.
Update:
As I continued to work on the code, I found that there are some issues with filtering with the -ResourceId parameter. When you provide the ResourceId for the alert that you want to find history on, it won't return any result. From what I can tell, the ResourceId isn't populated when the alert objects are returned when using the Get-AzureRmAlertHistory cmdlet with just the -ResourceId parameter. I did manage to find two ways to get this to work though.
Pass the -DetailedOutput parameter in before the -ResourceId parameter. It turns out that the ResourceId is populated in the DetailedOutput and can be matched there; however, if you pass the -ResourceId in first, the cmdlet acts as though it evaluates that first prior to bringing back the detailed output.
Get-AzureRmAlertHistory -StartTime 2018-01-16 -EndTime 2018-01-17 -DetailedOutput -ResourceId $AlertResourceID
The property CorrelationId contains within it the ResourceId. Using the Where-Object syntax, you can match on your ResourceId using Regex.
Get-AzureRmAlertHistory -StartTime 2018-01-16 -EndTime 2018-01-17 | Where-Object {$_.CorrelationId -Match "$AlertResourceID/incidents/.*"}
Now that you have the records you want, you can use a simple Sort-Object on the -EventTimestamp property and assign the results to a variable. Then if you reference the -1 index of the variable you assigned your results to, it should give you the latest alert instance along with the alert Status.
$AlertHistory = Get-AzureRmAlertHistory -StartTime 2018-01-16 -EndTime 2018-01-17 | Where-Object {$_.CorrelationId -Match "$AlertResourceID/incidents/.*"} | Sort-Object -Property EventTimestamp;
$AlertHistory[-1];
I have a dynamic distribution list that I'm trying to modify, however the current filter is complex and was not set up by me. I'm trying to decode it so I can exclude certain emails from it, since currently it seems to include all mailboxes and contacts in the domain.
This is the current filter as displayed in the Exchange Management Console, honestly I don't know enough about the filters to decode this string:
(&(!cn=SystemMailbox{*})(& (mailnickname=*) (| (&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact)) )))
The powershell command below isn't showing me the filter in the Exchange Management Shell, which I would probably be able to decode easier that this query above:
(Get-DynamicDistributionGroup GROUP_NAME).RecipientFilter
I've made sure I'm part of the Organization and Recipient Admin groups, is there something else I'm missing to be able to display this in the Shell? What's the easiest way to decode this filter?
If you need to convert ldap filter to opath you cabn use this script:
http://gallery.technet.microsoft.com/scriptcenter/7c04b866-f83d-4b34-98ec-f944811dd48d