Tag Info

Hot answers tagged

7

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 ...


2

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; ...


2

You do not specify the output format and/or if you want some aggregation functions, but one example script which will create as exit one column file is: for ((i=1;i<25;i++)) do awk '{print $9}' Angle${i}/output.txt >>total.txt done If you want to have 9th column from each file as column you can use script like this: awk '{print $9}' ...


2

This would do it: Get-ChildItem C:\PATH\TO\Folder\pka.dump -recurse | Where-Object{$_.Length -lt 500}


2

See: Where are the default settings saved for the Command prompt defaults? Export the HKEY_CURRENT_USER\Console registry folder to a .reg file, and then you can easily import them by double-clicking on the file. To automate the import, run regedit /s c:\temp\console.reg and the registry file will be imported automatically. On my Windows 7 system this ...


2

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

I was also searching for a good solution, but I couldn't find any ... Here is a short PowerShell script to translate ANSI color codes: function Open-Colored([String] $Filename) { Write-Colored(cat -Raw $Filename) } function Write-Colored([String] $text) { # split text at ESC-char $split = $text.Split([char] 27) foreach ($line in $split) ...


1

Delete all files from current directory and sub-directories but leaving the folders structure. (/Q) switch is for asking the user if he is ok to delete Caution : try it without the /Q to make sure you are not deleting anything precious. del /S * /Q


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

MMASetup-i386 uses the /Q for quiet install, not /s. Start-Process -FilePath "C:\Temp\MMASetup-i386.exe" -ArgumentList "/Q" -wait You can often find the valid arguments for an .exe by running it with the /? argument, such as: MMASetup-i386.exe /? However, that is not always the case and sometimes you may need to consult the documentation or search the ...


1

You're casting dates to strings and it's producing different results in ISE and PowerShell console. Look at your from073.rar file: ISE date: 10/05/2015 PowerShell console date: 5/10/2015 You'd better get rid of .ToShortDateString() and compare dates directly. See this question: Powershell: Comparing dates Even though the strings are presented ...


1

The feature name is RemoteServerAdministrationTools-Roles-AD-Powershell For future reference, dism will list all available features with the /get-features switch: dism /online /get-features


1

Get-ChildItem -Recurse C:\clntfiles | Select BaseName


1

The solution was to add an ACL entry for the VM's default gateway, or, in case of a custom route to the 192.168.Y subnet, the IP address of the route destination, to allow packets to be routed through to the remote host. Add-VMNetworkAdapterAcl -vm $vm -RemoteIPAddress 192.168.X.1 -action allow -direction both This, sadly, is not mentioned in any ...


1

I found out that it had nothing to do with my environment variables, execution policy, or any other settings. My desktop is running PowerShell 4.0. My laptop was running PowerShell 2.0. After upgrading my laptop to PowerShell 4.0, executables now run without the need to type in the extension.


1

You could use this: Create a PowerShell object in the Parent(i.e. script.ps1 holding Get-ChildItem PKA.dump -r | Sort-Object $_ | ForEach-Object { Get-Content $_ | Select -Index 19 } > output.txt), and enable Unsigned execution with: Set-ExecutionPolicy Unrestricted from an Admin PowerShell Copy and paste this into a batch file: copy script.ps1 Angle1 ...


1

There are several strategies for handling errors like that. The first is to add an -ErrorAction parameter to the command that may fail. The second is to wrap the command in try/catch: $ProjectSub = $Project + "\Folder2" $securityDescriptor = Get-Acl -Path $ProjectSub $securityDescriptor.SetSecurityDescriptorSddlForm($sddlRootFolders) try { Set-Acl ...



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