If you would like to automate your Windows Server Backup workflows, you can use the following Powershell snippet. 1. Install Windows feature (if not already installed) Firstly check if the Windows Server Backup feature is installed on the Windows Server machine. The easiest way is to execute the following statement in a Powershell Window which… Continue reading Powershell how to automate Windows Server Backup tasks
Category: Powershell
Powershell check if .NET executable is x86 or x64
Do you want to check if a (.NET) assembly has been built for x86 or x64? You can do this via the following Powershell snippet. Simple run the following command in a Powershell window: In the output above you should look for this line: In this case this assembly is built for 64-bit platforms (AMD64).… Continue reading Powershell check if .NET executable is x86 or x64
Powershell copy files from directory excluding certain extensions
In Powershell you can use the pipe symbol “|” to chain certain commands together. This enables you to make powerful scripts. One example how you can use this is to recursively copy files from one location to another, but exclude certain files based on the filename or extension. Example 1: copy all files from one… Continue reading Powershell copy files from directory excluding certain extensions
Powershell open a new file explorer window in a specific location
In order to open a new file explorer window in a specific location from Powershell, you can use the following very simple command in a Powershell script: This can come in handy in certain cases. For example if you are making a script that places files in a certain location, and you then want the… Continue reading Powershell open a new file explorer window in a specific location
Powershell pass arguments to script
If you wish to call a Powershell script with a certain argument (e.g. a directory), you can do so with the following example: Snippet: add expected argument to script Providing the argument Typing manually when prompted by calling script If you now call the script from the command line with the code above, you should… Continue reading Powershell pass arguments to script
Powershell connect with remote computer
With Powershell you are able to connect to remote computers and execute statements. For example this allows you to start and stop IIS on a remote webserver, install/uninstall Windows Services when deploying new software and more. Snippet: connect to a remote computer Remote execute examples Below you will find a few examples of things to… Continue reading Powershell connect with remote computer
Telnet equivalent in Powershell to test if port is reachable
Powershell doesn’t come with telnet by default, however you can use the following command to quickly connect to a TCP server in a Powershell window. 1. Test-NetConnection The simplest option is to use the command “Test-NetConnection”. With this command you can specify a computername (or IP address) and port to check if a connection can… Continue reading Telnet equivalent in Powershell to test if port is reachable
Powershell script run as administrator / elevated mode check
If you created a Powershell script which needs administrator permissions, and you try to run it as a normal user (e.g. when simply double clicking the .ps1 file), you might see errors such as “Access denied”. To fix this, you will need to run the Powershell script as Administrator. However this usually means you need… Continue reading Powershell script run as administrator / elevated mode check
Powershell error: the file is not digitally signed. You cannot run this…
If you are trying to run a custom Powershell (.ps1) script, you might see the following error: This problem is caused by the default Execution-Policy which prevents you from running custom Powershell scripts. Solution: change execution policy To fix this, open up a Powershell prompt as an Administrator: Then in the Powershell prompt, enter the… Continue reading Powershell error: the file is not digitally signed. You cannot run this…
How to delete files with Powershell
1. Delete a folder and everything in it With Powershell you can easily delete folders and files with the command line. Use the snippet below to first check if the folder exists, and if it does, delete it. Note: it is always a good practice to check if the folder exists before trying to delete… Continue reading How to delete files with Powershell