PowerShellAccessControl Module 3.0 output - powershell

Does anyone knows what O CC CO under the "Applied To" in the output of the following Get-AccessControlEntry command means?
PS> Get-ADUser tuser | Get-AccessControlEntry -ObjectAceType memberof -ActiveDirectoryRights ReadProperty
AceType Principal AccessMask InheritedFrom AppliesTo OnlyAppliesHere
------- --------- ---------- ------------- --------- ---------------
AccessAllowed Prod\ADR-CanGet_memberOf Read memberOf Property <not inherited> O CC CO False

Going out on a limb I'd say it stands for Object, ChildContainers and ChildObjects.

Related

Repeating the server name in the Win32_Service StartName report

I am trying to figure out in Powershell how to format this input example.
Input
SERVER0040 name startname
---------- ---- ---------
AGS Cash Forecasting DOMAIN\serviceaccount
AGS CutOffTime DOMAIN\serviceaccount
AGS DL DOMAIN\serviceaccount
SERVER0042 name startname
---------- ---- ---------
AGBankImportService DOMAIN\serviceaccount
AGConfirmationDeliveryService DOMAIN\serviceaccount
AGConfirmationMatchService DOMAIN\serviceaccount
To get the output as shown below.
Server name startname
SERVER0040 AGS Cash Forecasting DOMAIN\serviceaccount
SERVER0040 AGS CutOffTime DOMAIN\serviceaccount
SERVER0040 AGS DL DOMAIN\serviceaccount
SERVER0042 AGBankImportService DOMAIN\serviceaccount
SERVER0042 AGConfirmationDeliveryService DOMAIN\serviceaccount
SERVER0042 AGConfirmationMatchService DOMAIN\serviceaccount
Thanks for any input.
Edilberto
You are not showing your code, forcing folks to guess at this. There are several ways to format output, depending on how you are getting it in the first place. A simple idea of this is shown is below.
Example:
Clear-Host
$env:COMPUTERNAME,'nwtex01','nwtiis01' |
ForEach {
Get-WmiObject -ComputerName $PSItem -Class Win32_Service |
Select-Object -Property SystemName, Name, StartName -First 3 |
Format-Table -AutoSize
}
# Results
<#
SystemName Name StartName
---------- ---- ---------
NWTDC01 adfssrv NORTHWINDTRADERS\adfsadmin
NWTDC01 AdobeARMservice LocalSystem
NWTDC01 ADSync NORTHWINDTRADERS\sqladmin
SystemName Name StartName
---------- ---- ---------
NWTEX01 AdobeARMservice LocalSystem
NWTEX01 AeLookupSvc localSystem
NWTEX01 ALG NT AUTHORITY\LocalService
SystemName Name StartName
---------- ---- ---------
NWTIIS01 AdobeARMservice LocalSystem
NWTIIS01 AJRouter NT AUTHORITY\LocalService
NWTIIS01 ALG NT AUTHORITY\LocalService
#>
This is a very common PowerShell 101 kind of thing, with many examples in the built-in help files, and blogs all over the web.

powershell select-object property AND expandproperty

Trying to execute a Select-Object, but i can't seem to return property and a value from a key-value list property. There are 3 properties i want returned RunStart, Message and 'tableName' from this Parameters property.
I get too much with this:
|Select-Object -Property Parameters,RunStart,Message
Parameters RunStart Message
---------- -------- -------
{[tableName, AHROR012], [schemaName, dbo]...} 11/14/2019 5:39:06 PM Operation on target failed
But I dont get the RunStart or Message when i do this:
|Select-Object -ExpandProperty Parameters -Property tableName,RunStart,Message
Key Value
--- -----
tableName AHROR012
How do i do it to get:
Parameters.tableName RunStart Message
---------- -------- -------
AHROR012 11/14/2019 5:39:06 PM Operation on target failed
THANKS!!!
... | Select-Object -Property #{
Name='ParametersTableName';
Expression={ $_.Parameters.tableName }
}, RunStart, Message
A more elegant solution would be to use a 2nd select statement:
... | select RunStart,Message -ExpandProperty Parameters | Select RunStart,Message,tableName

