Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Friday, January 8, 2016

Someone has a file open.

So, they moved the GUI in 2012r2 to show who has a file open.

I have no idea where it went, and I'm sure there are a billion ways to do it on the interwebs.

001
Get-SmbOpenFile | Where-Object -Property Path -EQ 'DriveLetter:\Folder\Path\Here'


Play with Get-SmbOpenFile and it's friends Close-SmbOpenFile, Close-SmbOpenSession, Block-SmbShareAccess.

Ton of utility there.

Thursday, January 7, 2016

Wireless Disabled on Server 2012r2

Wireless networking is disabled (feature not installed), by default on Windows 2012r2.

Quick Google =
http://blogs.technet.com/b/blainbar/archive/2012/09/14/getting-your-windows-server-2012-to-use-wireless-not-best-practice-but.aspx

Easy fix. But why do it in the GUI?

PowerShell!

Get-WindowsFeature Wireless*
#Confirm that "Wireless-Networking is not installed (available).
Install-WindowsFeature Wireless Networking 

You'll have to restart, and after you do, if there are issues, you might need to change the "WLAN AutoConfig" service off "manual".

...and this is probably a bad thing to have in production..something...something not a best practice.

Install-WindowsFeature is actually a really interesting cmdlet.

You can within that cmdlet, do things like -ForceRestart and -Source. Source will let you specify a network UNC path, a repo specified by GPO, local system, VHD, or the venerable Windows Update.

