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.
Related
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!
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.
I am looking to create a rule in Office 365 applied to all of the members in our org.
I would like this rule to append a warning on all incoming email from outside the organization with the same Display Names as our users.
When I attempt to apply it to all of the users in our org I get an error stating that the rule is too long.
In order to solve that I pulled a group, but I am still about 1000 characters over the limit.
I would like to make two variables, that each hold one half of the list, created by this command:
(Get-DistibutionGroupMember -Identity email#contoso.com -ResultSize Unlimited).DisplayName
I have attempted to modify the ResultSize parameter, but what I would need is result 1-100 and then 100-200 from the same list.
Another caveat to this problem is that the list cannot be static. It is something that the script will have to update every time it is run.
There is a sub-string command that you can use on a particular username that I have utilized when I made something for AD, but I am not aware of any way to break up a list like this.
If anyone has any other ways to solve this issue I would be more than open to any suggestion.
Thanks for taking the time to read this!
There are many ways of doing it. I found it very readable.
My favorite one is this one:
$ObjectList = 1..1000
$Step = 100
$counter = [pscustomobject] #{ Value = 0 }
$ObjectListSplitted = $ObjectList | Group-Object -Property { math]::Floor($counter.Value++ / $step) }
Then if you want to show the third subset just use this format :
$ObjectListSplitted[3].Group
Have a look to this solution already explained.
As a note other languages are capable of slicing an array of object with a start, stop and a step, have a look here if you're curious.
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 am using PowerNSX module to work with NSX and I would like to retrieve ESG syslog server configuration.
I have managed to find out how to get values using $esgs = get-nsxedge and then retrieve values by typing $esgs.features.syslog.serveraddresses
I've got an output of several IP's. I would like to display ESG name (it is retrieved from get-nsxedge) and combine it with retrieved syslog IP.
How can I achieve this?
Br
wojcieh
Based on above description I guess that the information you want to combine is stored in $esgs. To select the name and the IP addresses you've to use calculated properties.
Example:
$esgs | select-object -Property PropertyNameWhereEsgNameIsStored, #{Name="IpAddresses";Expression={$_.features.syslog.serveraddresses}}
Hope that helps