powershell-3.0

How to detect whether a script is dot-sourced, or loaded as part of a module using powershell v2+?

*爱你&永不变心* 提交于 2019-12-11 01:19:31
问题 Given a ps1 file as part of a module with the following code: function Get-Greeting { 'Hello {0}' -f $Env:Username } Export-ModuleMember -Function:Get-Greeting When loaded as part of the module, everything is fine. If I dot-source the script, I get Export-ModuleMember : The Export-ModuleMember cmdlet can only be called from inside a module. I know I could just add a -ErrorAction:Ignore on the Export-ModuleMember, but that's not the point. I'd like to have a script run differently whether it

Possible to set a maximum of memory consumption on a powershell script in % or megabyte?

江枫思渺然 提交于 2019-12-11 00:35:16
问题 I sometimes have scripts which are eating up all the memory. Since I don't want to monitor them all the time or set cpu priority to low manually I am wondering if there is an option to give that specific script a value (maybe in mb) of memory. Does this option exist? 回答1: PowerShell doesn't provide any built-in way to control system resources like the memory used by a script. Windows does provide a way to limit system resources to groups of processes, you can learn more about that here: http:

Manage web farms from powershell v3.0

。_饼干妹妹 提交于 2019-12-10 22:27:47
问题 I have been searching for a way to create new web farms add add servers to it with PowerShell. I stumbled on this link http://www.iis.net/learn/web-hosting/microsoft-web-farm-framework-20-for-iis-7/web-farm-framework-20-for-iis-cmdlets-for-windows-powershell which says that you should add a snapin called WebFarmSnapin. But this does not seem to work at all in powershell v3.0 because it only says: Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 3. Does anyone

How to merge all contents in two csv files where records match off 1 column

会有一股神秘感。 提交于 2019-12-10 18:49:29
问题 I have two csv files. They both have SamAccountName in common. User records may or may not have a match found for every record between both files (THIS IS VERY IMPORTANT TO NOTE). I am trying to basically just merge all columns (and their values) into one file (based from the SamAccountNames found in the first file...). If the SamAccountName is not found in the 2nd file, it should add all null values for that user record in the merged file (since the record was found in the first file). If

Hudson cannot find powershell after update to powershell 3

为君一笑 提交于 2019-12-10 17:55:26
问题 One of my jobs had need for the ConvertTo-Json commandlet available in powershell 3.0 So I installed WMF 3.0 on our Windows Server 2008 R2 (SP1) box. After a restart all my powershell using jobs result in the error: [workspace] $ powershell.exe "& 'C:\Users\HUDSON~1\AppData\Local\Temp\hudson1263303013566726397.ps1'" The system cannot find the file specified FATAL: command execution failed java.io.IOException: Cannot run program "powershell.exe" (in directory "C:\hudson\jobs\MyProject

How can I remove a single user ACL from a large set of folders?

最后都变了- 提交于 2019-12-10 17:35:35
问题 I have a very large list of folders and I need to remove a single ACL from each of them. Rather than doing it manually, I'm trying to write a script to do it in a fraction of the time, but I'm running into a bit of trouble. Here is what I have so far: $filepath = "C:\ALCTEST" $user = "domain\username" $folders = @((get-item $filePath)) $folders += Get-ChildItem $filePath -Recurse | where { $_.PSIsContainer -ne $false } ##Need to do this in order to remove item 0 from the array, otherwise #

powershell xml sort nodes and replacechild

六眼飞鱼酱① 提交于 2019-12-10 17:06:40
问题 I'm trying to do something pretty simple with powershell and xml but haven't a bit of trouble. Basically I'm trying to take the following xml... and sort the machine elements by name. Then put them back into the XML so that I can save back to a file. Sorting seems to be working if output the $new object however, during the replacechild it's complaining "Cannot convert argument "0", with value: "System.Object[]" for "ReplaceChild" to type "System.Xml.XmlNode" : "Cannot convert the "System

What is the proper name for what [ordered] is in PowerShell 3.0?

对着背影说爱祢 提交于 2019-12-10 15:04:17
问题 In PowerShell, you can specify a type with square brackets like so: PS C:\Users\zippy> [int] IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Int32 System.ValueType There are also built in type accelerators like [xml] which saves a few keystrokes when you wish to cast something to an XmlDocument. PS C:\Users\zippy> [xml] IsPublic IsSerial Name BaseType -------- -------- ---- -------- True False XmlDocument System.Xml.XmlNode You can generate the list via one of the

How to Stop single Instance/VM of WebRole/WorkerRole

时光毁灭记忆、已成空白 提交于 2019-12-10 13:31:47
问题 We have a VM say SampleVM depoyed & running on Azure Environment and on the same we have created 2 instances One is WebRole & other is WorkerRole running onto Slot staging. My prob is I am able to Start/Stop SampleVM through powershell command but How can I Start/Stop a single instance(WebRole or WorkerRole) running on a SampleVM. However when I stop SampleVM then both the Instance also stopped but I want to stop only one Instance/VM i.e. WebRole Or WorkerRole. Please provide some powershell

Size of the sorted file is double than original file in powershell

两盒软妹~` 提交于 2019-12-10 13:05:49
问题 I have a powershell script, that reads file content, sorts it and writes output to new file. Following is the script: get-content $inputFile | sort > $sortedFile The output in file is sorted properly, but the output file ($sortedFile) is double larger than input file ($inputFile). Note: There are no duplicate or extra line in output file. Any help or ideas regarding this will be helpful. 回答1: Most likely the input file is ascii encoding while the default output using redirection is unicode