mysql - 为什么 write_host 不被识别为命令

标签 mysql powershell

我可以选择第一个写入主机,它会跳转到第二个写入主机以输入信息,但是当我尝试在第二个写入主机上选择一个选项时,无论我在它们之间选择什么,我都会遇到相同的错误。

错误是

术语“write_host”未被识别为 cmdlet、函数、脚本文件或可操作程序的名称。检查拼写 名称的名称,或者如果包含路径,请验证路径是否正确,然后重试。 行:110 字符:23 + write_host <<<<“设置要运行暂存的位置” + 类别信息:ObjectNotFound:(write_host:字符串)[],CommandNotFoundException + FullQualifiedErrorId:CommandNotFoundException

function Execute-MySqlcommand {param( [string]$Server,    #the host of the SQL server
                                            [string]$Database1,   #the name of the database
                                            [System.Data.MySqlclient.MySqlcommand]$Command)  #the command to execute (name of stored command)

         $mysqlConnection = new-object System.Data.MySqlclient.MySqlConnection
         $MySqlConnection.ConnectionString = "DROP_VIEW DATABASE.BTXADDR;DROP_VIEW DATABASE.BTXSUPB;CREATE_VIEW DATABASE.BTXADDR FOR DATABASE1.DATABASE1S2.BTXADDR;CREATE_VIEW DATABASE.BTXSUPB FOR DATABASE1.DATABASE1S3.BTXSUPB"
         $MySqlConnection.ConnectionString = "TRUNCATE TABLE DATABASE1.DATABASE1S2.BTXADDR;TRUNCATE TABLE DATABASE1.DATABASE1S3.BTXSUPB; INSERT INTO DATABASE1.DATABASE1S3.BTXSUPB SELECT * FROM DATABASE1.DATABASE1S2.BTXSUPB; select count(*) from DATABASE1.DATABASE.BTXADDR; select count(*) from DATABASE1S.DATABASE.BTXADDR; select count(*) from DATABASE1.DATABASE.BTXSURB; select count(*) from DATABASE1S.DATABASE.BTXSUPB;"

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

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

         if ($Result -gt 0) {return $True} else {return $False}

 }
function execute-MySqlcommand {param( [string]$Server,    #the host of the SQL server
                                            [string]$DataBase2,   #the name of the database
                                            [System.Data.MySqlclient.MySqlcommand]$Command)  #the command to execute (name of stored command)

         $mysqlConnection = new-object System.Data.MySqlclient.MySqlConnection
         $MySqlConnection.ConnectionString = "DROP_VIEW DATABASE.BTXADDR;DROP_VIEW DATABASE.BTXSUPB;CREATE_VIEW DATABASE.BTXADDR FOR DATABASE2.DATABASE2MS2.BTXADDR;CREATE_VIEW DATABASE.BTXSUPB FOR DATABASE2.DATABASE2S3.BTXSUPB"
         $MySqlConnection.ConnectionString = "TRUNCATE TABLE DATABASE2.DATABASE2S2.BTXADDR;TRUNCATE TABLE DATABASE2.DATABASE2S3.BTXSUPB; INSERT INTO DATABASE2.DATABASE2S3.BTXSUPB SELECT * FROM DATABASE2.DATABASE2S2.BTXSUPB; select count(*) from DATABASE2.DATABASE.BTXADDR; select count(*) from DATABASE2S.DATABASE.BTXADDR; select count(*) from DATABASE2.DATABASE.BTXSURB; select count(*) from DATABASE2S.DATABASE.BTXSUPB;"

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

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

         if ($Result -gt 0) {return $True} else {return $False}

 }