Searching for several Operating Systems with Get-ADComputer using LDAP Filter

I am using the below code to get Active Directory information with Get-ADComputer and it works fine
$computersFilter= "(&(operatingSystem=*Windows 7*)(name=*-*)(!name=V7-*)(!name=*-none)(!name=*-oncall)(!name=*-blackbaud)(!name=sc-win7-1)(!name=ut-swclient-01))"
$computers= Get-ADComputer -LDAPFilter $computersFilter -Property LastLogonDate | Select-Object Name, OperatingSystem,LastLogonDate
$computers | Select Name, LastlogonDate, OperatingSystem | Export-Csv $ServiceTagsPath -NoTypeInformation
I'd like to also retrieve computers with operating systems above Windows 7 (Windows 8, 8.1, and Windows 10) but when I change the filter like this:
(&(operatingSystem=*Windows 7*)(operatingSystem=*Windows 8*)(operatingSystem=*Windows 10*) ...
nothing is returned into the $computers variable
so what's the right way to do this?
The way you have defined $computersFilter, if you look at it's type you will notice that it is of type string. And hence it doesn't return anything.
PS C> $computersFilter = "(&(operatingSystem=*Windows7*))(name=*-*)(!name=V7-*)(!name=*-none)(!name=*-oncall)(!name=*-blackbaud)(!name=sc-win7-1)(!name=ut-swclient-01))"
PS C> $computersFilter.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
$computersFilter should be declared as an array, so that the -LDAPFilter parameter is evaluated against the collection of object, like this -
PS C>$computersFilter = #("operatingSystem=*Windows7*", "name=*-*", "!name=V7-*", "!name=*-none", "!name=*-oncall", "!name=*-blackbaud", "!name=sc-win7-1", "!name=ut-swclient-01")
PS C> $computersFilter.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array

Editing Annotations In VSphere Using PowerShell

I need to be able to edit the Annotations of VMs from powershell(ps) as will be editing many at once Image. I found "AvailibleField" after getting VM view in ps Image but not sure how to edit these. Can anyone help? Thanks :)
I think what you're looking for is the Get/Set-Annotation cmdlets: http://www.vmware.com/support/developer/PowerCLI/PowerCLI651/html/Set-Annotation.html
Example:
PS C:\Users\kruddy> Get-VM file02 | select CustomFields
CustomFields
------------
{[CompanyName, ]}
PS C:\Users\kruddy> Get-VM file02 | Get-Annotation
AnnotatedEntity Name Value
--------------- ---- -----
file02 CompanyName
PS C:\Users\kruddy> Set-Annotation -Entity (Get-VM file02) -CustomAttribute CompanyName -Value TempCorp -Confirm:$false
AnnotatedEntity Name Value
--------------- ---- -----
file02 CompanyName TempCorp
PS C:\Users\kruddy> Get-VM file02 | Get-Annotation
AnnotatedEntity Name Value
--------------- ---- -----
file02 CompanyName TempCorp
PS C:\Users\kruddy> Get-VM file02 | select CustomFields
CustomFields
------------
{[CompanyName, TempCorp]}
PS C:\Users\kruddy>

Get server names in a column and check if they exist in AD

I have a script that shows reserved IP list with computer names like below:
Get-DhcpServerv4Scope -ScopeId 192.168.2.0 |
Get-DhcpServerv4Reservation |
select IPAddress, ScopeId, addressstate, clientid, Name
The output of above code is like below:
IPAddress ScopeId addressstate clientid Name
--------- ------- ------------ -------- ----
192.168.2.57 192.168.2.0 InactiveReservation 00-50-56-9a-44-01 xyz.domain.com
192.168.2.58 192.168.2.0 InactiveReservation 00-50-56-9a-44-03 abc.domain.com
What I want is to get server names in Name column and to check if each of which exists in AD or not. I need to write the output of existence check in a column next to Name.
How can I manage this?
Use calculated properties for adding derivative information:
... | select ..., Name, #{n='Exists';e={$name=$_.Name; [bool](Get-ADComputer -Filter "Name -eq '$name'")}}