Hi
I am new to Power shell. As am trying to get output result in a table format. But still am getting output in a single column.
I am getting output as below:
AlerterStoppedALGRunningAppMgmtStoppedaspnet_stateStopped
But I need as below format:
Name State -------- ---- ----- Alerter Stopped ALG Running AppMgmt Stopped aspnet_state Stopped
Below is the command am going try to get "Win32_Service" Names and its State:
----------------------------------------------------------------------------------
cls $column1 = @{expression="Name"; width=20;label="Name"; alignment="left"} $column2 = @{expression="State"; width=10;label="State"; alignment="right"} $c = Get-WmiObject Win32_Service | ForEach-Object {$_.Name,$_.State} $c | Format-Table $column1, $column2 > "G:\study\power shell\procprop1.txt"
----------------------------------------------------------------------------------------------------------
And also I tried below Command:
------------------------------------------------------------------------------------------------------------
cls $c = Get-WmiObject Win32_Service | ForEach-Object {$_.Name,$_.State} $c | Format-Table Name,State > "G:\study\power shell\wmiservice.txt"
my first rule of formatting: keep it simple.
1. You can do this easily by:
Get-Service | format-list name,state -autosize
2. Using hash tables - you specified expression wrongly - it should look like this:
$column1 = @{expression={$_.Name}; width=20;label="Name"; alignment="left"}
$column2 = @{expression={$_.Status}; width=10;label="State"; alignment="right"}
3. Putting it all together, you can simplify:
$column1 = @{expression="$_.Name"; width=20;label="Name"; alignment="left"}
THat last line is wrong and I can't edit it.
Putting it all together, you can do like this:
Get-WmiObject Win32_Service | Format-Table $column1, $column2
You don't need all the other verbiage in your original post.