powershell-2.0

Adding logic to array in powershell

拟墨画扇 提交于 2019-12-25 01:05:48
问题 I have imported a CSV file and created an array out of the data. I need to split off the domain names which used split, however some of the names are IP addresses, so it is split those as well. How can I add some logic to do my normal split? But if it's a number like a IP address, ignore and print it. Below is my sample data, the "Client Name' is what I'm trying to work with. $NewCSV = $a | ForEach-Object { $Record = @{ 'Client Name' = $_."Name".Split('.')[0] 'Policy Name' = $_.

How to get the SolutionPath in a PowerShell Post-built script for TFS2013?

喜夏-厌秋 提交于 2019-12-24 21:43:40
问题 In a TFS2013 build, in the Post-build path of the build definition, I call a PowerShell script which need to get the path of the Solution built just before. But the SolutionPath varibale is not provided in the Environment Variables and we can't pass this variable in the Post-Build Arguments in the Definition Build. Have you a tip for that without modify the build template ? Thank you. 回答1: The reason there isn't a SolutionPath variable in the tfbuild , in my opinion, is because there aren't

PowerShell WhereObjectCommand from C#

点点圈 提交于 2019-12-24 20:06:28
问题 I'm trying to call the following PS script from C#: Get-MailboxDatabase -IncludePreExchange2007 -Status | Where-Object {$_.Server -eq 'myserver'} I have managed to execute the first part before the pipe using this code: public void Test() { using (Pipeline pipeline = _runspace.CreatePipeline()) { var cmd1 = new Command("Get-MailboxDatabase"); cmd1.Parameters.Add("IncludePreExchange2007"); cmd1.Parameters.Add("Status"); var cmd2 = new Command("Where-Object"); //how do I script {$_.Server -eq

Converting batch file to powershell with special characters in path

筅森魡賤 提交于 2019-12-24 19:43:06
问题 I'm having a hard time to write a simple batch file as powershell script. Consider this folder structure. Note the directory with the cool [1] in it... exiftool.exe Is a command utility to (for example) extract pictures from embedded MP3 tags. I uploaded its help if you need more info. oldscript.cmd exiftool -picture -b input.mp3 > output.jpg This line is the one to write in powershell. I found the syntax in a forum post from the author -picture stands for the tag to extract and -b stands for

powershell - execute cmdlet remotely with php

…衆ロ難τιáo~ 提交于 2019-12-24 17:50:14
问题 I need to get status of service for simple monitoring tool. There is no problem to get status locally, but when I try to get status of service on remote computer like this: <?php $output = shell_exec('powershell.exe "(get-service Webclient -computername server1).Status"'); echo "Webclient: $output "; ?> I get nothing. WinRM on server1 is set to receive requests and to allow remote access. The Get-Service on remote server1 works fine in console window. This works (locally): <?php $output =

Powershell Backgroundworker

荒凉一梦 提交于 2019-12-24 17:24:35
问题 Can anyone give me an example of how to use BackgroundWorker in Powershell? I want to write something so when a new tab is selected in my Powershell GUI app, it will switch to the tab with a "please wait" message displayed, then run some checks in a BackgroundWorker thread, and then update. Is this possible in Powershell? All the Googling I've done points to c# or VB.Net. Cheers, Ben 回答1: If the background thread is going to use a PowerShell pipeline to do its work, then I would avoid using

How to start/stop a service on a remote server using PowerShell - Windows 2008 & prompt for credentials?

旧时模样 提交于 2019-12-24 16:39:50
问题 I am trying to create a PowerShell script that will start/stop services on a remote computer, but prompt the user for all the values. I know the account that will be used; I just need to prompt the user for the password. This is for Tomcat instances. The problem is the Tomcat service isn't always named the same on different servers (tomcat6, tomcat7). I need to be able to store the password encrypted and prompt to stop or start. Here is what I have so far. Any thoughts? I am not sure if I

capture data from ini file PowerShell

旧街凉风 提交于 2019-12-24 14:25:58
问题 I would like to parse an ini file and capture data from a Section. Basically I am trying to capture the version of an AV installed on 1000+ Servers. the ini file contains "Program_Version". This variable contains the version no. If I search using Program_Version=, I directly find the phrase after the "=" sign it contains the version no. Like 8.0, 10.6 etc Can some one please guide me on how to achieve this? Thanks 回答1: Here is the function I use : function Parse-IniFile { [CmdletBinding()]

Add a header to a Word document?

风流意气都作罢 提交于 2019-12-24 12:18:45
问题 I would like to add a custom header to a .doc file using PowerShell (I mean the actual Header, not a heading). This SHOULD work: $Word=New-Object -ComObject "Word.Application" $wdSeekPrimaryHeader = 1 $Doc=$Word.Documents.Open("C:\test.doc") $Selection=$Word.Selection $Doc.ActiveWindow.ActivePane.View.SeekView=$wdSeekPrimaryHeader $Selection.TypeText("Text") $doc.close([ref]$Word.WdSaveOptions.wdDoNotSaveChanges) $word.quit() But it doesn't. It actually does nothing that I can tell. Any ideas

Powershell: Replace special characters

扶醉桌前 提交于 2019-12-24 11:46:00
问题 Is there an easy way to replace special characters, like æøåéü etc., from a string in a Powershell script? Making the string web-safe. 回答1: Ok, with additional explanation, I guess solution would depend on a scale. If that's user input and in "normal" use it would be short, that maybe something like that: $Replacer = @{ Å = 'aa' é = 'e' } $string_to_fix = 'æøåéüÅ' $pattern = "[$(-join $Replacer.Keys)]" [regex]::Replace($string_to_fix, $pattern, { $Replacer[$args[0].value] }) Obviously, you