Recent Posts | - July, 2024-7,(1)
- May, 2024-5,(2)
- May, 2023-5,(1)
- February, 2023-2,(1)
- November, 2022-11,(1)
- July, 2022-7,(2)
- March, 2022-3,(1)
- November, 2021-11,(2)
- August, 2021-8,(2)
- July, 2021-7,(2)
- June, 2021-6,(1)
- May, 2021-5,(1)
- March, 2021-3,(1)
- February, 2021-2,(2)
- January, 2021-1,(7)
- December, 2020-12,(3)
- March, 2020-3,(2)
- February, 2020-2,(1)
- December, 2019-12,(2)
- November, 2019-11,(1)
- October, 2019-10,(1)
- September, 2019-9,(1)
- August, 2019-8,(1)
- May, 2019-5,(1)
- April, 2019-4,(2)
- March, 2019-3,(2)
- December, 2018-12,(1)
- November, 2018-11,(4)
- July, 2018-7,(1)
- May, 2018-5,(3)
- April, 2018-4,(2)
- February, 2018-2,(3)
- January, 2018-1,(3)
- November, 2017-11,(2)
- August, 2017-8,(1)
- June, 2017-6,(3)
- May, 2017-5,(5)
- February, 2017-2,(1)
- December, 2016-12,(1)
- October, 2016-10,(2)
- September, 2016-9,(1)
- August, 2016-8,(1)
- July, 2016-7,(1)
- March, 2016-3,(2)
- February, 2016-2,(3)
- December, 2015-12,(5)
- November, 2015-11,(5)
- September, 2015-9,(1)
- August, 2015-8,(2)
- July, 2015-7,(1)
- March, 2015-3,(2)
- February, 2015-2,(1)
- December, 2014-12,(4)
- July, 2014-7,(2)
- June, 2014-6,(2)
- May, 2014-5,(3)
- April, 2014-4,(3)
- March, 2014-3,(1)
- December, 2013-12,(2)
- November, 2013-11,(1)
- July, 2013-7,(1)
- June, 2013-6,(2)
- May, 2013-5,(1)
- March, 2013-3,(3)
- February, 2013-2,(3)
- January, 2013-1,(1)
- December, 2012-12,(3)
- November, 2012-11,(1)
- October, 2012-10,(1)
- September, 2012-9,(1)
- August, 2012-8,(1)
- July, 2012-7,(6)
- June, 2012-6,(1)
- April, 2012-4,(1)
- March, 2012-3,(3)
- February, 2012-2,(3)
- January, 2012-1,(4)
- December, 2011-12,(3)
- October, 2011-10,(3)
- September, 2011-9,(1)
- August, 2011-8,(10)
- July, 2011-7,(2)
- June, 2011-6,(7)
- March, 2011-3,(2)
- February, 2011-2,(3)
- January, 2011-1,(1)
- September, 2010-9,(1)
- August, 2010-8,(2)
- June, 2010-6,(1)
- May, 2010-5,(1)
- April, 2010-4,(3)
- March, 2010-3,(2)
- February, 2010-2,(3)
- January, 2010-1,(1)
- December, 2009-12,(3)
- November, 2009-11,(3)
- October, 2009-10,(2)
- September, 2009-9,(5)
- August, 2009-8,(3)
- July, 2009-7,(9)
- June, 2009-6,(2)
- May, 2009-5,(2)
- April, 2009-4,(9)
- March, 2009-3,(6)
- February, 2009-2,(4)
- January, 2009-1,(10)
- December, 2008-12,(5)
- November, 2008-11,(5)
- October, 2008-10,(13)
- September, 2008-9,(10)
- August, 2008-8,(7)
- July, 2008-7,(8)
- June, 2008-6,(12)
- May, 2008-5,(14)
- April, 2008-4,(12)
- March, 2008-3,(17)
- February, 2008-2,(10)
- January, 2008-1,(16)
- December, 2007-12,(6)
- November, 2007-11,(4)
|
|
|
Blog posts for the month of November,2015.
|
|
| Always-on failover links | 11/18/2015 7:00:21 AM |
| SQL Server loses ntfs file permissions on MDF and LDF | 11/18/2015 6:54:11 AM |
Ever have that annoying problem where when you detach a database or stop sql and then go to copy / move the files and find you don't have permissions to the files ? ACL (access control list) and NTFS permissions can be very annoying but they are manageable.
I found a nice script for "take ownership", right click menu and it worked nicely, allowed me to take ownership and then add the sql service account back to the ACL for the file(s) and all was good.
Windows Registry Editor Version 5.00
; Created by: Shawn Brink ; http://www.sevenforums.com ; Tutorial: http://www.sevenforums.com/tutorials/1911-take-ownership-shortcut.html
[-HKEY_CLASSES_ROOT\*\shell\runas]
[HKEY_CLASSES_ROOT\*\shell\runas] @="Take Ownership" "HasLUAShield"="" "NoWorkingDirectory"="" Position="middle"
[HKEY_CLASSES_ROOT\*\shell\runas\command] @="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F /c /l" "IsolatedCommand"="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F /c /l"
[-HKEY_CLASSES_ROOT\Directory\shell\runas]
[HKEY_CLASSES_ROOT\Directory\shell\runas] @="Take Ownership" "HasLUAShield"="" "NoWorkingDirectory"="" Position="middle"
[HKEY_CLASSES_ROOT\Directory\shell\runas\command] @="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t /c /l /q" "IsolatedCommand"="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t /c /l /q"
[-HKEY_CLASSES_ROOT\dllfile\shell\runas]
[HKEY_CLASSES_ROOT\dllfile\shell\runas] @="Take Ownership" "HasLUAShield"="" "NoWorkingDirectory"="" Position="middle"
[HKEY_CLASSES_ROOT\dllfile\shell\runas\command] @="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F /c /l" "IsolatedCommand"="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F /c /l"
[-HKEY_CLASSES_ROOT\Drive\shell\runas]
[HKEY_CLASSES_ROOT\Drive\shell\runas] @="Take Ownership" "HasLUAShield"="" "NoWorkingDirectory"="" Position="middle"
[HKEY_CLASSES_ROOT\Drive\shell\runas\command] @="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t /c /l /q" "IsolatedCommand"="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t /c /l /q"
[-HKEY_CLASSES_ROOT\exefile\shell\runas]
[HKEY_CLASSES_ROOT\exefile\shell\runas] "HasLUAShield"=""
[HKEY_CLASSES_ROOT\exefile\shell\runas\command] @="\"%1\" %*" "IsolatedCommand"="\"%1\" %*" |
| Copy all files created today | 11/18/2015 6:31:08 AM |
| Rename Files replace a string | 11/18/2015 6:28:38 AM |
In the process of restoring all sql server backup files from a directory I had to rename them all and replace a date string with another string of _db_ , I have an existing script that will restore all files from a directory but the files have to meet the _db_ naming convention. I found a nice power shell script to do this rename for me from this blog post, http://blogs.technet.com/b/heyscriptingguy/archive/2013/11/22/use-powershell-to-rename-files-in-bulk.aspx
Get-ChildItem -Filter "*current*" -Recurse | Rename-Item -NewName {$_.name -replace 'current','old' }
Use PowerShell to Rename Files in Bulk
Summary: Learn how to use Windows PowerShell to rename files in bulk.
Microsoft Scripting Guy, Ed Wilson, is here. Matt Tisdale is back today with another solution to a situation at work…
I received a call from a gentleman named Cristofer this afternoon. He had a business need and he heard from someone that Windows PowerShell could help. I told him that I am sure Windows PowerShell can help—and that was before I even heard the question.
His immediate need was to rename almost 250 files that are located in various folders on the file system. He needed to find all files with a specific character string in the name and replace this character string with a new character string. For example purposes, let's say he needed to find all files with "current" in the name and replace "current" with "old".
I have never attempted this specific task, but by using Get-Command and Get-Help, we were able to find exactly how to do this in a couple of minutes. Assuming we need to find all files located under C:\temp (including all subfolders) with "current" in the name and rename them using "old" in place of "current", here are the steps.
- Open Windows PowerShell.
- Navigate to C:\temp.
- Run the following Windows PowerShell command:
Get-ChildItem -Filter "*current*" -Recurse | Rename-Item -NewName {$_.name -replace 'current','old' }
4. Sit back and let Windows PowerShell do all of the work for you.
Anyone who has access to modify the files and is running Windows 7 can follow these steps. No special tools or elevated rights are required.
Let's pick the command apart and explain each piece.
- Get-ChildItem -Filter "*current*"
Finds all files with the string "current" anywhere in the name.
Instructs Get-ChildItem to search recursively through all subfolders under the start point (the current directory where the command is run from).
Instructs Windows PowerShell to take each item (object) found with the first command (Get-ChildItem) and pass it to the second command (Rename-Item)
Renames files and other objects
- {$_.name -replace 'current','old' }
Tells Rename-Item to find the string "current" in the file name and replace it with "old".
For an added bonus, I also recommended that Cristofer use the -WhatIf parameter with this command on his first run to get an output that shows what the command will do before he actually pulls the trigger. Using -WhatIf will tell Windows PowerShell to run the Rename-Item portion of this command in Report Only mode. It will not actually rename anything—it will simply show what files were found that match the filter criteria and what each new name would be. Here is the command with the -WhatIf parameter added.
Get-ChildItem -Filter "*current*" -Recurse | Rename-Item -NewName {$_.name -replace 'current','old' } -whatif
Unfortunately, when we use –WhatIf, we cannot send our output to a text log file. If you need a log file that shows the results of using -WhatIf, you can follow these steps:
- Open Windows PowerShell.
- Run Start-Transcript.
- Run your command (including the -WhatIf parameter).
- After the command completes, run Stop-Transcript.
- Note the location and file name of the transcript file, and open this file to see the results.
It is always fun to solve business challenges with Windows PowerShell commands. Cristofer said he will probably need to use these commands for renaming 1000+ files in the near future, and he will share this process with other members of his team. Imagine how much "fun" it would be to rename all of these files manually or with some clunky old batch file. No thank you. I will stick with Windows PowerShell.
Keep the requests coming in. I always enjoy helping fellow employees find ways to be more efficient and save time and money.
~Matt
Thanks again, Matt, for sharing your time and knowledge. This is awesome.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy |
| Remove multiple disks at once from Cluster Manager | 11/7/2015 8:33:42 AM |
It sure would be nice to be able to select multiple disks at once and delete them from cluster manager.
But you can't, BUT you can use power shell to remove them all at once.
Get-ClusterResource | where {$_.Name -like "Cluster Disk *"} | Remove-ClusterResource -force
Thanks to Vipin for this script. |
|
Blog Home
|
|
|