powershell-1.0

Identify the PID of a Executing Batch File in Powershell

℡╲_俬逩灬. 提交于 2019-12-08 08:12:41
问题 I need to identify the P(rocess) ID of an executing batch file from a PowerShell (v1.0) script. Can anyone suggest a way of doing this? Thanks, MagicAndi. 回答1: Well, whether that's possible depends on how you executed the batch file. In general, the only way you could possibly find this out is to look at the command line used to start the batch. If you double-click a batch file in Windows Explorer you'll get a command line like cmd /c ""C:\Users\Me\test.cmd" " In Powershell you can then use

Why is Powershell ISE showing errors that Powershell console does not show?

会有一股神秘感。 提交于 2019-12-05 13:22:36
问题 I'm running exactly the same script.ps1 file in a Powershell ISE (manually loading the script and pressing F5) and in a Powershell console (executing the script file). They both work but ISE shows errors that the console does not. Why? The code is: git push origin master Write-Host "lastExitCode: $lastExitCode Last command was successful: $?" This code output this error in the ISE: git.cmd : Initializing to normal mode At E:\script.ps1:28 char:4 + git <<<< push origin master + CategoryInfo :

PowerShell script to move files and folders including subfolders from one location to another older than x days

痞子三分冷 提交于 2019-12-05 12:03:59
问题 I developed a PowerShell script, and it's working absolutely fine. The only challenge is the files in the subfolders are not getting moved to the destination. get-childitem -Path "\\servername\location" | where-object {$_.LastWriteTime -lt (get-date).AddDays(-31)} | move-item -destination "C:\Dumps" I am unable to customize the script further. 回答1: Use the -Recurse option on the Get-ChildItem command to get through to the files in the sub folders and then move each individually by piping the

Using PowerShell with .NET 3.5 runtime/libraries

安稳与你 提交于 2019-12-05 04:43:38
Is it possible to run PowerShell 1.0 (or 2.0 CTP) backed by the 3.5 runtime instead of 2.0? We're building a .NET 3.5 solution, and I'd still like to use PowerShell as our scripting engine for scheduled tasks, etc. I don't need LINQ syntax or anything, just the 3.5 libraries and runtime. FOLLOWUP: thank you for the reply about dynamically loading assemblies. But let me clarify my question: is there any way to run PowerShell so that the 3.5 libraries run by default? So that if I enter New-Object System.Xml.XmlDocument , for example, I'm actually getting the 3.5 version by default? Semi-related

PowerShell script to move files and folders including subfolders from one location to another older than x days

冷暖自知 提交于 2019-12-04 01:03:59
I developed a PowerShell script, and it's working absolutely fine. The only challenge is the files in the subfolders are not getting moved to the destination. get-childitem -Path "\\servername\location" | where-object {$_.LastWriteTime -lt (get-date).AddDays(-31)} | move-item -destination "C:\Dumps" I am unable to customize the script further. Musaab Al-Okaidi Use the -Recurse option on the Get-ChildItem command to get through to the files in the sub folders and then move each individually by piping the collection to Move-Item Get-ChildItem -Path "C:\Test" -Recurse | Where-Object {$_

Why is Powershell ISE showing errors that Powershell console does not show?

半城伤御伤魂 提交于 2019-12-04 00:19:23
I'm running exactly the same script.ps1 file in a Powershell ISE (manually loading the script and pressing F5) and in a Powershell console (executing the script file). They both work but ISE shows errors that the console does not. Why? The code is: git push origin master Write-Host "lastExitCode: $lastExitCode Last command was successful: $?" This code output this error in the ISE: git.cmd : Initializing to normal mode At E:\script.ps1:28 char:4 + git <<<< push origin master + CategoryInfo : NotSpecified: (Initializing to normal mode:String) [], RemoteException + FullyQualifiedErrorId :

Copy-Item copies directory as well as contents to UNC path

試著忘記壹切 提交于 2019-12-03 04:02:43
问题 I'm trying to take the contents of a folder and copy it to another using PowerShell 1.0. Pretty simple stuff and it all works fine using Copy-Item $from $to -recurse if I am copying from a local folder to a local folder. However, if the $to variable is a UNC path, it seems to copy the $from directory, not just its contents. e.g. $from = "c:\temp\rhysc\" $to = "\\OtherMachineName\ShareFolder\" Copy-Item $from $to -recurse ...ends up up creating a folder \\OtherMachineName\ShareFolder\rhysc

How to pass parameters to powershell command when interpreting script from standard input

戏子无情 提交于 2019-12-02 06:52:59
问题 I am running powershell script over ssh as ssh user@host "powershell -Comand - < script.ps1 . It works as expected as long as I start passing arguments. When I put it as powershell -Command - my args it fails (as documented) '-' was specified with the -Command parameter; no other arguments to -Command are permitted. While the other way around powershell my args -Command - it fails with: The term 'my' is not recognized as the name of a cmdlet, function, script file, or operable program. Check

Write-Host => Export to a file

吃可爱长大的小学妹 提交于 2019-12-01 03:04:21
I have got a script with some commands such as Write-Host "Server1" . How can I export it to a file? When I tried with script > export.txt it didn't work. CB. Write-Host redirects the output only to the console. You can use Write-Output and redirect to a file ( > export.txt or pipe to Out-File export.txt ) In the extreme case when you absolutely need to redirect all output from a script, take a look to this cmdlet: Start-Transcript Get-Help Start-Transcript -full jon Z In PowerShell script > export.txt is syntactic sugar for script | Out-File -path export.txt . Write-Host sends the objects to

Get-ChildItem recurse as a parameter in PowerShell

送分小仙女□ 提交于 2019-12-01 00:55:04
问题 I am looking to create a function that could toggle the ability to recurse in cmdlet Get-ChildItem. As a very basic example: ... param ( [string] $sourceDirectory = ".", [string] $fileTypeFilter = "*.log", [boolean] $recurse = $true ) Get-ChildItem $sourceDirectory -recurse -filter $fileTypeFilter | ... How does one conditionally add the -recurse flag to Get-ChildItem without having to resort to some if/else statement? I thought perhaps one could just substitute the -recurse in the Get