Category: Powershell
-
Create a new Resource Group
Three ways to create a resource group in Azure.
-
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 received 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…
-
Create a http to https URL redirect in IIS with Powershell
If you are hosting a website on IIS and would like your visitors to connect securely via https, whether they specify that in their browser or not, then there are a few steps you need to take. First of, you need to install your SSL certificate into IIS. Then install the URL Rewrite IIS module/extension…
-
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 root of my C: drive…
-
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…
-
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 (‘\’).…
-
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…
-
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…
-
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…
-
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…