powershell-3.0

Getting any special folder path in Powershell using folder GUID

爱⌒轻易说出口 提交于 2019-12-04 12:40:23
I want to use a PowerShell script to automate tasks related to the user when the user logs in. Sometimes a user will have moved his Documents folder from the default location. How can I determine the location of the user's Documents folder in PowerShell with a method that will work for all special folders? I tried to use SHGetKnownFolderPath calls from PowerShell based on Lee Holmes work As pinvoke website C# sample doesn't use StringBuilder, I assumed it was not required and stripped builder + "-Using" references param($KNOWNFOLDERID) $Pinvoke = @’ [DllImport("shell32.dll")] public static

Using PowerShell v3's Invoke-RestMethod to PUT/POST X Mb of a binary file

跟風遠走 提交于 2019-12-04 11:46:19
I have been doing a bit of work with PowerShell v3 (CTP2 from here ) and its new Invoke-RestMethod like so: Invoke-RestMethod -Uri $dest -method PUT -Credential $cred -InFile $file However, I'd like to use this for pushing very large binary objects, and therefore like be able to push a range of bytes from a large binary file. For example, if I have a 20Gb VHD, I would like to break it up into chunks of say, 5Gb each (without splitting and saving the individual chunks first) and PUT/POST these to BLOB storage like S3, Rackspace, Azure, etc. I am also assuming the chunk size is larger than the

PowerShell: the mysterious -RemainingScripts parameter of ForEach-Object

∥☆過路亽.° 提交于 2019-12-04 10:38:13
问题 Short question : anyone has detailed information on -RemainingScripts parameter of ForEach-Object? Long question: I just started learning PowerShell from last week and I'm going through each Cmdlets to learn more details. Based on public documentation, we know ForEach-Object can have Begin-Process-End blocks, like this: Get-ChildItem | foreach -Begin { "block1"; $fileCount = $directoryCount = 0} -Process { "block2"; if ($_.PsIsContainer) {$directoryCount++} else {$fileCount++}} -End { "block3

How to create real objects with behavior (methods) in PowerShell?

元气小坏坏 提交于 2019-12-04 10:34:33
问题 Probably this question has been answered before.... but I have not found a specific answer to my needs. BTW I'm using PowerShell 3 Well, I'm new in PowerShell but I have a lot of experience as a C# developer, so working with objects is very important to me. So I'm wondering if there's a clean way to apply OOP concepts (well not all of them, though that would be awesome) in a PowerShell script, for example there are specific things that I would like to do. Note: I'm aware that I can write C#

How do I download a protected file using PowerShell?

不问归期 提交于 2019-12-04 08:59:41
I am trying to download a file using PowerShell 3.0 from my TeamCity build server. I have configured TeamCity to use NTLM authentication but I cannot download the file directly and get redirected to login. I am trying to use the following PowerShell code to download the file. $artifacts = "http://teamcity/repository/download/bt1/.lastSuccessful/%7Bbuild.number%7D.zip" Invoke-WebRequest -Uri $artifacts -UseDefaultCredentials My response from the request is a redirection to the login page. Here is the code for the final solution . $artifacts = "http://teamcity/repository/download/bt1/

How to write an event log entry with structured XML data?

人走茶凉 提交于 2019-12-04 07:48:59
Question: How to write an event log entry with structured XML data using PowerShell? My PowerShell script writes to the Windows event log using the Write-EventLog cmdlet. Currently I use the -Message parameter to set the event log message: Write-EventLog -LogName $EventLogName -Source $EventSource -EntryType Error -EventId 1 -Message "MyMessageHere" If you look at the message using Windows EventViewer you get an XML like this: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> [...] </System> <EventData> <Data>MyMessageHere</Data> </EventData> </Event> I.e. the

Powershell Script Running Slowly

别来无恙 提交于 2019-12-04 06:10:15
问题 I'm writing a script to check the version on about 15 remote servers and the script is taking much longer to execute than I would expect. $listServers = @("compName1", "compName2", "compName3", ... "compName15") "" | Out-File C:\temp\javaVersion.txt "" | Out-File C:\temp\javaVersionLog.txt $cred = Get-Credential ForEach ($server in $listServers) { Measure-Command {$javaVersion = Invoke-Command -ComputerName $server -Credential $cred -Authentication Kerberos -ScriptBlock {Get-WmiObject -Class

specific text of today's date from txt file by powershell

守給你的承諾、 提交于 2019-12-04 05:52:10
问题 I have a text file. Similar to this. This is a sample data. This is a sample data. This is a sample data. Sat Jun 06 08:17:01 2015 WARNING: Cannot delete file. Error-101 Error-100 Error-102 This is a sample data. This is a sample data. Error-10666 This is a sample data. Sat Jun 06 10:17:01 2015 File deleted. This is a sample data. This is a sample data. Sat Jun 06 10:17:01 2015 File deleted. Sat Jun 06 11:17:01 2015 WARNING: Cannot delete file. Error-101 This is a sample data. Sat Jun 06 18

How can I use PowerShell's -filter parameter to exclude values/files?

我们两清 提交于 2019-12-04 03:26:39
I'm currently running a PowerShell (v3.0) script, one step of which is to retrieve all the HTML files in a directory. That works great: $srcfiles = Get-ChildItem $srcPath -filter "*.htm*" However, now I'm faced with having to identify all the non-HTML files...CSS, Word and Excel docs, pictures, etc. I want something that would work like the -ne parameter in conjunction with the -filter parameter. In essence, give me everything that's not "*.htm*" -filter -ne doesn't work, I tried -!filter on a whim, and I can't seem to find anything in powershell doc on MSDN to negate the -filter parameter.

Start PowerShell ISE with the 2.0 runtime

谁说胖子不能爱 提交于 2019-12-04 02:45:46
This question was migrated from Server Fault because it can be answered on Stack Overflow. Migrated 6 years ago . Learn more . When PowerShell 3.0 is installed, I can force PowerShell to start using the version 2.0 -Version Starts the specified version of Windows PowerShell. Enter a version number with the parameter, such as "-version 2.0" This is useful with snapin that does not supports the .Net Framework V 4 (SharePoint!). Is there an equivalent for PowerShell ISE ? I tried to run powershell_ise.exe -version 2.0 but this does not works. Running powershell_ise.exe -help does not show any