powershell-2.0

Convert seconds to hh:mm:ss,fff format in PowerShell

 ̄綄美尐妖づ 提交于 2019-12-06 19:27:04
问题 I have a string representing a time in seconds and milliseconds. I want to convert it to a string in the format "hh:mm:ss,fff". My solution still has the flaw that hours less than 10 are shown with one decimal instead of two: PS> $secs = "7000.6789" PS> $ts = [timespan]::fromseconds($s) PS> $res = "$($ts.hours):$($ts.minutes):$($ts.seconds),$($ts.milliseconds)" PS> $res PS> 1:56:40,679 What is the right way to achieve this? I'm sure there is a more elegant way with -f and datetime. 回答1: In

Why would a get-process -computername return a couldn't connect to remote machine error?

旧巷老猫 提交于 2019-12-06 13:04:18
I can execute the following command on a specific machine and it can return a list of processes on several target computers but returns a "Couldn't connect to remote machine" error on one machine. get-process -ComputerName 192.168.1.101 None of the target machines have powershell installed. The machine I am executing the powershell script on has 2.0 installed. I have admin privileges on all machines. The target machines that are able to return a list of processes remotely are server 2003 Standard Edition with SP 1. The target machine that does not return a list of processes remotely is server

Apply service packs (.msu file) update using powershell scripts on local server

不想你离开。 提交于 2019-12-06 12:11:30
What it basically does is the script gets the .msu files from a location and copies to the "C:\temp\" folder. Then the script gets all the .msu files and stores the names in the array. Using the foreach loop it tries to apply the .msu updates to the local server where the script is running. However when i run the script. It doesn't do anything. Below is the code $from="sourceLocation\*.msu" $to="C:\temp\" Copy-Item $from $to -Recurse -Force $listOfMSUs= (Get-ChildItem –Path $to -Filter "*.msu").Name Write-Host $listOfMSUs if($listOfMSUs) { foreach($msu in $listOfMSUs) { Write-Host "Processing

Is there way to know cmdlet version in Powershell for backward compatibility?

浪子不回头ぞ 提交于 2019-12-06 12:01:09
Say you are scripting in Powershell 4.0 environment and you want to make sure the script works in Powershell 3.0. How do you ensure its backward compatible?. Ok the question as phrased is a little more specific into what you are looking for. Sounds like you are asking for requires . The #Requires statement prevents a script from running unless the Windows PowerShell version , modules, snap-ins, and module and snap-in version prerequisites are met. If the prerequisites are not met, Windows PowerShell does not run the script. That way, while you are scripting, you can enforce the functional

get a set of files that have been modified after a certain date

允我心安 提交于 2019-12-06 11:59:14
Does anyone have a handy powershell script that gets a set of files from TFS based on a modification date ? I'd like to say "give me all the files in this folder (or subfolder) that were modified after X/Y/ZZZZ" and dump those files to a folder other than the folder they would normally go to. I know enough powershell to hack about and get this done, eventually, but I'm hoping to avoid that. Make sure you have the Team Foundation 2015 Power Tools installed. It comes with a PowerShell snapin. You can run the PowerShell console file right from its startup group or you can execute Add-PSSnapin

PowerShell to delete Desktop Items from a remote PC

末鹿安然 提交于 2019-12-06 11:30:58
I have 200 PC that need to have some specific icons removed. I created a CSV file with the ComputerName (1 name per row) I have another file with the file name of the icon that needs to be removed from the desktops (Shortcut1.lnk, etc). This other file is also a CSV (1 file name per row). How can I run a PowerShell script to remove those icons. (Please note that not all computers in my CSV file maybe turned on. Some maybe off or have network issues). $SOURCE = "C:\powershell\shortcuts" $DESTINATION = "c$\Documents and Settings\All Users\Desktop" $LOG = "C:\powershell\logs\logsremote_copy.log"

PowerShell script to extract .xls file from specific Outlook folder

☆樱花仙子☆ 提交于 2019-12-06 10:32:17
I want to extract and save an .xls file from an email I receive daily. I have a rule set up which saves the email in an Outlook mailbox, within a specific subfolder of the Inbox. The Outlook folder structure looks like this: -> Inbox --> Data (subfolder of "Inbox") ---> ToExtract (subfolder of "Data") I need to extract the .xls file from the "ToExtract" folder. I found a script that does most of the work for me, but it requires the user to supervise the script and manually select which Outlook folder to search. I need to change the script so it just points to the "ToExtract" subfolder. The

File in use with .net method but not with powershell cmdlet

核能气质少年 提交于 2019-12-06 10:10:00
To open and read files in powershell I use one of two methods: Get-Content $path or [System.IO.File]::OpenRead($path) While reading a log file that is in use by another process Get-Content doesn't seem to have any issues with it. Then again the powershell cmdlet is slow and uses more memory compared to .NET method. When I try to use .NET method however, I get the following error: "The process cannot access the file 'XYZ' because it is being used by another process." Q1: Why can't .net method access the file whilst powershell cmdlet can? Q2: And how could I read the file with .net method? Since

Does anyone have a Dependency graph and topological sorting code snippet for PowerShell?

拈花ヽ惹草 提交于 2019-12-06 07:21:20
问题 We were trying to parallelize our build with dependency graph and topological sorting. All our build logic is written in Msbuild and we are using powershell to call it. Has any one implemented dependency graph and topological sorting using powershell? I know that in unix there is a utility called tsort available. Is there any thing similar available in powershell? This article gives good idea but it is done in C# "http://msdn.microsoft.com/en-us/magazine/dd569760.aspx" 回答1: I did a quick

Speed up PowerShell script for Windows Registry search (currently 30 minutes)

别说谁变了你拦得住时间么 提交于 2019-12-06 06:35:45
I'm working on a script for use in Windows 7 and Windows 10 for a Windows Registry search in HKLM:\Software\Classes. So far my code works, but it's extremely slow. It takes about 30 minutes to complete. I need to use Set-Location also to avoid an error with Get-ItemProperty, which occurs because the $path is not a valid object. How can I speed this code up? What's wrong? File regsearch.ps1 ( Mathias R. Jessen's answer applied) Function Get-RegItems { Param( [Parameter(Mandatory=$true)] [string]$path, [string]$match) #Set Local Path and ignore wildcard (literalpath) Set-Location -literalpath