Start-Job Problems
Hi all, Why this code not works ? function teste { begin { function lala { while ($true) { "JJJJ" | Out-File c:\Testes\teste.txt -Append } } } process { Start-Job -ScriptBlock {lala} } } ...
Hi all, Why this code not works ? function teste { begin { function lala { while ($true) { "JJJJ" | Out-File c:\Testes\teste.txt -Append } } } process { Start-Job -ScriptBlock {lala} } } ...
How do i use a function in my profile on the remote machine when using Enter-PSSession on my local machine to open a remote powershell session. ...
Hi, How can i extricate substring from string using powershell ? I have this string: "-----start-------Hello World------end-------", i have to the hello world. What is the best way to do that? Thanks! ...
When trying to debug my powershell script in the powerGUI script editor (2.0.0.1082) the $MyInvocation.MyCommand.Path is $null. It works when running the script via powershell. Running it in Powershell_ise.exe (on one of our servers) also works fine. Have anyone else had the same problem or know what's wrong? Here's my powershell ve...
I have a directory with XML files. I quickly want to go through them and sum upp the value stored in one attribute. I have figured out how to fidn the nodes I am interested in. For example: (Select-Xml -Path .\*.xml -XPath "//*[@Attribue = 'valueImlookingfor']").Count This command gives me the count of elements in all of the XML fil...
I am trying to write the entire output (errors included) of an executing script to the console and a file at the same time. I have tried several different options .\MyScript.ps1 | tee -filePath C:\results.txt # only the output to the file .\MyScript.ps1 2> C:\results.txt # only the errors to the file and not the console .\MyScript.ps1 >...
I have a function in powershell 2.0 named getip which gets the IP address(es) of a remote system. function getip { $strComputer = "computername" $colItems = GWMI -cl "Win32_NetworkAdapterConfiguration" -name "root\CimV2" -comp $strComputer -filter "IpEnabled = TRUE" ForEach ($objItem in $colItems) {Write-Host $objItem.IpAddress} }...
I want to set a time limit on a PowerShell (v2) script so it forcibly exits after that time limit has expired. I see in PHP they have commands like set_time_limit and max_execution_time where you can limit how long the script and even a function can execute for. With my script, a do/while loop that is looking at the time isn't appropri...
I'm running across a problem I can't seem to wrap my head around using the Read-Archive cmdlet available via PowerShell Community Extensions (v2.0.3782.38614). Here is a cut down sample used to exhibit the problem I'm running into: $mainPath = "p:\temp" $dest = Join-Path $mainPath "ps\CenCodes.zip" Read-Archive -Path $dest -Format zip ...
I am attempting to use the Remove-Item cmdlet as part of an automation for a system. The files are stored on a server that requires elevated rights to perform the file deletion. I have access to a domain admin account that I use for such automation scripts. The code below will build the PSCredential object: $password = New-Object Sys...
I'm trying to find all instances of files with names like VAT*.xls where the creation date is less than 6 months ago. I have tried: dir c:\vat*.xls -r | ? {($now -$_.lastwritetime).days -lt 300} and gci c:\vat*.xls -r | ? {($now -$_.lastwritetime).days -lt 300} I know there is a file VAT0210.xls dated 1 April 2010 but neither query g...
I'm using PowerShell 2.0 and I want to pipe out all the subdirectories of a certain path. The command get-childitem c:\mypath -Recurse | ... outputs all files and directories, but I can't figure out how to filter out the files. I've tried using $_.Attributes to get the attributes but then I don't know how to construct a literal inst...
I am new to both MSBuild and PowerShell and am trying to wrap my head around where these stand with respect to deploying ASP.NET applications. Can someone explain the difference? (I hope I am comparing apples and apples) ...
Every day we run an backup job. This job creates a new file in format yyyyMMdd.7z and now we need to cleanup our backup storage automatically. Our backup police says that we need to keep files from last 5 days, and last backup of each month. First step is easy since I have current day. But how I can keep the last of each month? ...
I've never been able to get the AllowEmptyString validation attribute to work. This: function Get-InputString( [parameter(mandatory=$true, position=0)][string][AllowEmptyString]$Str ) { $Str } Results in this: PS C:\> Get-InputString '' Unable to find type [AllowEmptyString]: make sure that the assembly containing this type ...
I am trying to call the Rename method on the Win32_ComputerSytem class using Invoke-WMI method. Using this syntax works fine (gwmi win32_ComputerSystem).Rename("NEWNAME") This also works fine for demo purposes Invoke-WmiMethod -path win32_process -Name create -ArgumentList notepad However, when i try the following, I get an error ...
hi, suppose i have 2 powershell scripts, test1.ps1 and test2.ps1 #test1.ps1 $a="test1" ################## #test2.ps1 echo $a how to ref. $a in test2.ps1 from test1.ps1? ...
hi i have a simple powershell script, like this sqlcmd -S. -E -Q 'select ''$(x)''' -v x="c:a" but i always got the error message Sqlcmd: ':a': Invalid argument. Enter '-?' for help. i figured out that it is the ":" in the argument caused the problem, but i do not know how to escape it. thanks, David ...
Let's say I have the string "blah blah F12 blah blah F32 blah blah blah" and I want to match the F12 and F32, how would I go about capturing both to the Powershell magic variable $matches? If I run the following code in Powershell: $string = "blah blah F12 blah blah F32 blah blah blah" $string -match "F\d\d" The $matches variable onl...
Imagine I have a directory structure like so: parentDir\dirA\foo\ parentDir\dirB\foo\ parentDir\dirC\ parentDir\dirD\bar\foo\ parentDir\dirE\foo\ parentDir\dirF\ I want to select only the directories that a) are immediate children of parentDir, and b) have a foo directory as an immediate child. So dirs A, B, and E qualify, whilst C, ...