Check for folders and files where access is denied with Powershell

The following script is from another blog that was slightly adapted by someone who left a comment there: $errors=@() gci -recurse -Path “C:\test” -ea SilentlyContinue -ErrorVariable +errors | Out-Null $errors.Count $errors | select -expand categoryinfo | select reason,targetname | export-csv -NoTypeInformation -Delimiter “;” ErrorList.csv I created a folder on the Continue Reading

Check and amend the read only attribute with Powershell

We can use the following to iterate through a series of folders and check the read only status of the files: $Directories = “C:\drop\Test Complete\Dev\Global\Master\SeleniumTests” gci -Recurse -Path ${Directories} | select fullname,isreadonly It is not necessary to specify the list of directories as a variable but for my use it Continue Reading

Split a filepath with PowerShell

This is a relatively short post as the process is simple but may be required in more complex scenarios. $dirArray = (“C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA”).Split(‘\’) foreach ($dir in $dirArray) { $dir } By calling the Split function we get a zero-based array ($dirArray) containing each element of the supplied string Continue Reading

Open and close a process with Powershell

Short script to open notepad.exe (can be any process you want to open) on either your local machine or a remote machine and then kill the process. Option 1 C:\PSTools\PsExec.exe cmd /c start notepad.exe Start-Sleep -s 10 C:\PSTools\PsKill.exe -accepteula notepad.exe Option 2 C:\PSTools\PsExec.exe notepad.exe Start-Sleep -s 10 C:\PSTools\PsKill.exe -accepteula notepad.exe Continue Reading

Adding the date to a filename with Powershell

Following on from my previous post, Write to a text file using Powershell, I found it useful to be able to include the date into the log filename. $LogFile =”C:\PsTools\Method01-$(get-date -f yyyy-MM-dd).log” $DateTime = Get-Date Write-Output $DateTime “Performing some operation” | Add-Content $LogFile You can see from this script that Continue Reading