powershell-1.0

Measure-Object -sum all counterSamples from continuous get-counter

。_饼干妹妹 提交于 2020-01-23 18:54:20
问题 I am trying to write a PowerShell script that will continuously poll a performance counter every N seconds then sum the values returned by the counter. My end goal is to have results for a dozen or so counters get rolled up and shipped off to a Graphite server for monitoring and reporting. so far this is what I have cobbled together for a particular counter, i'm just not sure how to get a couple of things in the land of PowerShell magic voodoo. I can't figure out how to get the Job ID as an

PowerShell generic collections

谁都会走 提交于 2019-12-28 02:32:09
问题 I have been pushing into the .NET framework in PowerShell, and I have hit something that I don't understand. This works fine: $foo = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]" $foo.Add("FOO", "BAR") $foo Key Value --- ----- FOO BAR This however does not: $bar = New-Object "System.Collections.Generic.SortedDictionary``2[System.String,System.String]" New-Object : Cannot find type [System.Collections.Generic.SortedDictionary`2[System.String,System.String]]

Using PowerShell with .NET 3.5 runtime/libraries

夙愿已清 提交于 2019-12-22 05:02:37
问题 Is it possible to run PowerShell 1.0 (or 2.0 CTP) backed by the 3.5 runtime instead of 2.0? We're building a .NET 3.5 solution, and I'd still like to use PowerShell as our scripting engine for scheduled tasks, etc. I don't need LINQ syntax or anything, just the 3.5 libraries and runtime. FOLLOWUP: thank you for the reply about dynamically loading assemblies. But let me clarify my question: is there any way to run PowerShell so that the 3.5 libraries run by default? So that if I enter New

Write-Host => Export to a file

会有一股神秘感。 提交于 2019-12-19 05:11:07
问题 I have got a script with some commands such as Write-Host "Server1" . How can I export it to a file? When I tried with script > export.txt it didn't work. 回答1: Write-Host redirects the output only to the console. You can use Write-Output and redirect to a file ( > export.txt or pipe to Out-File export.txt ) In the extreme case when you absolutely need to redirect all output from a script, take a look to this cmdlet: Start-Transcript Get-Help Start-Transcript -full 回答2: In PowerShell script >

PowerShell: how to count number of rows in csv file?

 ̄綄美尐妖づ 提交于 2019-12-17 18:19:12
问题 How can I count the number of rows in a csv file using powershell? I tried something like Get-Content -length "C:\Directory\file.csv" or (Get-Content).length "C:\Directory\file.csv" but these result an error. 回答1: Pipe it to the Measure-Object cmdlet Import-Csv C:\Directory\file.csv | Measure-Object 回答2: Get-Content and Measure-Object are fine for small files, but both are super inefficient with memory. I had real problems with large files. When counting rows in a 1GB file using either method

Capturing Powershell output in C# after Pipeline.Invoke throws

冷暖自知 提交于 2019-12-17 12:19:09
问题 I'm running a Powershell test script from a C# application. The script can fail due to a bad cmdlet which causes pipe.Invoke() to throw an exception. I'm able to capture all the information I need about the exception, but I'd like to be able to display the script's output up to that point. I haven't had any luck since results appears to be null when an exception is thrown. Is there something I'm missing? Thanks! m_Runspace = RunspaceFactory.CreateRunspace(); m_Runspace.Open(); Pipeline pipe =

Help me use powershell and bcp to load CSV into SQL Server

天大地大妈咪最大 提交于 2019-12-12 03:54:48
问题 I'm using bcp to load a table from a CSV exported from another table by someone else far far away, and have run into some issues. My original two problems: one exported field is an int that needs to end up in a varchar field, and another field needs to be populated with a static string. Well, the first is no big deal, and Chad's answer led me to the @{n='Col3';e={'ABC'}} syntax. But i'm stumbling around several issues getting the data loaded correctly. Sometimes a value might have no spaces,

How to remove double quotes on specific column from CSV file using Powershell script

吃可爱长大的小学妹 提交于 2019-12-11 06:27:24
问题 "ID","Full Name","Age" "1","Jone Micale","25" Here a sample from a CSV file that I created, and now I want to remove double quotes from only the ID and Age column value. I tried different ways but I don't want to create a new file out of it. I just want to update the file with changes using PowerShell v1 . 回答1: Export-Csv will always put all fields in double quotes, so you have to remove the undesired quotes the hard way. Something like this might work: $csv = 'C:\path\to\your.csv' (Get

Sending Formatted HTML email

纵饮孤独 提交于 2019-12-11 05:37:28
问题 I have a text file output.txt which has following content: OPERATINGSYSTEM PROJECTSERVER1 PROJECTSERVER2 Windows 1.36 4.42 Linux12 2.78 5.76 MacOS 3.45 6.39 Ubuntu 4.12 0.00 Android 0.00 3.46 FreePhysicalMemory 30.12 31.65 TotalVisibleMemorySize 48.00 48.00 CPULoadPercentage 2 4 I want to send content of output.txt in a email as a body in Formatted HTML table look in Windows server 2008 R2 . I am trying with below code, but its not working for me..where am I mistaking below ? $smtpServer =

Size of the sorted file is double than original file in powershell

两盒软妹~` 提交于 2019-12-10 13:05:49
问题 I have a powershell script, that reads file content, sorts it and writes output to new file. Following is the script: get-content $inputFile | sort > $sortedFile The output in file is sorted properly, but the output file ($sortedFile) is double larger than input file ($inputFile). Note: There are no duplicate or extra line in output file. Any help or ideas regarding this will be helpful. 回答1: Most likely the input file is ascii encoding while the default output using redirection is unicode