How put quote with windows Processor(_Total)? - c++

When I process with powershell it works
(get-counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 5 |
select -ExpandProperty countersamples |
select -ExpandProperty cookedvalue |
Measure-Object -Average).average
Result: 1,75677
but when i translate this request with c++
string commande="get-counter -Counter \"\\Processor(_Total)\\% Processor Time\" -SampleInterval 300 -MaxSamples 3 | select -ExpandProperty countersamples | select -ExpandProperty cookedvalue | Measure-Object -Average).average";`
Result:
The term '_Total' is not recognized as the name of a cmdlet, function, script file, or operable program
It works when i put only with c++
string commande="get-counter"
Result:
Timestamp CounterSamples
--------- --------------
23/08/2019 11:30:33 \\win2008\network interface(realtek rtl8139c+ fast ethernet nic _4)\bytes total/sec : 0
I try
//Processor(_Total)//% Processor or
\Processor(_Total)\% Processor or
///Processor(_Total)///% Processor
Nothing works Do you know why? thanks

Related

Is there a way to extract only the value from "free" field of Get-PSDrive?

I'm trying to take the value of free space from a drive, this is necessary to do an automatict procedure in a database server.
I got this script:
$query_drive_mount_point = #"
select distinct
convert(varchar(512), b.volume_mount_point) as [volume],
convert(varchar(512), b.logical_volume_name) as [logical_volume]
from sys.master_files as [a]
CROSS APPLY sys.dm_os_volume_stats(a.database_id, a.[file_id]) as [b]
"#
[regex]$get_drive = '\w\:\\'
[regex]$get_drive_name = '\w'
[regex]$get_drive_space = '\d'
$mount_point = Invoke-Sqlcmd -ServerInstance "$server_ip\$sql_engine,$sql_port" -Username "$sql_user" -Password "$sql_password" -Database Master -Query "$query_drive_mount_point"
$get_disk = $get_drive.Matches($mount_point) | Foreach-Object {$_.Value}
$get_disk_name = $get_drive_name.Matches($get_disk) | Foreach-Object {$_.Value}
$size_bytes_string = Get-PSDrive $get_disk_name | Select-Object -Property Free
[int]$size_bytes = $get_drive_space.Matches($size_bytes_string) | ForEach-Object {$_.Value}
$size_giga = ( ( ( $size_bytes )/1024 )/1024 )/1024
This code runs without problem until this line:
[int]$size_bytes = $get_drive_space.Matches($size_bytes_string) | ForEach-Object {$_.Value}
It throws this error:
There was not found overload for "Matches" and args numbers is "1".
En línea: 1 Carácter: 1
+ $size_bytes = $get_drive_space.Matches($size_bytes_string) | ForEach- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
The last error is a traduction made by me, the os is in spanish.
Again, the objective is to store only the free space value.
You need to select the value from the property you need, so this line:
$size_bytes_string = Get-PSDrive $get_disk_name | Select-Object -Property Free to
Should be changed to the following:
$size_bytes_string = Get-PSDrive $get_disk_name | Select-Object -ExpandProperty Free
Alternatively you can format it as follows:
($size_bytes_string = Get-PSDrive $get_disk_name).Free
If you have PS version 5:
PS C:\> (($PSVersionTable).PSVersion)
Major Minor Build Revision
----- ----- ----- --------
5 1 18362 145
if not version 5, try to import the storage module.
You can get this information easier by using the below commandlet:
Get-disk # the command name
Get-Command -Module storage -Verb get -Noun disk # module
onliner code to select the size of the first hdd (disk 0):
[math]::Round((Get-Disk -Number 0).Size /1GB)
- Edited :
=========================================================================
if you load this assembly, you can get all the information you need,
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$sql = New-Object ('Microsoft.SqlServer.Management.Smo.Server')
You can run this commandlet to find what information you can get :
(($sql | gm) | measure).count
For example :
write-host $dbs.Parent
$dbs=$s.Databases
I believe you need a property called filegroup to get information about ldf&mdf files.

PowerCli - cannot filter Virtual Machines by VMHost property

I'm experimenting for the first time PowerCli on my VSphere environment.
I'm trying the Get-Vm filtering the results in this way and it's working fine:
Get-Vm | where MemoryGB -eq "8"
but if I try the same syntax, filtering by VMHost property, I don't get any result:
Get-Vm | where VMHost -eq "10.0.0.30"
But I have a lot of machines on the host 10.0.0.30, why it's not working?
I can see it if I use this syntax that filters the text output in the end:
Get-Vm | select name,vmhost | findstr -i .30
what I'm doing wrong?
thanks
The VMHost property that you're referring to is actually a VMHost object, so you may have to filter something like Get-VM | where {$_.VMHost.Name -eq '10.0.0.30'} in order to do a string vs. string comparison.
Get-VMHost -Name "10.0.0.30" | Get-VM
VMHost has the property "Name".
So you can pass the name(ip) of VMHost and get the list of all vms on the hosted ip.
Link to cmndlet explanation: https://vdc-repo.vmware.com/vmwb-repository/dcr-public/6fb85470-f6ca-4341-858d-12ffd94d975e/4bee17f3-579b-474e-b51c-898e38cc0abb/doc/Get-VMHost.html#:~:text=Suspend%2DVMHost-,This%20cmdlet%20retrieves%20the%20hosts%20on%20a%20vCenter%20Server%20system,one%2C%20use%20the%20Server%20parameter.

Keep words starting with character/letter in Pandas | Python

I'm not sure how to do this in a dataframe context
I have the table below here with text information
TEXT |
-------------------------------------------|
"Get some new #turbo #stacks today!" |
"Is it one or three? #phone" |
"Mayhaps it be three afterall..." |
"So many new issues with phone... #iphone" |
And I want to edit it down to where only the words with a '#' symbol are kept, like in the result below.
TEXT |
-----------------|
"#turbo #stacks" |
"#phone" |
"" |
"#iphone" |
In some cases, I'd also like to know if it's possible to eliminate the rows that are empty by checking for NaN as true or if you run a different kind of condition to get this result:
TEXT |
-----------------|
"#turbo #stacks" |
"#phone" |
"#iphone" |
Python 2.7 and pandas for this.
You could try using regex and extractall:
df.TEXT.str.extractall('(#\w+)').groupby(level=0)[0].apply(' '.join)
Output:
0 #turbo #stacks
1 #phone
3 #iphone
Name: 0, dtype: object

How to take the output of Sys.command as string in OCaml?

In OCaml, I have this piece of code:
let s =Sys.command ("minisat test.txt | grep 'SATIS' ");;
I want to take the output of minisat test.txt | grep "SATIS" , which is SATISFIABLE/UNSATISFIABLE to the string s.
I am getting the following output:
SATISFIABLE
val s : int = 0
So, how can I make the output of this command to a string.
Also, is it possible to even import time?
This is the output I get when I try minisat test.txt in terminal
WARNING: for repeatability, setting FPU to use double precision
============================[ Problem Statistics ]=============================
| |
| Number of variables: 5 |
| Number of clauses: 3 |
| Parse time: 0.00 s |
| Eliminated clauses: 0.00 Mb |
| Simplification time: 0.00 s |
| |
============================[ Search Statistics ]==============================
| Conflicts | ORIGINAL | LEARNT | Progress |
| | Vars Clauses Literals | Limit Clauses Lit/Cl | |
===============================================================================
===============================================================================
restarts : 1
conflicts : 0 (-nan /sec)
decisions : 1 (0.00 % random) (inf /sec)
propagations : 0 (-nan /sec)
conflict literals : 0 (-nan % deleted)
Memory used : 8.00 MB
CPU time : 0 s
SATISFIABLE
If you use just Sys, you can't.
However, you can create a temporary file (see the Filename module's documentation here) and tell the command to output in it:
let string_of_command () =
let tmp_file = Filename.temp_file "" ".txt" in
let _ = Sys.command ## "minisat test.txt | grep 'SATIS' >" ^ tmp_file in
let chan = open_in tmp_file in
let s = input_line chan in
close_in chan;
s
Note that this function is drafty: you have to properly handle potential errors happening. Anyway, you can adapt it to your needs I guess.
You can avoid the temporary file trick by using the Unix library or more advanced libraries.
You have to use Unix.open_process_in or Unix.create_process, if you want to capture the output.
Or better use a higher level wrapper like 'shell' (from ocamlnet):
http://projects.camlcity.org/projects/dl/ocamlnet-4.0.2/doc/html-main/Shell_intro.html
But I wouldn't pipe it to grep (not portable). Parse the output with your favorite regex library inside OCAML.

How to group and show multiple directory names with Powershell Get-ChildItem

I would like to pass multiple directories, then get a count of how many files were created yesterday in each directory.
This is what I have cobbled together so far:
$DirNames = #('d:\Work\Test1','d:\Work\Test2')
Get-ChildItem $DirNames | Where-Object { $_.CreationTime -ge (get-date).addDays(-1) } |
Group {$_.LastWriteTime.ToString("yyyy-MM-dd")} | Sort Name -Desc |
Format-Table Name,Count -auto
Current Output:
Name Count
---- -----
2014-03-25 4
It works fine for one directory, but I'm get confused how to show the the directory name in the output listing. The above count is for both directories, what I would like to see is:
Desired Output:
Directory Date Count
------------ ---------- -----
D:\Work\Test1 2014-03-25 2
D:\Work\Test2 2014-03-25 2
try this:
ls $env:temp| group {$_.lastwritetime.tostring('yyyy-MM-dd')} |
ft name,count,#{
'n' = 'Directory';
'e' = { $_ |select -expa group | select -first 1 -expa psparentpath | Convert-Path }
}
or you can use new pipelinevariable parameter with version 4