bommi1961
Goto Top

Powershell Übergabeparameter

Hallo zusammen!

Ich weis das ist hier schon oft beschrieben wurden, aber leider bekomme ich es nicht hin.

Mein PS:
param(
[parameter(Mandatory=$true)]
[alias("a")]
$ParamA
)

  1. $ParamA



$LIST = Get-ChildItem hklm:\software\Wow6432Node\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.pspath|select -property DisplayName, UninstallString|Format-List}

write $LIST >C:\temp\unstall.txt

$LIST1 = Get-ChildItem hklm:\software\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.pspath|select -property DisplayName, UninstallString|Format-List}
write $LIST1 >>C:\temp\unstall.txt

$LIST2 = Select-String -path C:\temp\unstall.txt -SimpleMatch $ParamA

write $LIST2 >C:\temp\unstall1.txt

$Path = "C:\temp\unstall1.txt"
$LineNumber = 0
$SearchString = "*$ParamA*"

$StreamReader = New-Object System.IO.StreamReader($Path)
While ($StreamReader.Endofstream -eq $False){
$LineNumber +=1
$Line=$StreamReader.ReadLine()
If($Line -like $SearchString){
"LineNumber: {0} -- {1}" -f $LineNumber,$Line
}
}

jetzt muss ich aus einem anderen Programm herraus das hier aufrufen und ihm einen Param. mit geben wo drin steht nach welchen Programm er suchen muss.

Hier bei diesem Beispiel kommt er immer mit einer Abfrage...

Was mache ich falsch?

Content-Key: 314264

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

Printed on: April 24, 2024 at 12:04 o'clock

Mitglied: 129813
129813 Sep 02, 2016 updated at 12:44:27 (UTC)
Goto Top
Hi,
  • first you should post your code inside code-tags face-sad
Select your code and click on this icon:

screenshot

1. $ParamA
This is no valid ps command

  • Second how do you call your script, and which message appears??

jetzt muss ich aus einem anderen Programm herraus das hier aufrufen und ihm einen Param. mit geben wo drin steht nach welchen Programm er suchen muss.
If you call your script from a batch or cmd you do it like this:
powershell.exe -Executionpolicy ByPass -File "C:\yourscript.ps1" "Your first Parameter"
or from a powershell console
'C:\yourscript.ps1' 'Your first parameter'
Hier bei diesem Beispiel kommt er immer mit einer Abfrage...
Which is ? What is the commandline you used to call your script?

Please read:
http://blog.stefanrehwald.de/2013/09/09/powershell-10-einem-script-para ...

Regards

p.s. you don't need a streamreader, you can do this with the already include cmdlet select-string to find strings and their respective line numbers.
Member: mayho33
mayho33 Feb 10, 2020 at 20:31:55 (UTC)
Goto Top
Hi!

Schau dir doch mal das Beispiel aus diesem Thread an:

Powershell-Skipt mit Übergabeparametern

Das du deinen Parameter mit Mandadory=$True gesetzt hast, musst du ihn auch angeben

Get-MyMethode -ParamA