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.).
Related
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
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'm trying to edit .NavigationButtons property of multiple MS Access Form objects using VBScript.
Here's my startup code:
Dim access
Set access = CreateObject("Access.Application")
access.OpenCurrentDatabase "d:/mydb.accdb"
Now when database is open I can access it's forms by calling .CurrentProject.AllForms of Application object. This method returns a collection of AccessObject objects. I can set their properties by simply calling .Properties.Add method, but it sets the property of AccessObject and it's not what I want.
I also tried to loop through .Forms property of Application object. This property stores a collection of forms with real form properties and .NavigationButtons is one of them. However, this collection is read-only and I can't set new values to these properties.
Is there any way to update Form property from VBScript program?
Finally, I was able to make it work using both .CurrentProject.AllForms and .Forms methods of Application object. I was missing one detail - you have to save form after you changed it's property.
For Each form.Name access.CurrentProject.AllForms
access.DoCmd.OpenForm form.Name, 1
access.Forms(form.Name).NavigationButtons = True 'Or another property.
access.DoCmd.Close 2, form.Name, 1 'Where "1" is equal to acSaveYes.
Next
I have an array of objects called $listy.
I am looking for object for which property $_.WorkflowAssociations.Count is greater than 0.
When I select that property I can see that several objects fulfill my criteria:
$listy | select title, workflowassociations.count
However when I use where: $listy | where {$_.WorkflowAssociations.Count -gt 0} none of the objects are listed:
I have the same issue with $_.Views.Count property. Other numeric properties seem to filter without issues. Is it because of the point (.)? Why? The property is called exactly Views.Count:
As #EtanReisner already pointed out in the comments to your question: if you have a property name containing a dot (like WorkflowAssociations.Count) you must put the name in quotes when trying to access it via dot notation:
$listy | Where-Object { $_.'WorkflowAssociations.Count' -gt 0 }
If you don't, the term $_.WorkflowAssociations.Count will be interpreted as the property Count of a property WorkflowAssociation of the current object ($_). Which, of course, doesn't exist.
Is it possible to retrieve the RDN of a user object in Active Directory with the attribute intact.
I've done a lot of reading on this and found that an AD user object stores the RDN in an property called "name". Supposedly the value of the name (rdn) property should be something like name = "cn=Smith, Joe". The cn attribute is part of what should be returned. However whenever I retrieve the name property of an object the "cn=" always seems to be missing. For instance
$foo = get-aduser -filter 'Name -like "Smith, Joe"'
$foo.name
will return "Smith, Joe" not "cn=Smith, Joe". Is there someway to query and get the full RDN to return?
An alternative, is to grab the full DN of the object, split the DN, and display the first element in the resulting array, which will be the RDN, either CN= or otherwise, object dependent
$((foo.distinguishedname).split(","))[0]
Not really an answer but informations :
First the attributeId of the RDN attribute is fixed by the schema :
On the RDN point of view Active-Directory inherit from X500 standard. That is to say that you don't choose the attribute you want to create the RDN (in other LDAP directories you can). In Active-Directory the RDN attribute is given in the class schema by rDNAttID, it specifies the attributeId of the RDN attribute. If you look the schema for the class user it's CN.
So you can use :
"CN=$((get-aduser 'Smith, Joe').Name)"
Second do the following experiment :
In an OU create a user called 'Mananegement' you have the following DN CN=MAnagement,OU=MyOU,... now try to create, in the same OU, an OU named 'Mananegement' it should create an object with the following DN OU=MAnagement,OU=MyOU,..., but you receive an error. This error makes me beleive that somehow Active-Directory consider 'Mananegement' as the RDN and not 'CN=Mananegement' like others directories.
$current.Substring($current.IndexOf('OU='))