Tag Info

Hot answers tagged

5

When defining variables in PowerShell, single quotes (') mean you want the literal version of the string. Use double-quotes (") if you want to allow variable expansion: PS C:\> $a = "hello" PS C:\> $a hello PS C:\> $b = "$a world!" PS C:\> $b hello world! More info: Single Quotes vs. Double Quotes in PowerShell: What's the Difference? ...


3

As you have not provided your complete bat-file I guess that it is Powershell.exe -noexit -command "cd 'c:\Dev\ProductDev'" PowerShell -NoExit -Command "Write-Host 'node sp'" This is the wrong approach. You are first starting a Powershell which changes to the given directory and then stays open. If you exit this powershell the bat file will start the ...


1

A few possibilities for resolving locked files: The System or an application is locking it; use a tool such as CrystalRich LockHunter to find out what, and if you wish, unlock it. Sometimes a computer needs to be restarted in order to relinquish all locks, particularly if the object is used by a web site. Setting permissions on a folder is a bit tricky; ...


1

To change from within Windows, try the following: Pin PowerShell to the taskbar. Right click the PowerShell icon on the taskbar. Right click 'Windows PowerShell' and select 'Properties'. Within the 'Properties' window, go to the 'Shortcut' tab and change the 'Start in:' field to your desired starting directory. (Example: C:\Users\username\Desktop). Click ...


1

Yes it's possible, you have to use DeviceChangeEvent instead of VolumeChangeEvent : Register-WmiEvent -Class win32_DeviceChangeEvent -SourceIdentifier deviceChange and $newEvent = Wait-Event -SourceIdentifier deviceChange Note that the SourceIdentifier is just the name of event subscription so you can keep "volumeChange" if you prefer.


1

Try to use PowerShell 3 - I think some limitations were removed from Move-Item. The following PowerShell script will do Copy-Item followed by compare-object and Remove-Item only if equal : $source = "<UNC Path>" $destination = "<UNC Path>" if (test-path $destination -PathType Container) { foreach ( $srcObj in (get-childitem $source )) { ...


1

Here's how you can use Robocopy to move a whole folder (test1) into another folder (some_folder) on a different server, while maintaining date stamps, etc.: ROBOCOPY "test1" "\\SomeServer\c$\some_folder\test1" /MOVE /COPY:DAT /DCOPY:T From the ROBOCOPY /? usage info: /COPY:copyflag[s] :: what to COPY for files (default is /COPY:DAT). ...


1

but I cannot get it to delete the brackets from the file name. So in my testing directory the files changed to the following Doc1-doc(1.0).doc ----- Doc1-doc().doc This is because replace uses regex and parentheses (capturing group) should be escaped. The easiest way to escape all text is to use [regex]::Escape method: gi * | % { rni $_ ...


1

The problem you're running into is that PowerShell's -replace uses Regular Expressions for searching. This means that the brackets (()) in your search query are being interpreted as a RegEx capture group. In this case, you want to reference them as literal characters, so you need to escape the brackets. In RegEx, this is done with a backslash (\). So ...


1

Powershell automatically expands variables in double quotes. Instead of returning the name propery of your object it returns what it thinks is the value you need. If you want to select the name attribute you can do it like this: gci test.* | % { "Name: $($_.Name)" } This forces Powershell to evaluate the expression in the braces first so that it only ...


1

Define parameter in the function, that will hold your data. Then check if parameter is supplied and act accordingly. You might have to do some tweaking due to the way how PowerShell passes data to external programs, but the basic idea stands. Barebone example: Usage: 'foo', '', 'bar' | Invoke-Python Here I'm passing an array to the Invoke-Python ...


1

You can check value of $MyInvocation.ExpectingInput expression to find out did your function expect any pipeline input or it is the first element of pipeline. function python { if($MyInvocation.ExpectingInput){ $input | & c:\python27\python.exe @args }else{ & c:\python27\python.exe @args } }


1

Looks like you need some tee. (Not the drinkable variety although you might enjoy a cup of that too while robocopy does its thing. :) powershell -command "robocopy 'drive:\source dir' 'drive:\target dir' /np | tee 'drive:\log file.log'" (Or just type powershell and then at the PS prompt type your robocopy command piped via tee to the log file.) Edit: Ok, ...


1

Example log: *EXTRA Dir -1 y:\Open Client Files\sample\ 0 f:\server\blah\somefolder\ 6 f:\server\blah\somefolder\ The numbers (-1, 0, 6, etc.) are the number of files in that folder. -1 is used for "Extra Dir" entries, and 0 is used for "New Dir" entries (and other folder without any files in them). ...


1

$newName = '$Rename_{0:d6}{1}' -f $i , $extension # $rename input cannot be used here Why not? This definitely works: $newName = '{0}_{1:d6}{2}' -f $Rename, $i, $_.Extension


1

Source GPG Configuration options 4.2.1 How to change the configuration These options are used to change the configuration and are usually found in the option file. ... --keyring file Add file to the current list of keyrings. If file begins with a tilde and a slash, these are replaced by the $HOME directory. If the filename does not ...


1

This should do the trick, it'll go through all the lines in the file, and replace any "a" with "b", but you'll need to save that back into a file afterwards cat file | % {$_.replace("a","b")} | out-file newfile



Only top voted, non community-wiki answers of a minimum length are eligible