So if you go so far as to establish a well known GPO with the repo, you can never ever need to have media available (doesn't come up much, but it does for things such as .NET 3.5 needing to be installed in 2012r2).

The kicker really is that it (centralized sources) will become more and more needed as server slims down and attack surfaces are reduced through simply reducing the amount of components installed.

Wonder if this will be merged into One-Get in the future.

Wednesday, December 30, 2015

Primary Devices of a User Collection

One of the limitations (to my knowledge) within ConfigMgr's console, is the ability to cross views easily in reference to the SQL DB.

I've wanted, for awhile, to be able to take a User Collection, and generate a Device Collection that are the Primary devices those users are set to.

This is what I've come up with so far as a new view in SQL.

001
002
003
004
005
006
SELECT dbo.vCollectionMembers.SiteID AS CollectionID, dbo.vCollectionMembers.Name AS Username, dbo.v_R_System_Valid.Netbios_Name0 AS DeviceName
FROM   dbo.v_UsersPrimaryMachines INNER JOIN
       dbo.v_R_User ON dbo.v_UsersPrimaryMachines.UserResourceID = dbo.v_R_User.ResourceID INNER JOIN
       dbo.v_R_System_Valid ON dbo.v_UsersPrimaryMachines.MachineID = dbo.v_R_System_Valid.ResourceID RIGHT OUTER JOIN
       dbo.vCollectionMembers ON dbo.v_R_User.Name0 = dbo.vCollectionMembers.Name
WHERE  (dbo.vCollectionMembers.SiteID = N'XYZ123456'AND (dbo.vCollectionMembers.ArchitectureKey = '4')

I also popped this together, a list of all users, and their assigned Primary Devices.

001
002
003
004
005
SELECT dbo.v_R_User.Unique_User_Name0 AS [User], dbo.v_R_System_Valid.AD_Site_Name0, dbo.v_R_System_Valid.Netbios_Name0 AS ComputerName
FROM   dbo.v_UsersPrimaryMachines INNER JOIN
       dbo.v_R_User ON dbo.v_UsersPrimaryMachines.UserResourceID = dbo.v_R_User.ResourceID RIGHT OUTER JOIN
       dbo.v_R_System_Valid ON dbo.v_UsersPrimaryMachines.MachineID = dbo.v_R_System_Valid.ResourceID
WHERE  (dbo.v_R_User.Unique_User_Name0 <> N'NULL')

Next, I'll put together a little PowerShell function to get this list of Devices, and then place them in a Collection.

Fancy!

Now I fully expect to be shown how this is something do-able in one or two simple clicks within the console. :)

Thursday, October 8, 2015

ISESteroids Version Control

I have little background in programming, code development and best practices.

My skillset in PowerShell developed by playing continually and trying to cover a need.

As a result I have a large folder of trials, tests, failures, terribly filed notes about tests. 

Incredibly painful to use and navigate.

I bet quite a few people have this same thing going on.

Any programmers that look at it probably feel this way:


This directory content will probably look familiar to some folks!


DoSomethingTest.ps1
DoSomethingTest2.2.ps1
DoSomething1.2.ps1
DoSomethingDraftTest.ps1
DoSomethingDraftTestnotes12.txt
Trythis.ps1
Something Do This To A Thing.ps1

So, a folder of junk.


Versioning was a cool idea.

A concept that I never was taught and I never stopped and took the time to learn.

Terrible habits I developed

Deliberately not saving due to just wanting to test something out.
That whole File>SaveAs was just too much work.
Rambling non-descriptive file names.

Installing the trial of ISESteroids changed everything!


Totally a game changer for me.

After a few hours of clicking around I stumbled on...

“Toggle Script File Versioning Management Tool”


I’m sorry….whats this!?


I saved a script and started playing.

Here’s how it works.


Your initial save does not do anything in this pane.


Check off “Auto Mode” for now and change something in your script.


Hit F5 to run the script.


Let’s change another thing, and make another save.


Oh my goodness! What’s this! I’ll go through what I understand.


Automatic


Upper right, this version was created via auto mode (I’ll get to manual in a moment).

Delete


Deletes this version.

Notes


You can add your own notes to the version, these notes are not saved in the script itself.

Open


This opens the version in a new tab within ISE so you don’t lose what you were actually working on. Note that you need to resave this version as a new file and turn versioning on if you want to sort of branch off.


Compare


Big one here!

Click Compare on Version .01 and you jump right into WinMerge!

This isn’t a guide on how to use WinMerge, but it’s pretty intuitive.

If you make a change, go to File > Save and you can commit your change.



Then when you close WinMerge, PowerShell_ISE will prompt you to reload the file.



Note that by reopening the file in this way, it’s now your current saved version.

It doesn’t create another minor version.

Another note. If you have WinMerge open, you cannot interact with the ISE window until it’s closed.
I thought that ISE had gone wonky and I was going to kill the program before it dawned on me.

Version  Development Status




Click on "Unclassified" and you’ll be able to chose the point at which the version is in development. 

Alpha > Beta > Stable > Internal > Release

Please know that is the sequence in which I see development is ordered, that may not be correct.

Manual Mode?



So, we’ve used Auto Mode, and understand what we’re seeing up there in the pane.

Let’s look at manually adding a version.

Click “Add New Version”


Add New Major Version


Notice how all our saves are small increases? (0.1 -> 0.2 -> 0.3)

This will increment the version in full versions (1.x -> 2.x -> 3.x).

Add New Minor Version


Similar to major version, this just adds a non automatic (non triggered by saving) minor version.

I also noticed if you bump past Version 0.9 it neatly goes to Version 0.10, 0.11 and so on.

Very nice! Another neat thing is that if you delete versions along the way, it remembers what they were, and doesn’t try to “fill in the blank” when you make a new version.


Add New Major Version and Remove Minor Versions


This creates a new V x.00 and deletes ALL the 0.xx versions listed.

You can click cancel and it will just create the Major Version.


Open History Archive in Explorer


Now you can discover how ISESteriods is actually performing all this magic!

Hit this and you will be pointed to a ZIP file sitting in the same folder as your saved (current) PS1.

Opening and extracting this zip will give all the versions you have created as plain old PS1 files.

The “index” file is an XML and with all the creation time, username and notes you created!

Side note! If you want a visual tool to help play with XPath searches check out:

(and note that the menu is hidden, hit Alt and you can add an XML to work with)

Final Words


If I possessed a bit of forethought, I would have looked and seen this blog entry was more concisely written in these locations:

Regardless, go get ISESteriods today and start trying it out! 10 day trial is worth it.