Category: Tools
Restarting a service with Task Scheduler
Some times you need to scheduler a restart of services on servers or computers, and I used to do this via a batch job, that I called from Task Scheduler, but..
I found a much easier way of doing this, just create a new task, and add the Actions like bellow.
NET as the program, and START/STOP “SERVICENAME” as the argument
and voila, there it is 🙂
Create #HASHED password file for PowerShell use
Connect to Azure/Office365 based on encrypted txt file
$encrypted = Get-Content “D:\Scripts\Azure_Encrypted_Password.txt” | ConvertTo-SecureString
Get MAC address from remote computer
In some settings you need to get a remote computers MAC addresses. And you don’t have access to it physically.
- Open a CMD window with you Administrative user (one that has admin access to computer objects)
- Ping the computer name (to get IP)
f.eks: PING COMPUTERNAME
Wait for reply.. 192.168.25.25 - type inn getmac /s 192.168.25.25 /v
Now you get a list with the MAC addresses.
Select Azure Subscription to work with
When you have a larger organisation, you will have several Azure Subscriptions to work against. So here is how you switch.
1. Open Powershell
2. Type in: Add-AzureRmAccount
(in pop-up enter admin id and password)
3. It will list up the subscription you are connected to when you have authenticated
4. Type in: Get-AzureRmSubscription
(will list out all your subscriptions)
5. Find the Subscription you want to connect to
6. Type in: Select-AzureRmSubscription -SubscriptionId “ENTER THE SUBSCRIPTION ID”
You can choose SubscriptionName too, but I prefere SubscriptionID
Count directory Objects in Active Directory
Some times you need to find out how many directory Objects you have in your AD.
A quick way of getting this done is to use the following PowerShell string
Get-ADObject -Filter {name -like ‘*’} -SearchBase ‘CN=Schema,CN=Configuration,DC=sameie,DC=COM’ -ResultSetSize $null | Measure-Object >c:\tmp\object_dump.txt
This will dump the information into a easy to read text file
Now you know how many Objects you have.
Get system uptime
December 8, 2017
Powershell, Server, Tips and Trix, Tools, Windows
No Comments
vincent
We all have our own ways of finding a servers / computers uptime.
But I thought I’d share my favorite way:
function Get-SrvUptime
{
$operatingSystem = Get-WmiObject Win32_OperatingSystem
[Management.ManagementDateTimeConverter]::ToDateTime($operatingSystem.LastBootUpTime)
}
powershellservertipstipstrixwindows