function Execute-MySqlcommand {param( [string]$Server,    #the host of the SQL server
                                            [string]$DATABASE3,   #the name of the database
                                            [System.Data.MySqlclient.MySqlcommand]$Command)  #the command to execute (name of stored command)

         $mysqlConnection = new-object System.Data.MySqlclient.MySqlConnection
         $MySqlConnection.ConnectionString = "DROP_VIEW DATABASE.BTXADDR;DROP_VIEW DATABASE.BTXSUPB;CREATE_VIEW DATABASE.BTXADDR FOR DATABASE3.DATABASE3S2.BTXADDR;CREATE_VIEW DATABASE.BTXSUPB FOR DATABASE3.DATABASE3S3.BTXSUPB"
         $MySqlConnection.ConnectionString = "TRUNCATE TABLE DATABASE3.DATABASE3S2.BTXADDR;TRUNCATE TABLE DATABASE3.DATABASE3S3.BTXSUPB; INSERT INTO DATABASE3.DATABASE3S3.BTXSUPB SELECT * FROM DATABASE3.DATABASE3S2.BTXSUPB; select count(*) from DATABASE3.DATABASE.BTXADDR; select count(*) from DATABASE3S.DATABASE.BTXADDR; select count(*) from DATABASE3.DATABASE.BTXSURB; select count(*) from DATABASE3S.DATABASE.BTXSUPB;"

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

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

         if ($Result -gt 0) {return $True} else {return $False}

 }
function Execute-MySqlcommand {param( [string]$Server,    #the host of the SQL server
                                            [string]$DATABASE4,   #the name of the database
                                            [System.Data.MySqlclient.MySqlcommand]$Command)  #the command to execute (name of stored command)

         $mysqlConnection = new-object System.Data.MySqlclient.MySqlConnection
         $MySqlConnection.ConnectionString = "DROP_VIEW DATABASE.BTXADDR;DROP_VIEW DATABASE.BTXSUPB;CREATE_VIEW DATABASE.BTXADDR FOR DATABASE4.DATABASE42.BTXADDR;CREATE_VIEW DATABASE.BTXSUPB FOR DATABASE4.DATABASE4S3.BTXSUPB"
         $MySqlConnection.ConnectionString = "TRUNCATE TABLE DATABASE4.DATABASE4S2.BTXADDR;TRUNCATE TABLE DATABASE4.DATABASE4S3.BTXSUPB; INSERT INTO DATABASE4.DATABASE4S3.BTXSUPB SELECT * FROM DATABASE4.DATABASE4S2.BTXSUPB; select count(*) from DATABASE4.DATABASE.BTXADDR; select count(*) from DATABASE4S.DATABASE.BTXADDR; select count(*) from DATABASE4.DATABASE.BTXSURB; select count(*) from DATABASE4S.DATABASE.BTXSUPB;"

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

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

         if ($Result -gt 0) {return $True} else {return $False}

 }


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}($DATABASE0980453.pkg,"d/DATABASE1/code_stg","d/DATABASE2/code_stg","d/DATABASE3/code_stg","d/DATABASE4/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
  }
}
write-host "This script sets up DATABASE Staging"
$ProductionDistro = Read-Host -Prompt "Which production do you `enter code here`want to run?(TC/MonsterLock/Cyc)"
While($ProductionDistro -notmatch "(TC/MonsterLock/Cyc)"){
    write-host "You have entered an error" -ForegroundColor Red
    write-host "You must type TC or MonsterLock or Cyc"
    write-host "you typed $ProductionDistro"
    write-host "This script sets up DATABASE Staging"
    $ProductionDistro = Read-Host -Prompt "Which production do you `enter code here`want to run?(TC/MonsterLock/Cyc)"
}

