powershell-2.0

Insert background color in a row

喜你入骨 提交于 2020-01-06 07:26:02
问题 I have a file input.txt having below content: ENVIRONMENT SERVER APPLICATION STATUS Test Windows abcd Success Dev Linux wxyz Failed Prod Windows pqrs Success Test Ubuntu efgh NoValue And using below script I use to convert this file's content into tabular format and sending mail to people. $smtpServer = "abc.com" $smtpFrom = "don'treply@abc.com" $smtpTo = "sunny@xyz.com" $messageSubject = "bla_bla_bla" $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto $message.Subject =

Insert background color in a row

梦想与她 提交于 2020-01-06 07:24:10
问题 I have a file input.txt having below content: ENVIRONMENT SERVER APPLICATION STATUS Test Windows abcd Success Dev Linux wxyz Failed Prod Windows pqrs Success Test Ubuntu efgh NoValue And using below script I use to convert this file's content into tabular format and sending mail to people. $smtpServer = "abc.com" $smtpFrom = "don'treply@abc.com" $smtpTo = "sunny@xyz.com" $messageSubject = "bla_bla_bla" $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto $message.Subject =

Execute Powershell script using java

江枫思渺然 提交于 2020-01-05 05:56:21
问题 I want to execute powershell cmdlets using java . Is there any way i can implement this? I tried using Runtime and exec commands but output window hangs in between. 回答1: It's easier to use the newer ProcessBuilder class. Runtime.exec has several pitfalls that you need to remember, in order for things to work correctly. For example you need to make sure that the input and outputstreams to the process are handled correctly. I suggest you google for an example on using ProcessBuilder. 来源: https:

Powershell - Getting Last Log Off Date and Time of a computer

佐手、 提交于 2020-01-05 01:23:26
问题 I'm not very good with powershell so here goes. I'm having trouble with displaying the last logoff Date and time of a computer. So far I have: $Logoff = GWMI -Comp $strComputer -Cl Win32_NetworkLoginProfile | foreach-object {Write-Host "Last Logoff: "$_.Lastlogoff} This gives me a list of I guess logoff dates and time. This seemed ok so I tried to convert the output using ConvertToDateTime to get a readable date/time but I don't now how to get it to work when a selection of datetimes are sent

Create a 7z Archive for files created by date using Powershell

久未见 提交于 2020-01-04 06:08:22
问题 I have directory where various daily files gets copied. I need to write a power shell script which will create 7z archive based on groups of file create date.The name of the archive includes those group dates. Example Below FileA 06/23/11 FileB 06/23/11 FileC 06/24/11 Script should create 2 archives 062311.7z contains FileA, FileB 062411.7z contains FileC Thanks in advance --------- Now I have to develop a compression routine which can take care of daily/Weekly/ Monthly durations 回答1: The

Create a 7z Archive for files created by date using Powershell

时光怂恿深爱的人放手 提交于 2020-01-04 06:08:19
问题 I have directory where various daily files gets copied. I need to write a power shell script which will create 7z archive based on groups of file create date.The name of the archive includes those group dates. Example Below FileA 06/23/11 FileB 06/23/11 FileC 06/24/11 Script should create 2 archives 062311.7z contains FileA, FileB 062411.7z contains FileC Thanks in advance --------- Now I have to develop a compression routine which can take care of daily/Weekly/ Monthly durations 回答1: The

Import-CSV GroupBy Sum

爷,独闯天下 提交于 2020-01-04 02:38:11
问题 I am stuck trying to get meaningful output from a csv file. The raw input looks like this. Col1,Col2,Col3,Col4 a,2,b,z a,2,c,x a,1,d,y e,1,f,s e,2,g,t h,1,k,r I am trying to achieve an output of below (exclude col4) and export to a file for further reporting using PowerShell 2. a 5 b,c,d e 3 f,g h 1 k Code from my script function is: $data = import-csv $filename.csv | Select-Object -property Col1,Col2,Col3 $view | Group Col1 | ` select Name,@{ Name="Col2Sum"; Expression = { [math]::round(($_

How can I compare two arrays, removing similar items, without iterating through the whole array?

喜欢而已 提交于 2020-01-03 19:09:30
问题 Is it possible to compare two arrays and remove the values that are equal (if they are at the same index), without iterating through both arrays? Here is an example: $array1 = @(1,2,3,4,5,6,7,23,44) $array2 = @(1,1,3,4,5,7,6,23,45) $array3 = $sudo_compare_function $array1 $array2 where $array3 would now contain an array of indexes where $array2 is different from $array1 array: (1,5,6,8) If there isn't something like this, is there an easy way to do something similar without iterating through

Run a powershell script in batch file as administrator

丶灬走出姿态 提交于 2020-01-03 17:22:27
问题 I have a powershell script. To run this sript, I have written a batch file. Here is code of batch file: :: psscript.bat set psscript='%CD%\Hotfix-Automation-Installer.ps1' echo Running PowerShell Script: %psscript% %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe ^&%psscript% %* When I double-click on batch file, I want my script Hotfix-Automation-Installer.ps1 to be run as an administrator. How I can run this script as administrator? 回答1: Read Matt's article on this link: How can

Stop-Service Cmdlet not able to open service that exists

陌路散爱 提交于 2020-01-03 06:59:19
问题 I am trying to write a PowerShell script to stop services on the local machine. When I run the get-service cmdlet it works as expected. When I use the stop-service cmdlet, It errors stating that no service exists with the name I specify. If this was true surely the get-service cmdlet would throw the same error. Get-Service "Service 1" # Returns Service and status Stop-Service "Service 1" # Throws error below: Stop-Service : Service 'Service 1' cannot be stopped due to the following error: