Search Results

Search found 1743 results on 70 pages for 'powershell'.

Page 22/70 | < Previous Page | 18 19 20 21 22 23 24 25 26 27 28 29  | Next Page >

  • Muliple Foreground Colors in Powershell in One Command.

    - by Mark Tomlin
    I want to output many different foreground colors with one statement. PS C:\> Write-Host "Red" -ForegroundColor Red Red This output is red. PS C:\> Write-Host "Blue" -ForegroundColor Blue Blue This output is blue. PS C:\> Write-Host "Red", "Blue" -ForegroundColor Red, Blue Red Blue This output is magenta, but I want the color to be Red for the word red, and blue for the word blue via the one command. How can I do that?

    Read the article

  • Checking only "Automatic" services with powershell.

    - by Lee
    I've seen lots of scripts out there for manually stopping/starting services in a list, but how can I generate that list programatically of -just- the automatic services. I want to script some reboots, and am looking for a way to verify that everything did in fact start up correctly for any services that were supposed to.

    Read the article

  • Powershell's import-clixml from string

    - by rocku
    Is there any way to run import-clixml cmdlet on a string or xml object? It requires a file path as input to produce ps objects and can't get input from an xml object. Since there is convertto-xml cmdlet which serializes ps object into xml object, why isn't there a convertfrom-xml, which would do the opposite? I am aware of System.Xml.Serialization.XmlSerializer class which would do just that, however I would like to stick with cmdlets to do this. Is there any way to do this with cmdlets (probably just with import-clixml), without creating temporary files?

    Read the article

  • PowerShell copy fails without warning

    - by boink
    Howdy, am trying to copy a file from IE cache to somewhere else. This works on w7, but not Vista Ultimate. In short: copy-item $f -Destination "$targetDir" -force (I also tried $f.fullname) The full script: $targetDir = "C:\temp" $ieCache=(get-itemproperty "hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders").cache $minSize = 5mb Write-Host "minSize:" $minSize Add-Content -Encoding Unicode -Path $targetDir"\log.txt" -Value (get-Date) Set-Location $ieCache #\Low\Content.IE5 for protected mode #\content.ie5 for unprotected $a = Get-Location foreach ($f in (get-childitem -Recurse -Force -Exclude *.dat, *.tmp | where {$_.length -gt $minSize}) ) { Write-Host (get-Date) $f.Name $f.length Add-Content -Encoding Unicode -Path $targetDir"\log.txt" -Value $f.name, $f.length copy-item $f -Destination "$targetDir" -force } End of wisdom. Please help!

    Read the article

  • powershell capture call stack after an error is thrown

    - by davidhayes
    Hi, I want to do something like this... try { # Something in this function throws an exception Backup-Server ... }catch { # Capture stack trace of where the error was thrown from Log-Error $error } Ideally I'd like to capture arguments to the function and line numbers etc. (like you see in get-pscallstack) Any ideas how to achieve this? Dave

    Read the article

  • Get last element of pipeline in powershell

    - by dozacinc
    Hi, This might be weird, but stay with me. I want to get only the last element of a piped result to be assigned to a varaiable. I know how I would do this in "regular" code of course, but since this must be a one-liner. More specifically, I'm interested in getting the file extension when getting the result from an FTP request ListDirectoryDetails. Since this is done within a string expansion, I can't figure out the proper code. Currently I'm getting the last 3 hars, but that is real nasty. New-Object PSObject -Property @{ LastWriteTime = [DateTime]::ParseExact($tempDate, "MMM dd HH:mm",[System.Globalization.CultureInfo]::InvariantCulture) Type = $(if([int]$tempSize -eq 0) { "Directory" } else { $tempName.SubString($tempName.length-3,3) }) Name = $tempName Size = [int]$tempSize } My idea was doing something similar to $tempName.Split(".") | ? {$_ -eq $input[$input.Length-1]} that is, iterate over all, but only take out where the element I'm looking at is the last one of the input-array. What am I missing ? Fire at will /M

    Read the article

  • Powershell Select-Object from array not working

    - by Andrew
    I am trying to seperate values in an array so i can pass them to another function. Am using the select-Object function within a for loop to go through each line and separate the timestamp and value fields. However, it doesn't matter what i do the below code only displays the first select-object variable for each line. The second select-object command doesn't seem to work as my output is a blank line for each of the 6 rows. Any ideas on how to get both values $ReportData = $SystemStats.get_performance_graph_csv_statistics( (,$Query) ) ### Allocate a new encoder and turn the byte array into a string $ASCII = New-Object -TypeName System.Text.ASCIIEncoding $csvdata = $ASCII.GetString($ReportData[0].statistic_data) $csv2 = convertFrom-CSV $csvdata $newarray = $csv2 | Where-Object {$_.utilization -ne "0.0000000000e+00" -and $_.utilization -ne "nan" } for ( $n = 0; $n -lt $newarray.Length; $n++) { $nTime = $newarray[$n] $nUtil = $newarray[$n] $util = $nUtil | select-object Utilization $util $tstamp = $nTime | select-object timestamp $tstamp }

    Read the article

  • Powershell - Using variables in -Include filter

    - by TheD
    (again!) My final question for the night. I have a function which uses the Get-ChildItem to work out the newest file within a folder. The reason being I need to find the latest incremental backup in a folder and script an EXE to mount it. However, within this same folder there are multiple backup chains for all different servers: i.e. SERVER1_C_VOL_b001_i015.spi SERVER2_D_VOL_b001_i189.spi SERVER1_C_VOL_b002_i091.spi SERVER1_E_VOL_b002_i891.spi (this is the newest file created) I want only to look at SERVER1, look at only the C_VOL and look at only b001 - nothing else. I have all these seperate components: the drive letter, the Server Name, the b00X number stored in array. How then can I go and use the Get-ChildItem with the -Include filter to only look at: .spi SERVER1 C_VOL b001 Given I have all of these separate components in an array taken from a text file: Get-Content .\PostBackupCheck-TextFile.txt | Select-Object -First $i { $a = $_ -split ' ' ; $locationArray += "$($a[0]):\$($a[1])\$($a[2])" ; $imageArray += "$($a[2])_$($a[3])_VOL_b00$($a[4])_i$($a[5]).spi" } I then go onto try and filter then and then get stuck: $latestIncremental = Get-ChildItem -Path ${shadowProtectDataLocation}\*.* -Include *.spi | Sort-Object LastAccessTime -Descending | Select-Object -First 1 I have the .spi filtered, but how can I also just include the C (for volume), the number for the b00x and the server name. Thanks!

    Read the article

  • stoppin pipeline - POwershell

    - by laertejuniordba
    Hi all I am using New-Object System.Management.Automation.PipelineStoppedException To stop the pipeline OK..works.. But how Can I test in the next cmdlet if was stopped ? Foo1 | foo2 | foo3 Stop in foo1, but goes to foo2. I want to test if was stopped in foo1 to stop too in each function function foo1 { process { try { #do } catch { New-Object System.Management.Automation.PipelineStoppedException } } and still going to the next cmdlet, as stopped by error I want to stop in each next cmdlets..:) Thanks !!!

    Read the article

  • Optimizing simple search script in PowerShell

    - by cc0
    I need to create a script to search through just below a million files of text, code, etc. to find matches and then output all hits on a particular string pattern to a CSV file. So far I made this; $location = 'C:\Work*' $arr = "foo", "bar" #Where "foo" and "bar" are string patterns I want to search for (separately) for($i=0;$i -lt $arr.length; $i++) { Get-ChildItem $location -recurse | select-string -pattern $($arr[$i]) | select-object Path | Export-Csv "C:\Work\Results\$($arr[$i]).txt" } This returns to me a CSV file named "foo.txt" with a list of all files with the word "foo" in it, and a file named "bar.txt" with a list of all files containing the word "bar". Is there any way anyone can think of to optimize this script to make it work faster? Or ideas on how to make an entirely different, but equivalent script that just works faster? All input appreciated!

    Read the article

  • Powershell GUI: Adding multiple instances of .tooltipseperate to menu

    - by obious
    So, I'm having a problem whereby for some reason I can only add one instance of a .tooltipseperator to a drop down menu. E.g. I have to create a new .tooltipseperator if I want to add another to a different menu list. I have this: $seperator = new-object System.Windows.Forms.Toolstripseparator $seperator1 = new-object System.Windows.Forms.Toolstripseparator which correlates to this: [Void]$packages_menu_bar.DropDownItems.Add($seperator1) [Void]$packages_menu_bar.DropDownItems.Add($Remove_from_AD) [Void]$process.DropDownItems.Add($Kill_process) [Void]$process.DropDownItems.Add($seperator) My question is this: how can I add the same instance on a .tooltipseperater to different menu items? Some sort of array? Thanks

    Read the article

  • Powershell: Writing errors and ouput to a text file and Console

    - by smaclell
    I am trying to write the entire output (errors included) of an executing script to the console and a file at the same time. I have tried several different options .\MyScript.ps1 | tee -filePath C:\results.txt # only the output to the file .\MyScript.ps1 2> C:\results.txt # only the errors to the file and not the console .\MyScript.ps1 > C:\results.txt # only the output to the file and not the console My hope was that I could use the file to review the output/errors Any help would be greatly appreciated.

    Read the article

  • Join two results in Powershell

    - by Hinek
    I've got two CMDlets that return lists of objects. One returns objects of the type SPSolution, which contains the property Id, the other returns objects of the type SPFeature with a property SolutionId. Now I want to join/merge this data something like this: $f = Get-Feature $s = Get-Solution $result = <JOIN> $f $s <ON> $f.SolutionId = $s.Id <SELECT> FeatureName = $f.DisplayName, SolutionName = $s.Name

    Read the article

  • Find multiple line spanning text and replace using Powershell

    - by MrGrant
    Hello, I am using a regular expression search to match up and replace some text. The text can span multiple lines (may or may not have line breaks). Currently I have this: $regex = "\<\?php eval.*?\>" Get-ChildItem -exclude *.bak | Where-Object {$_.Attributes -ne "Directory"} |ForEach-Object { $text = [string]::Join("`n", (Get-Content $_)) $text -replace $RegEx ,"REPLACED"}

    Read the article

  • C# Exchange Powershell specified cast not valid

    - by stevetaylor20
    I'm getting a specified cast error trying to return a integer, example code below: results = pipeline.Invoke(); foreach (PSObject ps in results) { int diff = 0; Int32 exchcount = Convert.ToInt32(ps.Members["itemcount"].Value); diff = itemcount - exchcount; } I'm trying to find out what the data type if for itemcount of the Get-Mailboxstatistics but i can't find the information, i assume it's Int, i've tried string but that does not work either. any ideas please let me know! Thanks Steve

    Read the article

  • PowerShell function won't return object

    - by Dan
    I have a simple function that creates a generic List: function test() { $genericType = [Type] "System.Collections.Generic.List``1" [type[]] $typedParameters = ,"System.String" $closedType = $genericType.MakeGenericType($typedParameters) [Activator]::CreateInstance($closedType) } $a = test The problem is that $a is always null no matter what I try. If I execute the same code outside of the function it works properly. Thoughts?

    Read the article

  • Powershell wait for file to delete, then copy a folder

    - by user3317623
    Morning guys, I have a couple of scripts that have to sync a folder from the network server, to the local terminal server, and lastly into the %LOCALAPPDATA%. I need to first check if a folder is being synced (this is done by creating a temporary COPYING.TXT on the server), and wait until that is removed, THEN copy to %LOCALAPPDATA%. Something like this: Server-side script executes, which syncs my folder to all of my terminal servers. It creates a COPYING.TXT temporary file, which indicates the sync is in progress. Once the sync is finished, the script removes the COPYING.TXT If someone logs on during the sync, I need a script to wait until the COPYING.TXT is deleted I.E the sync is finished, then resume the local sync into their %LOCALAPPDATA%. do{cp c:\folder\program $env:LOCALAPPDATA} while(!(test-path c:\folder\COPYING.txt)) (So that copies the folder while the file DOESN'T exist, but I don't think that exits cleanly) I cannot format the above as code for some reason I'm sorry? Or: while(!(test-path c:\folder\COPYING.txt)){ cp c:\folder\program $env:LOCALAPPDATA\ -recurse -force if (!(test-path c:\folder\program)){return} } But that script quits if the COPYING.TXT exists. I think I need to create a function and insert that function within itself, or a nested while loop, but that is starting to make my head hurt. Any help would be greatly appreciated. Thanks guys.

    Read the article

  • SharePoint 2010 PowerShell Script to Find All SPShellAdmins with Database Name

    - by Brian Jackett
    Problem     Yesterday on Twitter my friend @cacallahan asked for some help on how she could get all SharePoint 2010 SPShellAdmin users and the associated database name.  I spent a few minutes and wrote up a script that gets this information and decided I’d post it here for others to enjoy.     Background     The Get-SPShellAdmin commandlet returns a listing of SPShellAdmins for the given database Id you pass in, or the farm configuration database by default.  For those unfamiliar, SPShellAdmin access is necessary for non-admin users to run PowerShell commands against a SharePoint 2010 farm (content and configuration databases specifically).  Click here to read an excellent guest post article my friend John Ferringer (twitter) wrote on the Hey Scripting Guy! blog regarding granting SPShellAdmin access.  Solution     Below is the script I wrote (formatted for space and to include comments) to provide the information needed. Click here to download the script.   # declare a hashtable to store results $results = @{}   # fetch databases (only configuration and content DBs are needed) $databasesToQuery = Get-SPDatabase | Where {$_.Type -eq 'Configuration Database' -or $_.Type -eq 'Content Database'}   # for each database get spshelladmins and add db name and username to result $databasesToQuery | ForEach-Object {$dbName = $_.Name; Get-SPShellAdmin -database $_.id | ForEach-Object {$results.Add($dbName, $_.username)}}   # sort results by db name and pipe to table with auto sizing of col width $results.GetEnumerator() | Sort-Object -Property Name | ft -AutoSize     Conclusion     In this post I provided a script that outputs all of the SPShellAdmin users and the associated database names in a SharePoint 2010 farm.  Funny enough it actually took me longer to boot up my dev VM and PowerShell (~3 mins) than it did to write the first working draft of the script (~2 mins).  Feel free to use this script and modify as needed, just be sure to give credit back to the original author.  Let me know if you have any questions or comments.  Enjoy!         -Frog Out   Links PowerShell Hashtables http://technet.microsoft.com/en-us/library/ee692803.aspx SPShellAdmin Access Explained http://blogs.technet.com/b/heyscriptingguy/archive/2010/07/06/hey-scripting-guy-tell-me-about-permissions-for-using-windows-powershell-2-0-cmdlets-with-sharepoint-2010.aspx

    Read the article

  • When ran as a scheduled task, cannot save an Excel workbook when using Excel.Application COM object in PowerShell

    - by Daniel Richnak
    I'm having an issue where I've automated creating an Excel.Application COM object, add some data into a workbook, and then saving the document as an xlsx. This works fine if: I'm already in Powershell interactive host and either run each command in sequence, or execute as a ps1. I run it from cmd.exe, using the syntax: powershell.exe -command "c:\path\to\powershellscript.ps1" I create a scheduled task in Windows 7 / Server 2008 R2, use the above powershell.exe -command syntax, and use the mode "Run only when the user is logged on". It fails when I modify the same scheduled task, but set it to "run whether the user is logged on or not". Here's a sample script that illustrates the problem I'm having: $Excel = New-Object -Com Excel.Application $Excelworkbook = $Excel.Workbooks.Add() $excelworkbook.saveas("C:\temp\test.xlsx") $excelworkbook.close() I have a theory that the COM object fails somehow if my profile isn't loaded / if it's not performed in a command window. Any ideas on which options to choose when creating the scheduled task, or which options to use when creating the Excel object or using the SaveAs() function? Can anybody reproduce this? I've been able to see this behavior on both a Server 2008 R2 machine, and Windows 7. Haven't tried other platforms.

    Read the article

< Previous Page | 18 19 20 21 22 23 24 25 26 27 28 29  | Next Page >