Monday, September 30, 2019

Windows command line string search

If you find yourself using the Windows command line and are overwhelmed by the number or rows a command returns, you can filter the output so it only returns rows that match your criteria.  To do this you use the findstr command:  (https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/findstr)

To match on a simple string you use the /C switch and pass the string

example:  netstat -oan | findstr /C:"abcd"

this will return all rows with "abcd" in it

If you want to be more fancy you can use the switch /R and it will evaluate the string you are searching for as a regular expression.

Wednesday, July 10, 2019

Powershell Scheduled Tasks

Here is a script to create a scheduled task via powershell and run as a specific user.  This can be useful when using a Core server that you can't create the scheduled task through the GUI, or if you want to add the scheduled task to source control.

<#example of how to do this with the schtasks command
schtasks /create /tn "TaskName" /tr "powershell.exe -file c:\scripts\script.ps1" /sc DAILY /st 22:00:00 /ru "System"
#>

$name = 'TaskName'
$runAt = '10:00 PM'
$exe = 'powershell.exe'
$params = '-file script.ps1'
$location = 'C:\scripts\'

<# if you want, you can delete an existing task.
Unregister-ScheduledTask -TaskName $name -TaskPath $taskPath -Confirm:$false -ErrorAction:SilentlyContinue  
#>


$action = New-ScheduledTaskAction -Execute "$exe" -Argument "$params" -WorkingDirectory "C:\scripts"
$trigger = New-ScheduledTaskTrigger -Daily -At $runAt
Register-ScheduledTask -TaskName $name -TaskPath "\" -Action $action -Trigger $trigger -User 'System'  | Out-Null


This will create a task that runs the powershell script c:\scripts\script.ps1 every day at 10 PM and it will run as the System user.

Thursday, May 16, 2019

Windows Update commands

If you want to tell Windows Update to kick off a scan for new updates from the command prompt there is a command you can use.  For systems prior to 2016 you can use:

wuauclt /detectnow

For systems after 2016 you will need to use:

usoclient startscan

Wednesday, April 3, 2019

Installing RSAT on 1809

Starting with Windows Server 1809 RSAT is no longer a downloadable option.  We see this on the Microsoft download page here.


So how do we install the tools? The easiest way I found to do this was to click on the start menu and search for "Apps & features".  On this screen click on Manage optional features.  This screen will list all the items that are already installed.  To add a new feature simply click on "Add a feature.  I installed the following two:

Once the feature has finished installing you can find the tools on the start menu, under Windows Administrative Tools.




Wednesday, February 27, 2019

SQL Server install troubleshooting

A while back I spun up a VM with Fedora installed so I could install the SQL Server 2017 Preview for Linux.  I found it really easy to setup and get going.  I was amazingly simple.  I don't recall the exact order of events but I believe I did an update to the OS and it broke SQL Server.  I attempted to remove SQL Server and install the RTM version.  But I never had much luck. 

Out of frustration I spun up a new VM and installed the RTM version to play around with.  Now that it is a year later I thought I would check out that old VM and see if I can get it working.  I figure it would be a good learning opportunity to learn a few things about Linux and to get familiar with the OS.  Here are my pertinant notes from this endeavor.

To start out I checked the status of the current install. 

systemctl status mssql-server

The result was that the service wasn't running.  So trying to restart the service like so also failed:

systemctl start mssql-server

The status was 127 which indicates that the command wasn't found.  I checked the path for Sql Server and it was present.  I had a hunch that a dependency was missing.  So I tried to do verbose logging for systemd, but don't think I was successful.

systemd-analyze set-log-level notice

I did check the logs with the following command.  Note the parameter "--since 20:00" means only entries since 8:00 PM.  My last attempt to start the service was at approximately 8:10 PM.

journalctl --since 20:00

I noticed a line that said a no such file or directory, however it was wasn't for sqlservr.  Instead it was for libc++.so.1


I wasn't sure why this was missing, so I ran.  So after doing some digging I realized there was a package that was named similar. So I gave installing it a try.

yum install libcxx


After installing this package SQL Server was able to successfully run.


However I was still not able to connect.  I checked the firewall:

firewall-cmd --list-ports

Port 1433/tcp was listed so it wasn't the host firewall.  I still couldn't connect so I checked the journal and found the following


So the system thought the process was running but it wasn't, it failed.  Doing a quick reinstall fixed it.

sudo yum remove mssql-server
sudo yum install mssql-server
sudo /opt/mssql/bin/mssql-conf setup

After that I was able to connect.  Yay!