输入对象powershell更改

时间:2014-06-17 15:01:16

标签: powershell

我正在尝试将$ InvalidInput = $ True从linux更改为powershell命令。我可以通过powershell运行命令,它告诉我$ InvalidInput = $ True为true然后返回false。

我很失落如何改变这一点。任何信息都有帮助。

$InvalidInput= $true 

         if ( $n -eq 0 ) { 
write-host "This script sets up TF90 Staging"
write-host -n "Which production do you `enter code here`want to run?(RB/TaxLocator/Cyclic)"
read $ProductionDistroenter code here
       } else {
 $ProductionDistro=$1
       } 
      while { $InvalidInput = $true }
     do
if  ($ProductionDistro = $RB -o $ProductionDistro = $TaxLocator -o $ProductionDistro = $Cyclic) {
    $InvalidInput=$false
        break continue 
        } else { 
            write-host "You have entered an error"
            write-host "You must type RB or TaxLocator or Cyclic"
            write-host "you typed $ProductionDistro"
            write-host "This script sets up TF90 Staging"
            read $ProductionDistro
            }

原始问题。 ^

完整的脚本将在下面显示,以便您可以看到我想要做的事情。

function Copy-File {
#.Synopsis
# Copies all files and folders in $source folder to $destination folder, but with .copy inserted before the extension if the file already exists
  param}($TFL09143.pkg,"d/tf90/code_stg","d/tf90bp/code_stg","d/tf90lm/code_stg","d/tf90pv/code_stg")

 # create destination if it's not there ...
 #mkdir $destination -force -erroraction SilentlyContinue

 foreach($original in ls $source -recurse) { 
 $result = $original.FullName.Replace($source,$destination)
 while(test-path $result -type leaf){ $result = [IO.Path]::ChangeExtension($result,"copy$([IO.Path]::GetExtension($result))") }

   if($original.PSIsContainer) { 
   # mkdir $result -ErrorAction SilentlyContinue
   # } else {
copy $original.FullName -destination $result
   }
 }
 {$InvalidInput=$true}

   if ( $n -eq 0 ) { 
write-host "This script sets up TF90 Staging"
write-host -n "Which production do you want to run? (RB/TaxLocator/Cyclic)"
 $ProductionDistro
     else 
$ProductionDistro=$1
      }
     ( $InvalidInput = $true) 

if ( $ProductionDistro = $RB,  $ProductionDistro = $TaxLocator, $ProductionDistro = $Cyclic 
            ){
          ( $InvalidInput=$false )
                break 
            } else {
                write-host "You have entered an error"
                write-host "You must type RB or TaxLocator or Cyclic"
                write-host "you typed $ProductionDistro"
                write-host "This script sets up TF90 Staging"
                 $ProductionDistro
            }

    {$InvalidInput=$true}

        if ($n -eq 0) {
            write-host "This script sets up RB TF90 Staging"
            write-host -n "Which Element do you want to run? (TF90/TF90BP/TF90LM/TF90PV/ALL)"
            read $ElementDistro
        else
            $ElementDistro=$1
        }

             ( $InvalidInput = $true )

            If ( $ElementDistro = $TF90, $ElementDistro = $TF90BP, $ElementDistro = $TF90LM, $ElementDistro = $TF90PV, $ElementDistro = $ALL
            ){
                ( $InvalidInput=$false )
                break
            } else {
                write-host "You have entered an error"
                write-host "You must type TF90 or TF90BP or TF90LM or TF90PV"
                write-host "you typed $ElementDistro"
                write-host "This script sets up TF90 Staging"
                $ElementDistro
            } 

if ( $ElementDistro = $TF90 ) {

    cd /d/tf90/code_stg
function Execute-MySQLCommand {param(   [string]$app03bsi,              #the host name of the SQL server
                [string]$TF90NCS,               #the name of the database
                [System.Data.SqlClient.SqlCommand]$Command) #the command to execute (name of stored procedure)

$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "TF90_CONNECT_STRING=DSN=TF90NCS;Description=TF90NCS;Trusted_Connection=Yes;WSID=APP03-
    BSI;DATABASE=TF90NCS;DATASET=DEFAULT"

$Command.CommandType = SET # 1 is the 'Text' command type
$Command.Connection = $sqlConnection

$sqlConnection.Open()
$Result = $Command.ExecuteNonQuery()
$sqlConnection.Close()

if ($Result -gt 0) {return $TRUE} else {return $FALSE}
      }     
    install -y ../TFL09143.pkg

}

