Posted in
Windows Powershell |
No Comment | 1,613 views | 01/08/2012 13:42
C# ile ilgili kendime bazı notlarım:
String Builder:
StringBuilder SB = new StringBuilder();
SB.AppendFormat("Get-VM -Id {0} | Set-VM ", Id); |
StringBuilder SB = new StringBuilder();
SB.AppendFormat("Get-VM -Id {0} | Set-VM ", Id);
If / Else yazma:
if (ProcessorCount > 0)
SB.AppendFormat("-ProcessorCount {0} ", ProcessorCount); |
if (ProcessorCount > 0)
SB.AppendFormat("-ProcessorCount {0} ", ProcessorCount);
Or kullanımı ve eğer null ise:
if (string.IsNullOrEmpty(MemoryStartupBytes) || string.IsNullOrEmpty(MemoryStartupBytes))
sadsadsadasdada
else if (bla bla)
sdsdsadsadsada
else |
if (string.IsNullOrEmpty(MemoryStartupBytes) || string.IsNullOrEmpty(MemoryStartupBytes))
sadsadsadasdada
else if (bla bla)
sdsdsadsadsada
else
Class yaratma:
class NewVMResult
{
public string VMId { get; set; }
public string VMName { get; set; }
} |
class NewVMResult
{
public string VMId { get; set; }
public string VMName { get; set; }
}
Powershell çalıştırma:
static NewVMResult NewVM(string Name, string Path)
{
IEnumerable<dynamic> PSResult = PSShell.AddCommand("New-VM")
.AddParameter("Name", Name)
.AddParameter("Path", Path)
.Invoke();
var PSObject = PSResult.FirstOrDefault();
return new NewVMResult() { VMId = PSObject.Id.ToString(), VMName = PSObject.VMName };
} |
static NewVMResult NewVM(string Name, string Path)
{
IEnumerable<dynamic> PSResult = PSShell.AddCommand("New-VM")
.AddParameter("Name", Name)
.AddParameter("Path", Path)
.Invoke();
var PSObject = PSResult.FirstOrDefault();
return new NewVMResult() { VMId = PSObject.Id.ToString(), VMName = PSObject.VMName };
}
C# yeni başladığım için kendime not düştüm :)