AzureRm is dead, long live Az!

December 2018 saw the first stable release from Microsoft of the “Az” module. The Az module replaces AzureRm which has now receive bug fixes only, any new features and/or development will take place for Az. To check the latest version of Az, take a look at this page in the Powershell Gallery. The new Az module allows for the cross-platform […]

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: [email protected]() 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 root of my C: drive called test, I then removed […]

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 makes sense. We use the Get-ChildItem and the -Recurse option […]

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 based on the delimiter (‘\’). This array is dynamically sized […]

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 Both options result in the same outcome, notepad is opened […]

Using Powershell to access Oracle

Before trying to access an Oracle database with Powershell it is necessary to have the Oracle Data Provide for .Net available, the most common way to get this is to install the Oracle client. If you are already interacting with Oracle databases then you will likely have a version of the client installed, if not use the link below to […]

Enabling Powershell-ISE in Windows Server

To use PowerShell-ISE (Integrated Scripting Environment) on a Windows 2008 R2 server it is necessary to first enable it. There are just a few simple steps to take to do this… Run PowerShell with Administrator privileges (right-click PowerShell -> Run as administrator). Import the Server Manager PowerShell module. Next, add the Powershell-ISE feature. That’s all there is to it! The result […]

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 the date format will give you, as example, 2016-06-22 as […]