static public void loadUtils() { string FileName = @".\vmmodule.ps1"; if (System.IO.File.Exists(FileName)) { WraperPs.RunScript(@". " + FileName); } }
private void btnRun_Click(object sender, EventArgs e) { try { txtResult.Clear(); txtResult.Text = WraperPs.RunScript(txtScript.Text); toDataView(txtResult.Text); } catch (Exception error) { txtResult.Text += String.Format("\r\nError in script : {0}\r\n", error.Message); } }
public void DoScript(string scriptText) { if (Properties.Settings.Default.isDebug) { txtScript.Text += scriptText; } try { txtResult.Text = WraperPs.RunScript(scriptText); } catch (Exception error) { txtResult.Text += String.Format("\r\nError in script : {0}\r\n", error.Message); } }
private void btnDiskTree_Click(object sender, EventArgs e) { DataColumn dc = aTable.Columns["Disk Name"]; if (dc == null) { MessageBox.Show("未選擇硬碟", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string id = dataGridView1.SelectedCells[0].Value.ToString(); string cmd = "Get-VHDChain -Path " + id; txtScript.Text = cmd; txtResult.Text = WraperPs.RunScript(cmd); toDataView(txtResult.Text, "Disk Tree"); }
private void btnMergeDisk_Click(object sender, EventArgs e) { DataColumn dc = aTable.Columns["Disk Tree"]; if (dc == null) { MessageBox.Show("未選擇虛擬機", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string id = dataGridView1.SelectedCells[0].Value.ToString(); string cmd = "MergeDisk -DiskPath " + id; txtScript.Text = cmd; txtResult.Text = WraperPs.RunScript(cmd); txtResult.Text = txtResult.Text + Environment.NewLine + " ==>done"; //toDataView(txtResult.Text, "Disk Tree"); }
private void btnGetDisk_Click(object sender, EventArgs e) { string prevAction = "Vm Name"; DataColumn dc = aTable.Columns[prevAction]; //如果有的話,dc.ColumnName if (dc == null) { MessageBox.Show("未選擇虛擬機", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string id = dataGridView1.SelectedCells[0].Value.ToString(); string cmd = "listDisk -Name " + id; txtScript.Text = cmd; txtResult.Text = WraperPs.RunScript(cmd); toDataView(txtResult.Text, "Disk Name"); }
private void btnGetVm_Click(object sender, EventArgs e) { txtResult.Text = WraperPs.RunScript("(Get-Vm).Name"); toDataView(txtResult.Text, "Vm Name"); }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { WraperPs.end_session(); }
private void Form1_Load(object sender, EventArgs e) { WraperPs.init_session(); }