IF OBJECT_ID(N 'tempdb..##err') IS NOT NULL BEGIN
DROP
TABLE ##err
END CREATE TABLE ##err (
[LogDate] DATETIME2,
[ProcessInfo] VARCHAR(255),
[Text] VARCHAR(max)
) INSERT INTO ##err
EXEC sp_readerrorlog
SELECT
*,
CASE WHEN ISNUMERIC(
LTRIM(
RTRIM(
SUBSTRING(
TEXT,
CHARINDEX('approximately ', TEXT, 0) + 14,
CHARINDEX(
' seconds',
SUBSTRING(
TEXT,
CHARINDEX('approximately ', TEXT, 0) + 14,
9999
),
0
)
)
)
)
) = 1 THEN CAST(
LTRIM(
RTRIM(
SUBSTRING(
TEXT,
CHARINDEX('approximately ', TEXT, 0) + 14,
CHARINDEX(
' seconds',
SUBSTRING(
TEXT,
CHARINDEX('approximately ', TEXT, 0) + 14,
9999
),
0
)
)
)
) AS INT
) ELSE NULL END AS TimeLeftinSeconds,
CASE WHEN ISNUMERIC(
LTRIM(
RTRIM(
SUBSTRING(
TEXT,
CHARINDEX('approximately ', TEXT, 0) + 14,
CHARINDEX(
' seconds',
SUBSTRING(
TEXT,
CHARINDEX('approximately ', TEXT, 0) + 14,
9999
),
0
)
)
)
)
) = 1 THEN CAST(
LTRIM(
RTRIM(
SUBSTRING(
TEXT,
CHARINDEX('approximately ', TEXT, 0) + 14,
CHARINDEX(
' seconds',
SUBSTRING(
TEXT,
CHARINDEX('approximately ', TEXT, 0) + 14,
9999
),
0
)
)
)
) AS FLOAT
) / 60 ELSE NULL END AS TimeLeftinMinutes
FROM
##err
ORDER BY
Logdate DESC IF OBJECT_ID(N 'tempdb..##err') IS NOT NULL BEGIN
DROP
TABLE ##err
END
Sometimes, you just can't reset your password.
Sometimes, your company doesn't care why you can't.
Desperate times call for desperate measures;
The following posh script can be run on any domain computer by a domain admin and will reset the password expiration for a given user (the logged-in user by default).
This will simulate the password being reset.
I encapsulated the code in Invoke-Command statements so it will run against a DC, then it forces replication after it's done.
cls
$ls = ($env:LOGONSERVER).TrimStart("\\").ToString() # Get Logon Server
$forestpdc = Invoke-Command -ComputerName $ls -ScriptBlock {Get-ADForest | Select-Object -ExpandProperty RootDomain | Get-ADDomain | Select-Object -Property PDCEmulator}
$localdomainpdc = Invoke-Command -ComputerName $ls -ScriptBlock {Get-ADDomain | Select-Object -Property PDCEmulator}
$sam = $env:UserName.ToString() #change this value to reset another user
$sam2 = Read-Host "User name to reset: [default: $sam]"
if($sam2-eq ""){$sam2=$sam}
$cmd = "Get-ADUser -Filter {SamAccountName -eq ""$sam""}"
$user = Invoke-Command -ComputerName $localdomainpdc.PDCEmulator -ScriptBlock {Get-ADUser -Filter {SamAccountName -eq $Using:sam2}}
Invoke-Command -ComputerName $localdomainpdc.PDCEmulator -ScriptBlock {$uObj = [ADSI]"LDAP://$Using:user"
$uObj.put("pwdLastSet", 0)
$uObj.SetInfo()
$uObj.put("pwdLastSet", -1)
$uObj.SetInfo()}
write-host "Syncing the local domain..."
Invoke-Command -ComputerName $localdomainpdc.PDCEmulator -ScriptBlock {(Get-ADDomainController -Filter *).Name | Foreach-Object {repadmin /syncall $_ (Get-ADDomain).DistinguishedName /e /A | Out-Null}; Start-Sleep 10; Get-ADReplicationPartnerMetadata -Target "$env:userdnsdomain" -Scope Domain | Select-Object Server, LastReplicationSuccess}
if($localdomainpdc.PDCEmulator-ne $forestpdc.PDCEmulator){
write-host "Syncing the forest..."
Invoke-Command -ComputerName $forestpdc.PDCEmulator -ScriptBlock {(Get-ADDomainController -Filter *).Name | Foreach-Object {repadmin /syncall $_ (Get-ADDomain).DistinguishedName /e /A | Out-Null}; Start-Sleep 10; Get-ADReplicationPartnerMetadata -Target "$env:userdnsdomain" -Scope Domain | Select-Object Server, LastReplicationSuccess}
}
$pls = Invoke-Command -ComputerName $localdomainpdc.PDCEmulator -ScriptBlock {(Get-ADUser -Filter {SamAccountName -eq $Using:sam2} -properties PasswordLastSet).PasswordLastSet}
write-host "Sync done..."
write-host "Password last set: $pls"
Despite my initial requests to my management at the time to look at a wonderful ticketing system called IssueTrack which I had deployed at my previous employment, I was overruled and now my company uses a ticketing solution that is installed as an Azure application called Samanage (which was just purchased by SolarWinds). It is an adequate solution, despite it being a little weak in the area of workflow automation and form customization.
One thing that has bothered me since the initial deployment is the multi-step process for assigning newly created users from AD on-prem to the Azure application because we wanted to limit the authorized users to only real "person" accounts. The only other alternative was to all users to sync from Azure AD, which would have created a bit of a mess.
To deal with this, I created a PowerShell script that fetches the members of a group, checks that list against a list of assigned users for the application, then assigns any new users to that application.
Then I created a task scheduler task that runs once every half hour that runs the script to keep everything in sync.
The code for the script, as well as an application that encrypts credentials, are attached. Keep in mind, when encrypting credentials, you must run the "BuildCreds.exe" application on the machine on which you plan to use them. The ConvertFrom-SecureString command is machine specific.
Hey All,
Wrote a quick script for Made2Manage to check both which users have more than one user license occupied (total_session_count) and also if a user has a session that is chewing up a bunch of resources (total_screen_count) including what their machine name is (client_name) and which server they are connected to for those of you with more than one application server (server_name)
Hey All,
I have a stored procedure scheduled to run a job every ten minutes that I was doing some testing on.
It usually takes about a minute to run, so when I'm testing it out, I like to run it on the 5th minute of every ten minute period to be sure that it doesn't interfere with the jobs run.
To make sure this happens every time, I created a quick snippet to find the current offset needed in a WAITFOR statement so it'll run the next time the time ends in a 5.
This doesn't account for seconds intentionally because I want there to be no delay if the GETDATE() statement returns a value in the 5th minute.
Hi everyone,
This is just a quick script for a scalar function to return the first day of the current week.
With a little modification you could add a parameter so you could pass it a date and have it return the first day of that week.
It's also easy to adjust the numeric value for the days in the event your week starts on Sunday.
Have fun!
CREATE FUNCTION F_wtd () |
So, in addition to my life as an IT guy, I also have a strong interest in component level electronics.
My parents had to replace many household electronic items having been victims of my curiosity and a screwdriver.
Today on the healing bench is a very nice piece of kit from Logitec;
The Logitech Smartdock for Skype for Rooms v2.
What the heck is this thing and why did you take it apart.
Good Question. A little while back, Microsoft finally decided to patch a hole in its Skype for Business offering when it came to organizations like the one I work for, who needed a meeting space S4B enabled. Up to this point, there were some previous generation options, made for Lync, which worked, but were old enough to be out of hardware support and only available secondhand, or a rigged together solution with a small PC like a NUC strapped to the back of a large wall mounted TV. I have two issues with the latter; first is that the S4B desktop app doesn't work well as a room system and required some type of keyboard mouse combo left on a table, which someone will inevitably log out, which creates support weight for the IT staff. The second is that if someone needs to bring their laptop in to share, they'd have to start a meeting on the room PC, then join it on their laptop and remember to join without audio, which never happened, and you'd hear a high pitch squealing of feedback from anywhere in the office, which is like the IT siren.
This thing fixes both of those things.
Basically, it's a dock for a Surface Pro 4 (or a Pro 3 if you have a pair of side cutters) with a built-in HDMI capture card, which is then connected to a wall mount TV.
Once the software is installed, the tablet becomes a "Room Control Panel" and the TV is the main output.
It allows users to start scheduled meetings, schedule a meeting, or display content, local or remote, with the touch of a screen.
It makes using the conference room for users so simple, I can't imagine anything they could do to make it any easier. Even displaying content is as easy as plugging in an HDMI cord to your laptop and clicking the "Present" button.
If you have conference rooms and plan to use Skype for Business to connect them, this is the only way to fly.
Cool story Josh, why did you take it apart if it's so awesome?
Two reasons;
First, I have seen many third-party devices made for the Surface Pro. For all of the products I've seen, I haven't ever seen a third party device that uses the Microsoft proprietary Surface dock connection. There are many knocks of mag chargers, but none that use the data bus on the connector. In fact, the only two devices that I can think of that use the data connection are the surface pro 3 and surface pro 4 docks. This uses that data connection and is also third-party. I wanted to know if it was possible that this thing was just a Microsoft Surface dock in a fancy plastic case.
Second, and the more interesting one, is that this dock isn't really what makes this system awesome, it's the software, which is made by Microsoft and is freely available, but requires a Skype for Rooms v2 compatible device to work. The "requires a Skype for Rooms v2 compatible device to work" part is not a real limitation, it actually works fine without it, it just won't complete setup unless it's plugged into one during install.
Stay tuned for more regarding how to get the software working without the dock!!!
Let me know if there are any images of something on the doc not pictured here (This is just the highlight reel!)
|
If you're like me, you often run into a situation where Microsoft has been kind enough to solve an issue or add functionality to an obvious gap in a previous version (like the function ISNUMERIC() ), but you are unable to upgrade to the newer SQL version for one of a never-ending list of reasons ("the application only supports SQL 2000", "there's no money in the budget for that", "why fix what isn't broken", "the moon is full", "I ate bad sushi yesterday and i'm just not 'feelin it' today").
At any rate, I needed to use the STRING_SPLIT function available in 2016 forward on a 2008 R2 box, so I wrote code that emulated that table-valued function and can be used interchangeably.
I also added a piece that allows for escaped delimiters using \delimiter\, so you may find utility for this even in a SQL 2016 instance.
Running this script installs the function in MASTER and then creates a synonym in each database as well as MODEL, so any new databases will have it as well.
Enjoy!
USE master |
This is a public service announcement:
It is critical that when you extract the month from a date with a two digit conversion (between October and December) and put it into a variable, you must define the length of the variable, or it will truncate the second digit.
If you do not, it will return a 1 and not the correct digit value.
Running this code:
DECLARE @ldBegDate AS DATE = '10-09-2018' |
Produces this output.
@ldBegDate = 2018-10-09
@inline_month_no_len = 1
@inline_month_w_len = 10
@inline_month_no_trim = 1
@inline_month_no_trim_w_len = 10
@the_right_way = 10
No Variable = 10
You've been warned.
I've got a secret. Don't tell anyone.
I still use the command line for everything; I only use PowerShell when I can't figure out how to do something with a batch script.
Seriously, don't tell anyone.
Keep it real; I'm not the only one.
One of the things that has always bothered me about the MOVE command is that when moving a whole directory, if it encounters a problem with one of the files, the whole thing fails.
I wrote a little application to deal with that. I'm using it to move my SQL transaction logs and backups from one location to another.
Basically, it gets a list of files from a path (including UNC) and moves them one at a time and just keeps going if it hits a file it has trouble with.
Just download it!
If you’ve been in IT long enough, chances are that you’ve had to deal with disabling an account or changing a password without knowing if it's running a service somewhere.
I’ve always struggled with this, and have employed a few different methods:
Both of these options stink.
I’ve spent quite a bit of time on the Google and Bing machines looking for someone who had a simpler and cleaner solution to this problem to no avail.
Given that I've caused dealt with this at multiple jobs, it's surprising that no one else admitted guilt has posted a solution to this problem.
So here it is (source and an executable version below)….
cls ##clear the screen Write-Host "Starting Service Credential Check..." $GetDesktopPath = [Environment]::GetFolderPath("Desktop") ## get the path to save the files Write-Host "Saving files to " $GetDesktopPath "..." $name = Read-Host -prompt 'Run for domain (blank = current domain)...' $myDomain = if ($name -eq ""){((Get-WmiObject Win32_ComputerSystem).Domain)} elseif ($name -eq $null){((Get-WmiObject Win32_ComputerSystem).Domain)} else {$name} $ldapaddress = "LDAP://" + $myDomain $ADSearch = New-Object System.DirectoryServices.DirectorySearcher $ADSearch.SearchRoot = $ldapaddress.ToString() $ADSearch.SearchScope = "Subtree" $ADSearch.PageSize = 8000 $ADSearch.Filter = "(objectCategory=Computer)" $colResults = $ADSearch.FindAll() $computers = $colResults.GetDirectoryEntry() $servers = $computers | Where-Object {$_.operatingSystem -Like "*Server*"} #| select -last 50 $servers2 = $servers.dNSHostName | where { Test-Connection -ComputerName $_ -Count 1 -Quiet } $services = gwmi win32_service -computer $servers2 | select SystemName,DisplayName,StartName,State,StartMode | Sort-Object StartName,SystemName,DisplayName $services | ConvertTo-HTML -Property SystemName,DisplayName,StartName,State,StartMode,InstallDate > ([Environment]::GetFolderPath("Desktop")+"\all_services.html") $services | Where-Object {$_.StartName -NotLike "*NT Authority*" -and $_.StartName -NotLike "*NT Service*" -and $_.StartName -NotLike "*locals*"} | ConvertTo-HTML -Property SystemName,DisplayName,StartName,State,StartMode,InstallDate > ([Environment]::GetFolderPath("Desktop")+"\nonsystem_services.xls") Write-Host "The files have been saved..." Write-Host "Exiting..."
Hi all,
Back in the FoxPro days of M2M, when the table was still named just INMAST, there were several fields present on the item master which are now calculated such as on-hand quantities. To bridge the gap, when they removed the fields the developers did us a solid and renamed the item master INMASTX then created a view as a stand-in for the original INMAST. Inside that view, they didn't just calculate the since removed fields, but they created SQL functions to do the calculations.
Turns out, that those functions have a bunch of useful parameters that are generally unused by the application.
For example, getitemmtdissues has 3 parameters; facility, part number, revision, and date. The one that is the most interesting to me is date. This allows for a host of trend reporting without concern for the accuracy of the data given that you are using a function created by the application maker.
Here is a demonstration of something i've done with these functions:
It's a query that shows your excess and overages of the previous 3 years, have fun !!!