When I type in Get-IISAppPool the Status property is always empty.
Get-IISAppPool | Select-Object Status
The application pools are running, and the names are correct.
Does anyone know why?
I'm not the creator of the application pools, could that be the reason?
Status is not a property of the returned objects. This is a calculated property for the default table output. If you run this command:
Get-IISAppPool | Get-Member
You will see there is no Status property. There is, however, a State property, which, I guess, is where the default view gets it's value:
State Property Microsoft.Web.Administration.ObjectState State {get;}
In fact, if you look at the member information, apart from Name, none of the items in the default view appear as properties - well, they do, but under different names.
If you want to know the status of the particular application pool using the powershell command.
Open PowerShell as administrator.
Run below command:
Get-WebAppPoolState -Name sample1
Note:
Check the name of the application pool you used in command that is available or not.
Regards,
Jalpa
Related
So I need to create a report of what odbc-dsns are on computers.
The first hurdle I'm trying to do is get the csv to output correctly on MINE. Then I figure I'll just deploy a runonce group policy with the script set to append.
The problem is that get-odbcdns returns an object. That object has:
Name: the friendly name of the odbc
Attribute : {Description}
I just want to be able to formatlist with the VALUE of the {Description} value inside the Attribute property. I can't figure out how to do that.
Whenever I go | fl name, attribute
it returns 1sl-den-db01 and {description} I would like for it to actually parse out description from Attribute. No idea how. Thoughts?
I have a commandlet that gathers information from a device register:
PS C:\windows\system32> Get-PSDevice serverA
HostName: ServerA
OOB:
Criticality: Normal
IsVirtual: True
etc
Some of these have an array of 'sub properties' inside, for example:
Cluster : #{Url=https://ps-apps.com/DeviceRegister/api/Clusters/62; VCenterUrl=https://ps-apps.com/DeviceRegister/api/VCenters/2; ClusterId=62; VCenterId=2; Name=Vcenter 1 ABC Prod;
DataCenterUrl=https://ps-apps.com/DeviceRegister/api/DataCenters/3; DataCenter=; IsValidated=True; IsExceptionCluster=False; SupportsProdWorkloads=False; SupportsNonProdWorkloads=False; SupportsSqlWorkloads=False;
ManagedByabc=False}
I can get whatever property within the aray I want using something like:
(Get-PSDevice ServerA).cluster.name
I'm trying to determine a way to enumerate all of the sub properties using a foreach type statement to populate a value.
What would be the best way to achieve this?
Every object in PowerShell has a hidden .PSObject property which tells you things about the object. One of its properties is a .Properties property (as PetSerAl points out, it's not a property but in fact a MemberSet, though you access it with property semantics).
(Get-PSDevice ServerA).cluster.PSObject.Properties
That would return [PSProperty] objects that show you the information about the properties (the name, value, type, whether it's gettable and settable, etc.).
As per the subject, I'm trying to get the name of a property and the value assocaited with that property, for a specific mailbox.
So, the line below gets me a nice list of the available object properties, and a default column displayed in the output has the heading 'Name'
Get-Mailbox -Identity "Person Name" | gm
I then want to say something like:
For the object: "Mailbox of Person Name"
Where the property of "Mailbox of Person Name" has a name like 'quota'
List both the actual property name and it's value for "Mailbox of Person Name"
I've tried a number of things using -ExpandProperty/Select-Object/Where-Object but they're all failing. I'm sure this is pretty basic, but Powershell is definitely not my strength. Can anyone show me how to structure this pipeline correctly?
You do not need to use Where-Object, only Select-Object:
Get-Mailbox -Identity "Person Name" | Select-Object -Property *quota*
You seem to have used the correct commandlets. Where-Object filters. Select-Object selects specific properties.
From my experience, sometimes what you see on the console doesn't match the actual property name because there is a formatter that can even change the column name. If you you drive the Where-Object and Select-Object with that virtual property name then they do fail. Also sometimes, the output is not really a recordset that works well with these cmdlets.
My advice is to always check the type of an object when things go strange. Starting from $items=Get-Mailbox -Identity "Person Name".
Then $items.GetType() reveals the actual .net type.
Then $items.Count reveals if it is actually an array or a single object.
Then $items|ForEach-Object {$_.GetType()} reveals the type of each object.
Also the $items|Get-Member is very helpful to figure out the property names. If necessary use it also within your loop.
That is how I troubleshoot strange behaviors and if you can post your findings and the code you tried with Where-Object and Select-Object that would be a great help.
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've a sitecore template with field name state. Where a state field has a drop link field which displays the country states from "Country State" node.
I'm trying to write a query which shows all the courses with given states.
But when I run the query below it shows "Sitecore.Data.Items.ItemState".
gci -recurse | format-table state
Any idea on why it's not displaying the state GUID value instead?
I understand this is long overdue and you have probably dealt with it long time ago, but for the sake of anyone who would run into it in the future, let me explain why and how.
The reason why State returns the Sitecore.Data.Items.ItemState text is that the Sitecore items contains a property named State on the Item object.
Sitecore PowerShell Extensions attaches additional dynamic properties on to the object that expose your item fields. Those however cannot collide with the existing item properties which would be the case here. To avoid the collision SPE will detect it and prepend the dynamic property with an underscore. In your case the one liner that would give you the expected results would be:
gci -recurse | format-table _state
or if you wanted to display the property as State still rather than _state you could use the following syntax:
gci master:\content | format-table #{Name="State"; Expression={$_._state } }
Hope this still helps someone.