powershell-2.0

Keep x number of files and delete all others - Powershell

删除回忆录丶 提交于 2019-12-18 12:54:36
问题 I am trying to write a script that will look through a set of folders and keep only the last 10 files. The files in each folder could be created daily, weekly or monthly. I need the script to keep the 10 most recent copies regardless of the creation date or modified date. Using another post I created the script below that works but it doesnt keep 10 copies it keeps any file that isn't older than 10 days. $ftppath = "C:\Reports" Get-ChildItem $ftppath -recurse *_Report_*.zip -force|where {$_

Colour-coding get-content results

 ̄綄美尐妖づ 提交于 2019-12-18 12:29:29
问题 I've got a powershell script that monitors a log file, filters out the interesting bits and then presents those bits to me as and when they are written to the file. Works wonderfully. The line of interest is: get-content "$logFile" -wait | where { select-string $searchTerm -inp $_ } Now I want to get fancy! I would like the font colour to change everytime a particular term is encountered. I can set the font colour easily enough, but how would you do it on-the-fly with the above statement?

SMO ConnectionContext.StatementTimeout setting is ignored

醉酒当歌 提交于 2019-12-18 07:05:21
问题 I am successfully using Powershell with SMO to backup most databases. However, I have several large databases in which I receive a "timeout" error "System.Data.SqlClient.SqlException: Timeout expired". The timout consistently occurs at 10 minutes. I have tried setting ConnectionContext.StatementTimeout to 0, 6000, and to [System.Int32]::MaxValue. The setting made no difference. I have found a number of Google references which indicate setting it to 0 makes it unlimited. No matter what I try,

Why is Powershell 2.0 installed in the same location as Powershell 1.0?

倖福魔咒の 提交于 2019-12-18 05:45:18
问题 Does anyone know why Powershell 2.0 is installed in C:\Windows\System32\WindowsPowerShell\v1.0 on a Windows 7 box? 回答1: It's actually an interesting story in side-effects. Visual Studio has a fixed list of assemblies in their "Add Reference" dialog. Anything else has to be browsed for. Developers tended to browse for this location in the Windows directory, where System.Management.Automation.dll (the assembly that runs most of PowerShell lives) This made an absolute reference to this location.

Read Json Object in Powershell 2.0

ε祈祈猫儿з 提交于 2019-12-18 03:55:53
问题 I am using Powershell 2.0 (cannot make an upgarde to V3.0 as of now) & I want to read the below Json object. "{\"DevResults\":[{\"TechnologyName\":\"AD\",\"RuleName\":\"SOA account (user logon/display name)\",\"OutputValue\":\"SOADevClientCenter\"}, {\"TechnologyName\":\"AD\",\"RuleName\":\"SOA account (pre-Windows 2000)\",\"OutputValue\":\"SOADevCliCen\"}, \"ProdResults\":[{\"TechnologyName\":\"AD\",\"RuleName\":\"SOA account (user logon/display name)\",\"OutputValue\":\"SOAClientCenter\"},

http requests with powershell

筅森魡賤 提交于 2019-12-18 03:54:47
问题 I am looking to make http requests to web pages with powershell, is this possible and if so, how may I achieve this? Can I make requests to https pages? I am able to make http requests with a bat file but not https, was hoping I could https page requests with powershell. 回答1: You can use the usual WebRequest and HttpWebRequest classes provided by the .NET framework. $request = [System.Net.WebRequest]::Create('http://example.com') # do something with $request It's no different from using the

http requests with powershell

流过昼夜 提交于 2019-12-18 03:53:59
问题 I am looking to make http requests to web pages with powershell, is this possible and if so, how may I achieve this? Can I make requests to https pages? I am able to make http requests with a bat file but not https, was hoping I could https page requests with powershell. 回答1: You can use the usual WebRequest and HttpWebRequest classes provided by the .NET framework. $request = [System.Net.WebRequest]::Create('http://example.com') # do something with $request It's no different from using the

start-Transcript not capturing all output to log file..?

旧城冷巷雨未停 提交于 2019-12-17 19:58:00
问题 I have the below code that goes through and gets scheduled tasks info and puts the output that occurs on the screen to a log file. However, what I have noticed is that all errors are logged EXCEPT for servers that have "Access is denied" - how can I log those errors in the log file as well. Below is the code: Start-Transcript -path $scheduledpath\logging.txt -append foreach ($name in $names) { Write-Host "Running Against Server $name" -ForegroundColor Magenta if ( Test-Connection

How to retrieve a recursive directory and file list from PowerShell excluding some files and folders?

你离开我真会死。 提交于 2019-12-17 17:42:25
问题 I want to write a PowerShell script that will recursively search a directory, but exclude specified files (for example, *.log , and myFile.txt ), and also exclude specified directories, and their contents (for example, myDir and all files and folders below myDir ). I have been working with the Get-ChildItem CmdLet, and the Where-Object CmdLet, but I cannot seem to get this exact behavior. 回答1: The Get-ChildItem cmdlet has an -Exclude parameter that is tempting to use but it doesn't work for

How do I get help messages to appear for my Powershell script parameters?

筅森魡賤 提交于 2019-12-17 17:25:14
问题 I have a powershell script ( setup.ps1 ), that we use as the entry point for our development environment setup scripts. It takes a parameter: param( [Parameter(Position=0,HelpMessage="The targets to run.")] [Alias("t")] [string[]] $Targets = "Help" ) When I run PS > get-help .\setup.ps1 -detailed in the parameters section, my help message doesn't appear: PARAMETERS -Targets <String[]> What do I need to do to get my parameter help messages to display? 回答1: You put a certain style of comment at