Парсинг PowerShell
Цитата: N от 28.02.2024, 14:59Привет 🖐
Пытаюсь в проекте использовать powershell, но не получается использовать команду с переменными. Подскажите, как это можно осуществить.[spoiler title="Код который работает в powershell:"]
$adapterMemory = (Get-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*" -Name "HardwareInformation.qwMemorySize" -Exclude PSPath -ErrorAction SilentlyContinue) foreach ($adapter in $adapterMemory) { [PSCustomObject] @{ " "=[math]::round($adapter."HardwareInformation.qwMemorySize"/1GB)} }[/spoiler]
[spoiler title="Как это выглядит в проекте:"]
Process process = Process.Start(new ProcessStartInfo { FileName = "powershell", Arguments = @"/command $adapterMemory = (Get-ItemProperty -Path /""HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*/"" -Name /""HardwareInformation.qwMemorySize/"" -Exclude PSPath -ErrorAction SilentlyContinue) foreach ($adapter in $adapterMemory) {[PSCustomObject] @{' '=[math]::round($adapter./""HardwareInformation.qwMemorySize/""/1GB)}}", UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true }); label23.Text = process.StandardOutput.ReadToEnd();[/spoiler]
Привет 🖐
Пытаюсь в проекте использовать powershell, но не получается использовать команду с переменными. Подскажите, как это можно осуществить.
$adapterMemory = (Get-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*" -Name "HardwareInformation.qwMemorySize" -Exclude PSPath -ErrorAction SilentlyContinue)
foreach ($adapter in $adapterMemory) {
[PSCustomObject] @{
" "=[math]::round($adapter."HardwareInformation.qwMemorySize"/1GB)}
}
Process process = Process.Start(new ProcessStartInfo
{
FileName = "powershell",
Arguments = @"/command $adapterMemory = (Get-ItemProperty -Path /""HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*/"" -Name
/""HardwareInformation.qwMemorySize/"" -Exclude PSPath -ErrorAction SilentlyContinue)
foreach ($adapter in $adapterMemory) {[PSCustomObject] @{' '=[math]::round($adapter./""HardwareInformation.qwMemorySize/""/1GB)}}",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
});
label23.Text = process.StandardOutput.ReadToEnd();
Цитата: En32 от 26.03.2024, 17:44Цитата: N от 28.02.2024, 14:59Привет
Пытаюсь в проекте использовать powershell, но не получается использовать команду с переменными. Подскажите, как это можно осуществить.[spoiler title="Код который работает в powershell:"]
$adapterMemory = (Get-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*" -Name "HardwareInformation.qwMemorySize" -Exclude PSPath -ErrorAction SilentlyContinue)foreach ($adapter in $adapterMemory) {[PSCustomObject] @{" "=[math]::round($adapter."HardwareInformation.qwMemorySize"/1GB)}}$adapterMemory = (Get-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*" -Name "HardwareInformation.qwMemorySize" -Exclude PSPath -ErrorAction SilentlyContinue) foreach ($adapter in $adapterMemory) { [PSCustomObject] @{ " "=[math]::round($adapter."HardwareInformation.qwMemorySize"/1GB)} }$adapterMemory = (Get-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*" -Name "HardwareInformation.qwMemorySize" -Exclude PSPath -ErrorAction SilentlyContinue) foreach ($adapter in $adapterMemory) { [PSCustomObject] @{ " "=[math]::round($adapter."HardwareInformation.qwMemorySize"/1GB)} }[/spoiler]
[spoiler title="Как это выглядит в проекте:"]
Process process = Process.Start(new ProcessStartInfo{FileName = "powershell",Arguments = @"/command $adapterMemory = (Get-ItemProperty -Path /""HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*/"" -Name/""HardwareInformation.qwMemorySize/"" -Exclude PSPath -ErrorAction SilentlyContinue)foreach ($adapter in $adapterMemory) {[PSCustomObject] @{' '=[math]::round($adapter./""HardwareInformation.qwMemorySize/""/1GB)}}",UseShellExecute = false,CreateNoWindow = true,RedirectStandardOutput = true});label23.Text = process.StandardOutput.ReadToEnd();Process process = Process.Start(new ProcessStartInfo { FileName = "powershell", Arguments = @"/command $adapterMemory = (Get-ItemProperty -Path /""HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*/"" -Name /""HardwareInformation.qwMemorySize/"" -Exclude PSPath -ErrorAction SilentlyContinue) foreach ($adapter in $adapterMemory) {[PSCustomObject] @{' '=[math]::round($adapter./""HardwareInformation.qwMemorySize/""/1GB)}}", UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true }); label23.Text = process.StandardOutput.ReadToEnd();Process process = Process.Start(new ProcessStartInfo { FileName = "powershell", Arguments = @"/command $adapterMemory = (Get-ItemProperty -Path /""HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*/"" -Name /""HardwareInformation.qwMemorySize/"" -Exclude PSPath -ErrorAction SilentlyContinue) foreach ($adapter in $adapterMemory) {[PSCustomObject] @{' '=[math]::round($adapter./""HardwareInformation.qwMemorySize/""/1GB)}}", UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true }); label23.Text = process.StandardOutput.ReadToEnd();[/spoiler]
Привет, вот попробуй этот код
Process process = Process.Start(new ProcessStartInfo { FileName = "powershell", Arguments = "-Command \"$adapterMemory = Get-ItemProperty -Path 'HKLM:\\SYSTEM\\ControlSet001\\Control\\Class\\{4d36e968-e325-11ce-bfc1-08002be10318}\\0*' -Name 'HardwareInformation.qwMemorySize' -Exclude PSPath -ErrorAction SilentlyContinue; foreach ($adapter in $adapterMemory) { [PSCustomObject] @{'' = [math]::round($adapter.'HardwareInformation.qwMemorySize' / 1GB)} }\"", UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true }); label23.Text = process.StandardOutput.ReadToEnd();
Цитата: N от 28.02.2024, 14:59Привет
Пытаюсь в проекте использовать powershell, но не получается использовать команду с переменными. Подскажите, как это можно осуществить.Код который работает в powershell:$adapterMemory = (Get-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*" -Name "HardwareInformation.qwMemorySize" -Exclude PSPath -ErrorAction SilentlyContinue)foreach ($adapter in $adapterMemory) {[PSCustomObject] @{" "=[math]::round($adapter."HardwareInformation.qwMemorySize"/1GB)}}$adapterMemory = (Get-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*" -Name "HardwareInformation.qwMemorySize" -Exclude PSPath -ErrorAction SilentlyContinue) foreach ($adapter in $adapterMemory) { [PSCustomObject] @{ " "=[math]::round($adapter."HardwareInformation.qwMemorySize"/1GB)} }$adapterMemory = (Get-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*" -Name "HardwareInformation.qwMemorySize" -Exclude PSPath -ErrorAction SilentlyContinue) foreach ($adapter in $adapterMemory) { [PSCustomObject] @{ " "=[math]::round($adapter."HardwareInformation.qwMemorySize"/1GB)} }Как это выглядит в проекте:Process process = Process.Start(new ProcessStartInfo{FileName = "powershell",Arguments = @"/command $adapterMemory = (Get-ItemProperty -Path /""HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*/"" -Name/""HardwareInformation.qwMemorySize/"" -Exclude PSPath -ErrorAction SilentlyContinue)foreach ($adapter in $adapterMemory) {[PSCustomObject] @{' '=[math]::round($adapter./""HardwareInformation.qwMemorySize/""/1GB)}}",UseShellExecute = false,CreateNoWindow = true,RedirectStandardOutput = true});label23.Text = process.StandardOutput.ReadToEnd();Process process = Process.Start(new ProcessStartInfo { FileName = "powershell", Arguments = @"/command $adapterMemory = (Get-ItemProperty -Path /""HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*/"" -Name /""HardwareInformation.qwMemorySize/"" -Exclude PSPath -ErrorAction SilentlyContinue) foreach ($adapter in $adapterMemory) {[PSCustomObject] @{' '=[math]::round($adapter./""HardwareInformation.qwMemorySize/""/1GB)}}", UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true }); label23.Text = process.StandardOutput.ReadToEnd();Process process = Process.Start(new ProcessStartInfo { FileName = "powershell", Arguments = @"/command $adapterMemory = (Get-ItemProperty -Path /""HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*/"" -Name /""HardwareInformation.qwMemorySize/"" -Exclude PSPath -ErrorAction SilentlyContinue) foreach ($adapter in $adapterMemory) {[PSCustomObject] @{' '=[math]::round($adapter./""HardwareInformation.qwMemorySize/""/1GB)}}", UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true }); label23.Text = process.StandardOutput.ReadToEnd();
Привет, вот попробуй этот код
Process process = Process.Start(new ProcessStartInfo
{
FileName = "powershell",
Arguments = "-Command \"$adapterMemory = Get-ItemProperty -Path 'HKLM:\\SYSTEM\\ControlSet001\\Control\\Class\\{4d36e968-e325-11ce-bfc1-08002be10318}\\0*' -Name 'HardwareInformation.qwMemorySize' -Exclude PSPath -ErrorAction SilentlyContinue; foreach ($adapter in $adapterMemory) { [PSCustomObject] @{'' = [math]::round($adapter.'HardwareInformation.qwMemorySize' / 1GB)} }\"",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
});
label23.Text = process.StandardOutput.ReadToEnd();