write-host "Sets up location you want to run staging"
        $ElementDistro = Read-Host -Prompt "Which Element do you want to run? (DATABASE1/DATABASE2/DATABASE3/DATABASE4/ALL)"
        While($ElementDitro -notmatch "(DATABASE1/DATABASE2/DATABASE3/DATABASE4/ALL)") {
            write-host "you have enterd an error" -ForgroundColor Red
            write-host "You must type DATABASE1 or DATABASE2 or DATABASE3 or DATABASE4 or ALL"
            write-host "you typed $ElementDistro"
            write-host "set location you want to run staging"
          $ElementDistro = Read-Host -Prompt "Which Element do you want to run? (DATABASE1/DATABASE2/DATABASE3/DATABASE4/ALL)"
 }

    if ( $ElementDistro = $DATABASE1 )

        cd /d/DATABASE1/code_stg
    function Execute-MySQLCommand {param(   [string]$Server,                #the host name of the SQL server
                    [string]$DATABASE1,             #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 = "DATABASE_CONNECT_STRING=DSN=DATABASE1;Description=DATABASE1;Trusted_Connection=Yes;WSID=Server;DATABASE=DATABASE1;DATASET=DEFAULT"

    $Command.CommandType = 1 # 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  ../DATABASE0980453.pkg

    }

    if ( $ElementDistro = $DATABASE2 ) {
        cd /d/DATABASE2/code_stg
        function Execute-MySQLCommand {param(   [string]$Server,                #the host name of the SQL server
                    [string]$DATABASE2,             #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 = "DATABASE_CONNECT_STRING=DSN=DATABASE2; Description=DATABASE2; Trusted_Connection=Yes;WSID=Server;DATABASE=DATABASE2;"

    $Command.CommandType = 1 # 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 ../DATABASE0980453.pkg
    }

    if ( $ElementDistro = $DATABASE3 ) {
        cd /d/DATABASE3/code_stg
        function Execute-MySQLCommand {param(   [string]$Server,                #the host name of the SQL server
                    [string]$DATABASE3,             #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 = "DATABASE_CONNECT_STRING=DSN=DATABASE3;Description=DATABASE3;Trusted_Connection=Yes;WSID=Server;DATABASE=DATABASE3;"

    $Command.CommandType = 1 # 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 ../DATABASE0980453.pkg
    }

    if ( $ElementDistro = $DATABASE4 ) {
        cd /d/DATABASE4/code_stg
        function Execute-MySQLCommand {param(   [string]$Server,                #the host name of the SQL server
                    [string]$DATABASE4,             #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 = "DATABASE_CONNECT_STRING=DSN=DATABASE4;Description=DATABASE4;Trusted_Connection=Yes;WSID=Server;DATABASE=TF90PVS;"

    $Command.CommandType = 1 # 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 ../DATABASE0980453.pkg

     if ( $ElementDisrto = $ALL ){

     function Execute-MySQLCommand {param(  [string]$app03bsi,              #the host name of the SQL server
                    [string]$DATABASE1,$DATABASE2,$DATABASE3,$DATABASE4,                #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 = "(DATABASE_CONNECT_STRING=DSN=DATABASE1;Description=DATABASE1;Trusted_Connection=Yes;WSID=Server;DATABASE=DATABASE1;DATASET=DEFAULT;),(DATABASE_CONNECT_STRING=DSN=DATABASE2; Description=DATABASE2; Trusted_Connection=Yes;WSID=Server;DATABASE=DATABASE2;),(DATABASE_CONNECT_STRING=DSN=DATABASE3;Description=DATABASE3;Trusted_Connection=Yes;WSID=Server;DATABASE=DATABASE3;),(DATABASE_CONNECT_STRING=DSN=DATABASE4;Description=DATABASE4;Trusted_Connection=Yes;WSID=Server;DATABASE=TF90PVS;)"

    $Command.CommandType = 1 # 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 ../DATABASE0980453.pkg
     }

}}}}

最佳答案

您的问题出在这一行:

write_host "set location you want to run staging"

cmdlet 的名称是 write-host,而不是 write_host。下划线应该是连字符:

write-host "set location you want to run staging"

关于mysql - 为什么 write_host 不被识别为命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24271913/

相关文章:

powershell - Windows PowerShell 在哪里设置 $profile?

mysql - 如何只获取列表中指定的项目?

mysql - 从表中获取列名称,其中值为零

mysql - 从 SQL 日期时间格式中提取小时数?

c# - 添加到数据库后访问对象属性

powershell - Powershell阵列到文本文件

mysql - 从 SQL 结果中删除重复项并显示其他列

windows - 使用 PowerShell 检查内存类型(是否 ECC)

powershell - 重命名计算机并添加加入域powershell脚本

function - 如何正确地将 Win32 类对象传递给函数