apparentlysimon
Goto Top

Powershell - Softwareabfrage von Remote PC

Hallo liebe Community,

ich bin neu auf dem Gebiet der Shell. Ich bin derzeit dabei ein Programm zu entwickeln, was es mir ermöglicht per Remote auf einen PC zuzugreifen und dort eine art Softwareabfrage durchführt.
Ich will also von meinem PC über die Powershell die gesamte installierte Software auf dem Remote PC auslesen und diese, zentral in einer txt datei auf meinem PC abspeichern.
Mein Skript derzeit sieht wie folgt aus:

Version 2.3
@* **

$computer = "Test"
Invoke-Command -Cn $computer -Credential $cred -ScriptBlock
{Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
Sort Displayname |
Select-Object DisplayName, DisplayVersion, InstallDate, Publisher |
out-file "c:\TestPS\Softwareabfrage\Test\SoftwareTest.txt " -append}

Dies funktioniert aber leider so garnicht...

Könnt ihr mir da helfen?

Viele Grüße
Simon

PS: Dies ist der Fehlercode:
Invoke-Command : Fehlendes Argument für den Parameter "ScriptBlock". Geben Sie einen Parameter vom Typ
"System.Management.Automation.ScriptBlock" an, und versuchen Sie es erneut.
In Zeile:2 Zeichen:48

back-to-topInvoke-Command -Cn $computer -Credential $cred -ScriptBlock

back-to-top~~~~~~~~~~~~

+ CategoryInfo : InvalidArgument: (face-smile [Invoke-Command], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.InvokeCommandCommand

Content-Key: 2471466937

Url: https://administrator.de/contentid/2471466937

Printed on: June 16, 2024 at 19:06 o'clock

Member: MrCount
MrCount Apr 11, 2022 at 08:02:04 (UTC)
Goto Top
Servus,

versuche es mal mit einer Variablen:

$script = {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Sort Displayname | Select-Object DisplayName, DisplayVersion, InstallDate, Publisher | out-file "c:\TestPS\Softwareabfrage\Test\SoftwareTest.txt " -append}  

Invoke-Command -Cn $computer -Credential $cred -ScriptBlock $script
Member: ApparentlySimon
ApparentlySimon Apr 11, 2022 at 08:13:50 (UTC)
Goto Top
Hey, besten dank!
das hat super funktioniert. Leider speichert er mir die Datei auf dem Remote PC. Gibt es eine möglichkeit wie ich die Datei auf meinem PC selber speicher?
Also nach dem Motto:
PC1 führt Befehl aus verbindet sich zu PC2.
Auf PC2 wird die datei gespeichert.

Das soll so sein:
PC1 führt Befehl aus verbindet sich zu PC2.
Auf PC1 wird die datei gespeichert.

Viele Grüße Simon
Member: MrCount
Solution MrCount Apr 11, 2022 at 08:28:06 (UTC)
Goto Top
Sollte so gehen:

$script = {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Sort Displayname | Select-Object DisplayName, DisplayVersion, InstallDate, Publisher}

$command = Invoke-Command -Cn $computer -Credential $cred -ScriptBlock $script

$command | out-file "c:\TestPS\Softwareabfrage\Test\SoftwareTest.txt " -append  
Member: ApparentlySimon
ApparentlySimon Apr 11, 2022 at 08:46:08 (UTC)
Goto Top
Herzlichen Danke! Damit klappt es wunderbar!
Eine letzte Frage hätte ich. Kann man die Outfile datei besser Sortieren?

So, dass mein Output ca so ausschaut:

DisplayName DisplayVersion InstallDate Publisher
-------------- ----------- ---------
Adobe Acrobat 2017 17.012.30205 20220310 Adobe Systems Incorpor...
Adobe Genuine Service 7.6.0.52 Adobe Inc.
Adobe Refresh Manager 1.8.0 20220108 Adobe Systems Incorpor...
...

Und nicht so:

DisplayName : Adobe Acrobat 2017
DisplayVersion : 17.012.30205
InstallDate : 20220310
Publisher : Adobe Systems Incorporated
PSComputerName : BCI-TH-PEAXACT
RunspaceId : 248cdc85-c086-4fb7-9e34-80677714159d

DisplayName : Adobe Genuine Service
DisplayVersion : 7.6.0.52
InstallDate :
Publisher : Adobe Inc.
PSComputerName : BCI-TH-PEAXACT
RunspaceId : 248cdc85-c086-4fb7-9e34-80677714159d

DisplayName : Adobe Refresh Manager
DisplayVersion : 1.8.0
InstallDate : 20220108
Publisher : Adobe Systems Incorporated
PSComputerName : BCI-TH-PEAXACT
RunspaceId : 248cdc85-c086-4fb7-9e34-80677714159d

...
Member: ApparentlySimon
Solution ApparentlySimon Apr 11, 2022 at 08:51:45 (UTC)
Goto Top
Ah hab es schon gelöst!
So funktioniert alles!

Version 2.4
@***

$cred = "USERNAME"
$computer = "COMPUTERNAME"

$script = {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Sort Displayname | Select-Object DisplayName, DisplayVersion, InstallDate, Publisher | Format-Table}

$command = Invoke-Command -Cn $computer -Credential $cred -ScriptBlock $script

$command | out-file "c:\TestPS\Softwareabfrage\$computer\Software$computer.txt"


Danke dir MrCount!
Member: MrCount
MrCount Apr 11, 2022 at 08:52:46 (UTC)
Goto Top
Mitglied: 148523
148523 Apr 11, 2022 at 17:09:54 (UTC)
Goto Top
Code Tags zu nutzen ist nur was für Dummies und wird überbewertet !
Formatting instructions in the posts