How to list files last modified in the last 30 days via Powershell. Run these commands in the directory containing the files to filter.
$lastModAge = (get-date).adddays(-30); Get-ChildItem | Where { $_.LastWriteTime -gt $lastModAge }
How to list files last modified in the last 30 days via Powershell. Run these commands in the directory containing the files to filter.
$lastModAge = (get-date).adddays(-30); Get-ChildItem | Where { $_.LastWriteTime -gt $lastModAge }
I keep finding the need to find an open IP address for a new server, and I get tired of searching manually. I am also not patient enough for a ping sweep, so I created a nslookup sweep with powershell. The nslookup sweep just looks through a subnet to find the first address without a dns entry. The next step just requires you to ping the address to insure it’s not being used. Check out this post for a TCP Port Scanner in PowerShell.
$i = "1";
$subnet = "192.168.1";
while ( $i -lt 255 ) {
$ipaddr = "$subnet.$i"
$nsResult = nslookup $ipaddr 2>&1 | select-string "Name";
if ( $nsResult ) {
$i++;
}else{
echo "$ipaddr is available";
$i = "256";
}
}
Below are some interesting sets of PowerCLI commands that will give you more information on your VM’s hard drives and your datastores.
The below will give you the total allocated hard drive space of all the VM’s in a cluster.
Get-Cluster "Cluster Name" | get-vm | Get-HardDisk | %{ $vmCapacity += $_.capacityKB }
$vmCapacity
The below will give you the Total Capacity, Free Space, and Usage of your datastores.
Get-Datastore | %{ $datastoreFreeSpace += $_.FreeSpaceMB }
Get-Datastore | %{ $datastoreTotalCapacity += $_.CapacityMB }
$datastoreUsageTotal = $datastoreTotalCapacity - $datastoreFreeSpace
write-host "Total Capacity: $datastoreTotalCapacity MBs"
write-host "Total Free Space: $datastoreFreeSpace MBs"
write-host "Total Usage: $datastoreUsageTotal MBs"
Step one, make sure you have a KMS server and you have set it up for Office 2010. If not, check out my post on setting up your KMS server Office 2010.
Activating Office 2010 with your KMS Server
Open an elevated command prompt on your client with Office 2010 installed.
Change directory into your Office installation directory cd “C:\Program Files\Office 2010\”
Then change directory into office14 cd office14\
Now run ospp.vbs /sethst:kmsserver.yourdomain
The above command set’s your KMS Server (replace kmsserver.yourdomain with your server’s name)
Then run ospp.vbs /act
The above command activates your Office 2010 with your KMS server
Now close your command prompt, you are good to go.
Log into your Windows Server 2008 R2 KMS Server or server to be.
Download KeyManagementServiceHost.exe file from the MS Office KMS Host License Pack page
Now run the KeyManagementServiceHost.exe file.
Enter your KMS Host Key when it asks.
Then just continue with activation when prompted.
More information on KMS Servers and Office 2010 can be found here.
Create container for logs:
New-EventLog -logname 'Event Log Name' -source 'logsourcename'
Note: Must be run in elevated powershell window
Command to create event log:
Write-EventLog -computername localhost -logName 'Event Log Name' -EventID 5000 -Message "Hello World!" -EntryType Information -source logsourcename
Finding newly created event log: Open Server Manager Expand Diagnostics Expand Event Viewer Expand Applications and Services Logs Click on the container that you named using the -logName parameter Your Logs should be in the right pane.
Here is a quick one liner to show how you can pull DNS information and filter it using powershell. Replace zonename with the name of the zone you want to pull information from and replace computername with the name of the computer you are searching for.
dnscmd.exe /zoneprint zonename | where{$_ -like "*computername*"}
Below is a script I wrote to help identify computers that had a trust relationship issue with the Active Directory domain. This script searches for an event on the domain controller that you run this on(please use caution). It looks for an event that has an event ID of 5723, and that happened today. Then it pulls the name of the computer identified in the event. This script allows me to know and address the computers with issues before I get a support call.
#Get todays date;
$today = get-date -uformat "%m/%d/%Y";
#Create array for computers;$cName = @();
#Pull events from system event log that are errors;$events = Get-EventLog -log system -entrytype Error
#Filter the events where eventID is 5723 and the time written is today;
$events = $events | where {
$_.eventID -eq 5723 -and $_.timewritten -like "$today*"
}
#Select computer name property;$events = $events | select ReplacementStrings;
#Add computer names to array;$events | foreach { $cName += $_.replacementstrings[0];};
#Print array leaving out duplicates$cName | select -uniq;
Creating a scheduled task to run a batch file at startup is a very easy process, but if you miss a certain setting it can be very frustrating. I have a quick how-to on creating a scheduled task that runs a batch file at startup, below. This how-to was created using a Windows 2008 R2 Server, if you notice variations on other versions of Windows please comment to help others. Thank you.
Type in a Name and Description and click “Next“
Click the radio button for “When the computer starts” and click “Next“
–
Make sure “Start a program” is marked and click “Next“
–
Type in the location of the script under “Program/script” and the folder the script is in in the “Start in (optional):” textbox
Click “Next“
–
Click “Finish“