if ( $ElementDistro = $TF90BP ) {
    cd /d/tf90bp/code_stg
    function Execute-MySQLCommand {param(   [string]$app03bsi,              #the host name of the SQL server
                [string]$TF90BPS,               #the name of the database
                [System.Data.SqlClient.SqlCommand]$Command) #the command to execute (name of stored procedure)

$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "TF90_CONNECT_STRING=DSN=TF90BPS; Description=TF90BPS; Trusted_Connection=Yes;WSID=APP03-
    BSI;DATABASE=TF90BPS;"

$Command.CommandType = SET # 1 is the 'Text' command type
$Command.Connection = $sqlConnection

$sqlConnection.Open()
$Result = $Command.ExecuteNonQuery()
$sqlConnection.Close()

if ($Result -gt 0) {return $TRUE} else {return $FALSE}

    install ../TFL09143.pkg
}

if ( $ElementDistro = $TF90LM ) {
    cd /d/tf90lm/code_stg
    function Execute-MySQLCommand {param(   [string]$app03bsi,              #the host name of the SQL server
                [string]$TF90LMS,               #the name of the database
                [System.Data.SqlClient.SqlCommand]$Command) #the command to execute (name of stored procedure)

$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "TF90_CONNECT_STRING=DSN=TF90LMS;Description=TF90LMS;Trusted_Connection=Yes;WSID=APP03-
    BSI;DATABASE=TF90LMS;"

$Command.CommandType = SET # 1 is the 'Text' command type
$Command.Connection = $sqlConnection

$sqlConnection.Open()
$Result = $Command.ExecuteNonQuery()
$sqlConnection.Close()

if ($Result -gt 0) {return $TRUE} else {return $FALSE}
    install ../TFL09143.pkg 
}

if ( $ElementDistro = $TF90PV ) {
    cd /d/tf90pv/code_stg
    function Execute-MySQLCommand {param(   [string]$app03bsi,              #the host name of the SQL server
                [string]$TF90PVS,               #the name of the database
                [System.Data.SqlClient.SqlCommand]$Command) #the command to execute (name of stored procedure)

$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString  = "TF90_CONNECT_STRING=DSN=TF90PVS;Description=TF90PVS;Trusted_Connection=Yes;WSID=APP03-
    BSI;DATABASE=TF90PVS;"

$Command.CommandType = SET # 1 is the 'Text' command type
$Command.Connection = $sqlConnection

$sqlConnection.Open()
$Result = $Command.ExecuteNonQuery()
$sqlConnection.Close()

if ($Result -gt 0) {return $TRUE} else {return $FALSE}
}
    install ../TFL09143.pkg
}}}}

产生的是 d / tf90 / code_stg d / tf90bp / code_stg d / tf90lm / code_stg d / tf90pv / code_stg 此脚本设置TF90 Staging $ InvalidInput = $真 真正 您输入了一个错误 您必须键入TF90或TF90BP或TF90LM或TF90PV 你打字了 此脚本设置TF90 Staging

之后显示没有任何反应,也没有做任何事情。我的目标是让它询问我想要选择什么样的产品并让我选择它,并询问我想要选择哪个元素并将包加载到文件夹中。这些都没有完成。

1 个答案:

答案 0 :(得分:1)

我认为更简单的方法是提示用户输入,然后执行While ([User Input] -NotMatch RB or TaxLocator or Cyclic) {Give error and ask again}。请注意,那个伪代码,但我认为这比你工作的更好地为你服务。检查此代码:

write-host "This script sets up TF90 Staging"
$ProductionDistro = Read-Host -Prompt "Which production do you `enter code here`want to run?(RB/TaxLocator/Cyclic)"
While($ProductionDistro -notmatch "(RB|TaxLocator|Cyclic)"){
    write-host "`nYou have entered an error" -ForegroundColor Red
    write-host "You must type RB or TaxLocator or Cyclic"
    write-host "you typed $ProductionDistro"
    write-host "This script sets up TF90 Staging"
    $ProductionDistro = Read-Host -Prompt "Which production do you `enter code here`want to run?(RB/TaxLocator/Cyclic)"
}