Repeating the server name in the Win32_Service StartName report - powershell

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.

Related

How to gather CPU and RAM information using Powershell and display into one table

I am trying to create a script that gather the CPU and RAM information from the Local computer, but I need it to display in the same row.
$installed =
$processor = Get-WmiObject -Class Win32_Processor | Select-Object -Property Name
$memory = Get-WmiObject Win32_PhysicalMemory | Format-Table BankLabel, Capacity, Manufacturer
$result = $processor, $memory
$result | out-file test.txt
What I got
SystemName Name
---------- ----
EX Intel(R) Core(TM) i5-8500T CPU # 2.10GHz
Capacity Manufacturer
-------- ------------
8589934592 80AD000080AD
What I want to achieve
SystemName Name Capacity Manufacturer
---------- ---- ---------------------
EX Intel(R) Core(TM) i5-8500T CPU # 2.10GHz
Are there any ways to emerge the two tables?
Yes. Create a custom PowerShell object.
# Gather the data from the local (or remote) system
$processor = Get-WmiObject -Class Win32_Processor
$memory = Get-WmiObject Win32_PhysicalMemory
# Create a custom PowerShell object with the desired properties
[PSCustomObject]#{
SystemName = $processor.SystemName
Name = $processor.Name
MemoryCapacity = $memory.Capacity
Manufacturer = $memory.Manufacturer
}
Here's what the output looks like on my system.
SystemName Name MemoryCapacity Manufacturer
---------- ---- -------------- ------------
ARTEMIS AMD Ryzen 9 3900X 12-Core Processor {17179869184, 17179869184} {Unknown, Unknown}

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>

PowerShellAccessControl Module 3.0 output

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.

Incorrect total size result from powershell

I'm facing a problem which the result of getdrive is not accurate. Clueless.
As seen in the screenshots below, 10.1.105.203 has a total space of 7.81TB, but from what powershell gives me, it is only roughly 4TB. Pretty confusing here.
You can also use Get-Psdrive to get the size of a drive.
PS C:\> Get-PSDrive -PSProvider filesystem
Name Used (GB) Free (GB) Provider Root
---- --------- --------- -------- ----
C 48.92 195.13 FileSystem C:\
D 30.82 69.18 FileSystem D:\
E .12 121.49 FileSystem E:\
You can always do a little manipulation to achieve multiple things with this, e.g,
PS C:\> Get-PSDrive -PSProvider filesystem | select Name, #{n= 'Used(GB)' ; e = {"{0:N2}" -f ($_.used/1GB)}}, #{n= 'Free
(GB)' ; e = {"{0:N2}" -f ($_.Free/1GB)}}, #{n= 'Total(GB)' ; e = {"{0:N2}" -f (($_.used + $_.Free)/1GB)}} | ft -auto
Name Used(GB) Free(GB) Total(GB)
---- -------- -------- ---------
C 48.92 195.13 244.04
D 30.82 69.18 100.00
E 0.12 121.49 121.62
You're not really using PowerShell. You're using the Windows Scripting Host's object model, the precursor to PowerShell, from PowerShell. Try using either:
C:\PS> Get-Volume
DriveLetter FileSystemLabel FileSystem DriveType HealthStatus SizeRemaining Size
----------- --------------- ---------- --------- ------------ ------------- ----
C NTFS Fixed Healthy 94.34 GB 237.96 GB
Recovery NTFS Fixed Healthy 10.19 MB 300 MB
or
C:\PS> Get-WmiObject Win32_Volume | Format-Table DriveLetter,Capacity,FreeSpace
DriveLetter Capacity FreeSpace
----------- -------- ---------
C: 255505461248 101292863488
314568704 10682368
Full agree with #Keith Hill, with the PowerShell way to get the result. The strange behaviour is that for your drive L:, I can see that the total size is ok for the 10Tb drive, so I would not be surprise if you receive the same results from the new commands.
The next thing, I would check is if quotas are activated on your server.
You can also use :
Get-WmiObject Win32_logicaldisk -filter "driveType=4"