Powershell Command vs Variable Formatting

Jordan

I'm playing around with some Powershell commands and implementing them into scripts.

I noticed something that I cannot find much information on despite looking for a few hours so maybe you can help me here. This could also be lack of me searching for the wrong things, apologies ahead if that is the case.

What I'm experimenting with here is manipulating services through PS. Namely, for now, just getting the TaskName. Here is what I am doing:

PS C:\WINDOWS\system32> Get-ScheduledTask -TaskName 'Adobe*' | Select -ExpandProperty TaskName

Output:
Adobe Acrobat Update Task
Adobe Flash Player NPAPI Notifier
Adobe Uninstaller

This is all well and good. However, if I assign that command to a variable from within a powershell script and run the script:

$TaskNames = Get-ScheduledTask -TaskName 'Adobe*' | Select -ExpandProperty TaskName

Output:
Adobe Acrobat Update Task Adobe Flash Player NPAPI Notifier Adobe Uninstaller

So my questions here are:

  1. Why does the formatting change when assigning the command to a variable and calling that variable as opposed to just writing the command explicitly
  2. How can I get the variable call to format output as if I'm just typing the command in the first example
shadow2020
$TaskNames -join "`n" 

... it's doing this probably because one is output of an object, and one is output of an array. If you do $TaskNames.getType() it should tell you it's an array. -join displays an array joined by whatever character you specify.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Bad columns formatting by the tr command

分類Dev

Powershell 7 ForEach-Object Parallel breaks automatic variable when passed to invoke-command

分類Dev

Specify custom formatting for html tags in VS Code

分類Dev

Visual Studio Code vs SQL Formatting

分類Dev

BCP command in powershell

分類Dev

bash export command in powershell

分類Dev

Azure CLI vs Powershell?

分類Dev

Azure CLI vs Powershell?

分類Dev

PowerShell -match vs -like

分類Dev

C# vs PowerShell

分類Dev

Using PowerShell variable in line

分類Dev

Powershell Command open from location and run command

分類Dev

Variable assignment in command substitution

分類Dev

variable in a grep command

分類Dev

Evaluating a command and assigning it to variable

分類Dev

redirecting output of command to variable

分類Dev

Execute command within variable

分類Dev

Output a Command Stored in a Variable

分類Dev

How to run PowerShell command in R?

分類Dev

CMD powershell command not allowing pipe

分類Dev

Execute a powershell command from batch

分類Dev

Formatting Time/Date from different time zones in Powershell

分類Dev

How to use Powershell to paste an excel table into powerpoint while keeping the formatting

分類Dev

ksh/bash Formatting Files through sed by cat file|sed command

分類Dev

Adding the --command flag vs not adding

分類Dev

How to convert variable to time format when values have different formatting

分類Dev

Powershell access to a variable in previous pipe

分類Dev

How to change environment variable with powershell?

分類Dev

Inject variable value in lldb command