本文介绍了我想在Red Hat Linux服务器中执行.ps1 powershell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个在窗口中执行的.ps1 powershell脚本,但是我的全部数据都在linux服务器中,有没有什么办法可以在red hat服务器中执行powershell脚本
i am having a .ps1 powershell script which executes in window, but my whole data is in linux server, is there any possible way via which i can execute the powershell script in red hat server
powershell脚本为:
the powershell script is :
Clear-Host
$path="D:\Deep Backup 26-04-2013\New folder"
$systemname=Read-Host 'Enter System Name'
$files=Get-ChildItem $path -Recurse -Force -Include *_Registrar.zip*,*.reg.zip*
$counter=1
foreach($file in $files)
{
$name=$file.name
[void][system.reflection.Assembly]::LoadFrom("C:\Program Files\MySQL\MySQL Connector Net 6.5.4\Assemblies\v2.0\MySql.Data.dll")
$dbconnect=New-Object MySql.Data.MySqlClient.MySqlConnection
$dbconnect.ConnectionString="server=localhost;userid=root;password=nPr123*;database=test3;"
$dbconnect.Open()
$sql="insert into eid values('"+$name + "','"+$systemname+"')"
$command=new-object MySql.Data.MySqlClient.MySqlCommand($sql,$dbconnect)
$command.ExecuteNonQuery()
}
$sql="insert into eid_unique
select distinct Packet_name, System_name from eid a
where not exists (select 1 from eid_unique b
where a.Packet_name=b.Packet_name);"
$command=new-object MySql.Data.MySqlClient.MySqlCommand($sql,$dbconnect)
$command.ExecuteNonQuery()
$dbconnect.close()
推荐答案
四年后,最初的问题微软发布了powershell对于Linux。它是开源的:
Four years later from original question microsoft releases powershell for linux. And it's opensource: https://github.com/PowerShell/PowerShell
在Linux环境中,您可以使用以下语法:(script.ps1,可执行文件)
In linux environment you can use syntax like this: (script.ps1, executable)
#!/usr/bin/powershell -Command
write-host -fore Green "executing PowerShell!";
这篇关于我想在Red Hat Linux服务器中执行.ps1 powershell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!