我想在PowerShell腳本中使用一個字串。在執行腳本時,它應該像變數一樣被移交,就像這樣:
這在只有一個字的情況下效果不錯。 但是我的字串看起來是這樣的,應該交待一下:
這個字串包含一些引號,我在把它注入我的腳本時遇到了問題。
在腳本中,我有以下內容: 在腳本中,我有以下內容: uj5u.com熱心網友回復: PowerShell腳本可以接受引數,這些引數成為變數,只是對腳本的其他部分可用。 在你的腳本的頂部使用這個來設定三個變數,一個布爾(真偽)型別,一個字串型別和一個整數型別。
然后傳入數值 如何處理奇數或復雜字串 現在,如果要傳入一個有引號的復雜字串,請使用這個語法:
標籤:C:WindowsSystem32WindowsPowerShellv1.0powershell.exe
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -c C: empmyscript.ps1 "string" **<UserInputs>< UserInputs Question="Gruppenname"/span> Answer="& lt;Values Count="1"&。 gt;<Value DisplayName="Humanresources&。 quot; Id="af05c5d3-2312-c897-8439-08979d4d0a49& quot; />< /Values>" Type="System. SupportingItem.PortalControl.InstancePicker InstancePicker" />< UserInput Question="Ausgabe"/span> 答案="Namen" 型別="richtext" /> </UserInputs>**。
$mystring = $Null if($args[0] -ne $Null) { $mystring = $args[0] } $result = $mystring | Select-String -Pattern "DisplayName=& quot; (. *?)"" $result= $result. Matches.Groups[1] $group = $result. value Write-Output "$group" | Out-file C: empgroup.txt
#stack.ps1
param(
# Param1幫助描述。
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]$MyString="MyDefaultValue"/span>。
[int]$MyIntInput。
[bool]$MyTrueFalseInput。
)
"腳本正在運行!"。
"收到的值!"。
"MyString = $MyString"。
"MyIntInput = $MyIntInput"。
"MyTrueFalse = $MyTrueFalseInput"。
C: emp> .stack.ps1 -MyString Ham -MyIntInput 75 -MyTrueFalseInput $true
腳本正在運行!
收到的值!
MyString = Ham
MyIntInput = 75
MyTrueFalse = True
# using single quotes as a delimiter, ignoring the doubles inside.
$myWeirdString = 'ThisIs "SomeString "WhichHasQuotes "WhichIsWeird'
##額外的情況,如果它真的很奇怪并且有兩種引號型別。
$myWeirdString = @"
'ThisIs"SomeString"WhichHasQuotes"WhichIsWeird'
"@
