tag:blogger.com,1999:blog-64174759959920203482024-03-05T04:51:06.162-06:00The Overnight AdminI'm a Windows PowerShell Enthusiast trying to spread all the great things PowerShell can do with the world!BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.comBlogger46125tag:blogger.com,1999:blog-6417475995992020348.post-68873309554539289852017-06-29T18:16:00.000-05:002017-06-29T18:24:34.171-05:00Cleanup WSUS content folder with PowerShell<div style="text-align: center;">
<div style="text-align: left;">
WSUS drive alerting for low disk space? Run this script and go get some coffee!</div>
</div>
<br />
This script is the equivalent of running the WSUS cleanup wizard with all checkboxes checked.<br />
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<a href="https://gallery.technet.microsoft.com/scriptcenter/WSUS-Content-Cleanup-68986b06/file/175020/1/Start-WSUSCleanup.ps1">Download the script from the Microsoft Script Repository!</a></div>
<br />
<span style="color: darkblue;">Function</span><span style="color: black;"> </span><span style="color: blueviolet;">Start-WSUSCleanup</span><span style="color: black;">{</span><br />
<span style="color: darkgreen;"><#<br />.SYNOPSIS <br />Cleans up a WSUS content folder.<br />
<br />.DESCRIPTION<br />This script is the equivalent of running a WSUS cleanup with all checkboxes checked from within the WSUS console> options > WSUS Cleanup. `<br />It scrunbs the WSUS content folder for unneeded data.<br />
<br />.EXAMPLE<br />PS C:\> Start-WSUSCleanup<br />
<br />.NOTES <br />Version : 3.0+<br />Author/Copyright : © Matthew Kerfoot - All Rights Reserved<br />Email/Blog/Twitter : mkkerfoot@gmail.com www.TheOvernightAdmin.com @mkkerfoot<br />
<br />Disclaimer : THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK<br />OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.<br />While these scripts are tested and working in my environment, it is recommended <br />that you test these scripts in a test environment before using in your production environment<br />Matthew Kerfoot further disclaims all implied warranties including, without limitation, any <br />implied warranties of merchantability or of fitness for a particular purpose. The entire risk <br />arising out of the use or performance of this script and documentation remains with you. <br />In no event shall Matthew Kerfoot, its authors, or anyone else involved in the creation, production, <br />or delivery of this script/tool be liable for any damages whatsoever (including, without limitation, <br />damages for loss of business profits, business interruption, loss of business information, or other <br />pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, <br />even if Matthew Kerfoot has been advised of the possibility of such damages.<br />
<br />Assumptions : ExecutionPolicy of AllSigned (recommended), RemoteSigned or Unrestricted (not recommended)<br />Limitations : not all functions work with PSv1<br />Ideas/Wish list : Now working with PSv2, PSv3, PSv4 and PSv5 <br />Known issues : None<br />Authors notes : I found this somewhere on the internet and adapted it.. not sure where.. <br />#></span><br />
<br />
<span style="color: darkgrey;">[</span><span style="color: lightblue;">CmdletBinding</span><span style="color: black;">(</span><span style="color: black;">SupportsShouldProcess</span><span style="color: darkgrey;">=</span><span style="color: orangered;">$True</span><span style="color: black;">)</span><span style="color: darkgrey;">]</span><br />
<span style="color: black;"> </span><span style="color: darkblue;">param</span><span style="color: black;">(</span><br />
<span style="color: black;"> </span><span style="color: darkgrey;">[</span><span style="color: lightblue;">Parameter</span><span style="color: black;">(</span><span style="color: black;">Mandatory</span><span style="color: darkgrey;">=</span><span style="color: orangered;">$false</span><span style="color: darkgrey;">,</span><span style="color: black;">ValueFromPipeline</span><span style="color: darkgrey;">=</span><span style="color: orangered;">$true</span><span style="color: black;">)</span><span style="color: darkgrey;">]</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$Date</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: blue;">Get-date</span><span style="color: black;"> </span><span style="color: navy;">-Format</span><span style="color: black;"> </span><span style="color: blueviolet;">MMddyyyy</span><span style="color: black;">)</span><span style="color: darkgrey;">,</span><br />
<span style="color: black;"> </span><span style="color: darkgrey;">[</span><span style="color: lightblue;">Parameter</span><span style="color: black;">(</span><span style="color: black;">Mandatory</span><span style="color: darkgrey;">=</span><span style="color: orangered;">$false</span><span style="color: darkgrey;">,</span><span style="color: black;">ValueFromPipeline</span><span style="color: darkgrey;">=</span><span style="color: orangered;">$true</span><span style="color: black;">)</span><span style="color: darkgrey;">]</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$OutFilePath</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: darkred;">"$env:USERPROFILE\Desktop\wsusCleanUpResults_$date.txt"</span><br />
<span style="color: black;"> </span><span style="color: black;">)</span><br />
<span style="color: black;"> </span><span style="color: darkgreen;"># Loads the WSUS .NET assembly - should probably be changed to load as loadwithpartial name is outdated</span><br />
<span style="color: black;"> </span><span style="color: darkgreen;"># This is piped to out-null so that the next line won't run until the WSUS assembly is fully loaded</span><br />
<span style="color: black;"> </span><span style="color: teal;">[reflection.assembly]</span><span style="color: darkgrey;">::</span><span style="color: black;">LoadWithPartialName</span><span style="color: black;">(</span><span style="color: darkred;">"Microsoft.UpdateServices.Administration"</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: darkgrey;">|</span><span style="color: black;"> </span><span style="color: blue;">out-null</span><br />
<br />
<span style="color: black;"> </span><span style="color: darkgreen;"># retrieves the primary WSUS servers information</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$wsusServer</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: teal;">[Microsoft.UpdateServices.Administration.AdminProxy]</span><span style="color: darkgrey;">::</span><span style="color: black;">GetUpdateServer</span><span style="color: black;">(</span><span style="color: black;">)</span><span style="color: black;">;</span><br />
<br />
<span style="color: black;"> </span><span style="color: darkgreen;"># Gets the Cleanup scope options, this is the same as the radio buttons in the WSUS console `</span><br />
<span style="color: black;"> </span><span style="color: darkgreen;"># Switch any of them to false to disable cleaning up that kind of data</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$cleanupScope</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: blue;">new-object</span><span style="color: black;"> </span><span style="color: blueviolet;">Microsoft.UpdateServices.Administration.CleanupScope</span><span style="color: black;">;</span><br />
<br />
<span style="color: black;"> </span><span style="color: darkgreen;"># $True means that item will be scrubbed and data will be deleted!</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$cleanupScope</span><span style="color: darkgrey;">.</span><span style="color: black;">DeclineSupersededUpdates</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$true</span><span style="color: black;"> </span><br />
<span style="color: black;"> </span><span style="color: orangered;">$cleanupScope</span><span style="color: darkgrey;">.</span><span style="color: black;">DeclineExpiredUpdates</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$true</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$cleanupScope</span><span style="color: darkgrey;">.</span><span style="color: black;">CleanupObsoleteUpdates</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$true</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$cleanupScope</span><span style="color: darkgrey;">.</span><span style="color: black;">CompressUpdates</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$true</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$cleanupScope</span><span style="color: darkgrey;">.</span><span style="color: black;">CleanupObsoleteComputers</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$true</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$cleanupScope</span><span style="color: darkgrey;">.</span><span style="color: black;">CleanupUnneededContentFiles</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$true</span><br />
<br />
<span style="color: black;"> </span><span style="color: darkgreen;"># Opens WSUS cleanup console as a background task</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$cleanupManager</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$wsusServer</span><span style="color: darkgrey;">.</span><span style="color: black;">GetCleanupManager</span><span style="color: black;">(</span><span style="color: black;">)</span><span style="color: black;">;</span><br />
<br />
<span style="color: black;"> </span><span style="color: darkgreen;"># Initiats the cleanup and writes outputs to $OutputFile</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$cleanupManager</span><span style="color: darkgrey;">.</span><span style="color: black;">PerformCleanup</span><span style="color: black;">(</span><span style="color: orangered;">$cleanupScope</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: darkgrey;">|</span><span style="color: black;"> </span><span style="color: blue;">Out-File</span><span style="color: black;"> </span><span style="color: navy;">-FilePath</span><span style="color: black;"> </span><span style="color: orangered;">$OutFilePath</span><span style="color: black;"> </span><span style="color: navy;">-Verbose</span><br />
<br />
<span style="color: black;"> </span><span style="color: darkgreen;"># Opens the output file so you can see how many items this script cleaned up</span><br />
<span style="color: black;"> </span><span style="color: blue;">Invoke-Item</span><span style="color: black;"> </span><span style="color: orangered;">$OutFilePath</span><span style="color: black;"> </span><span style="color: navy;">-Verbose</span><br />
<br />
<span style="color: black;">}</span><span style="color: black;"> </span><span style="color: blue;">Start-WSUSCleanup</span>BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com75595 Bristol Ln, Minnetonka, MN 55343, USA44.902818678675395 -93.435849113671844.8129401786754 -93.597210613671791 44.992697178675392 -93.2744876136718tag:blogger.com,1999:blog-6417475995992020348.post-87461142066069810532017-06-27T20:37:00.000-05:002017-06-27T20:38:31.583-05:00Automate Folder CleanupHere is a script I wrote to help automate the scrubbing\cleanup of my security camera footage.<br />
<br />
In its current unmodified configuration, it is set to keep the security_Camera folder on my K:\ drive above 10% free space. This is accomplished by scanning the folding or drive to figure out the used space percentage, if the used space percentage is less than the configured $FreeSpaceThreshold then it will remove the oldest file, rescan, if needed and remove the oldest file again. This will continue to happen until the $PercentageFree is over the threshold.<br />
<br />
<h3 style="text-align: center;">
<a href="https://gallery.technet.microsoft.com/scriptcenter/Automated-Folder-Cleanup-5cf859a4">Download the script from the Microsoft Script Repository!</a></h3>
<br />
<span style="color: darkblue;">Function</span><span style="color: black;"> </span><span style="color: blueviolet;">Automated-FolderCleanup</span><span style="color: black;"> </span><span style="color: black;">{</span><br />
<br />
<span style="color: darkgreen;"><# Matthew Kerfoot 6-26-17<br />.Synopsis<br />Cleans up aged files.<br />
<br />.DESCRIPTION<br />Monitors a folder and deletes the oldest files until the percent free Space reaches the configured threshold.<br />
<br />.EXAMPLE<br />PS:\>Automate-FolderCleanup -Path "K:\Security_Camera" -FreeSpaceThreshold "10"<br />
<br />.FUNCTIONALITY<br />This script was put together to scrub the oldest files from my security camera footage storage space.<br />
<br />.NOTES <br />
<br />Version : 3.0+<br />
<br />Author/Copyright : © Matthew Kerfoot - All Rights Reserved<br />
<br />Email/Blog/Twitter : mkkerfoot@gmail.com www.TheOvernightAdmin.com @mkkerfoot<br />
<br />Disclaimer : THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK<br />OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.<br />While these scripts are tested and working in my environment, it is recommended <br />that you test these scripts in a test environment before using in your production environment<br />Matthew Kerfoot further disclaims all implied warranties including, without limitation, any <br />implied warranties of merchantability or of fitness for a particular purpose. The entire risk <br />arising out of the use or performance of this script and documentation remains with you. <br />In no event shall Matthew Kerfoot, its authors, or anyone else involved in the creation, production, <br />or delivery of this script/tool be liable for any damages whatsoever (including, without limitation, <br />damages for loss of business profits, business interruption, loss of business information, or other <br />pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, <br />even if Matthew Kerfoot has been advised of the possibility of such damages.<br />
<br />Assumptions : ExecutionPolicy of AllSigned (recommended), RemoteSigned or Unrestricted (not recommended)<br />
<br />Author's notes : In its current unmodified configuration, it is set to keep the security_Camera `<br />folder on my K:\ drive above 10% free space. This is accomplished by scanning the folding `<br />or drive to figure out the used space percentage, if the used space percentage is less `<br />then the configured $FreeSpaceThreshold then it will remove the oldest file, rescan, `<br />if needed and remove the oldest file again. This will continue to happen until the `<br />$PercentageFree is over the threshold.<br />#></span><br />
<span style="color: black;"> </span><span style="color: darkgrey;">[</span><span style="color: lightblue;">Cmdletbinding</span><span style="color: black;">(</span><span style="color: black;">SupportsShouldProcess</span><span style="color: black;">)</span><span style="color: darkgrey;">]</span><br />
<span style="color: black;"> </span><span style="color: darkblue;">Param</span><span style="color: black;">(</span><br />
<span style="color: black;"> </span><span style="color: darkgrey;">[</span><span style="color: lightblue;">Parameter</span><span style="color: black;">(</span><span style="color: black;">Mandatory</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$false</span><span style="color: darkgrey;">,</span><br />
<span style="color: black;"> </span><span style="color: black;">ValueFromPipelineByPropertyName</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$true</span><span style="color: darkgrey;">,</span><br />
<span style="color: black;"> </span><span style="color: black;">Position</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: purple;">0</span><span style="color: darkgrey;">,</span><br />
<span style="color: black;"> </span><span style="color: black;">HelpMessage</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: darkred;">"Please enter the full path of the folder or drive you would like to monitor and clean"</span><span style="color: black;">)</span><span style="color: darkgrey;">]</span><br />
<span style="color: black;"> </span><span style="color: teal;">[string[]]</span><span style="color: orangered;">$Path</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: darkred;">"K:\Security_Camera"</span><span style="color: darkgrey;">,</span><br />
<span style="color: black;"> </span><span style="color: darkgrey;">[</span><span style="color: lightblue;">Parameter</span><span style="color: black;">(</span><span style="color: black;">Mandatory</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$false</span><span style="color: darkgrey;">,</span><br />
<span style="color: black;"> </span><span style="color: black;">ValueFromPipelineByPropertyName</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$true</span><span style="color: darkgrey;">,</span><br />
<span style="color: black;"> </span><span style="color: black;">Position</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: purple;">1</span><span style="color: darkgrey;">,</span><br />
<span style="color: black;"> </span><span style="color: black;">HelpMessage</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: darkred;">"What free space percentage do you want to set the threshold for?"</span><span style="color: black;">)</span><span style="color: darkgrey;">]</span><br />
<span style="color: black;"> </span><span style="color: teal;">[int]</span><span style="color: orangered;">$FreeSpaceThreshold</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: darkred;">"10"</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: darkgreen;"># What percentage do you want the drive to free up until?</span><br />
<span style="color: black;"> </span><span style="color: darkgrey;">[</span><span style="color: lightblue;">Parameter</span><span style="color: black;">(</span><span style="color: black;">Mandatory</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$false</span><span style="color: darkgrey;">,</span><br />
<span style="color: black;"> </span><span style="color: black;">ValueFromPipelineByPropertyName</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$true</span><span style="color: darkgrey;">,</span><br />
<span style="color: black;"> </span><span style="color: black;">Position</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: purple;">2</span><span style="color: darkgrey;">,</span><br />
<span style="color: black;"> </span><span style="color: black;">HelpMessage</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: darkred;">"Please enter the full path to where you would like a transaction log stored."</span><span style="color: black;">)</span><span style="color: darkgrey;">]</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$TranscriptLog</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: darkred;">"C:\windows\Temp\Automated-FolderCleanup.log"</span><br />
<span style="color: black;"> </span><span style="color: black;">)</span><br />
<span style="color: black;"> </span><span style="color: darkblue;">Begin</span><span style="color: black;">{</span><br />
<span style="color: black;"> </span><span style="color: blue;">Start-Transcript</span><span style="color: black;"> </span><span style="color: navy;">-Path</span><span style="color: black;"> </span><span style="color: orangered;">$TranscriptLog</span><br />
<span style="color: black;"> </span><span style="color: teal;">[string]</span><span style="color: orangered;">$Drive</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: blue;">Split-Path</span><span style="color: black;"> </span><span style="color: navy;">-Qualifier</span><span style="color: black;"> </span><span style="color: orangered;">$Path</span><br />
<span style="color: black;"> </span><span style="color: teal;">[WMI]</span><span style="color: orangered;">$Disk</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: darkred;">"Win32_LogicalDisk.DeviceID='$Drive'"</span><br />
<span style="color: black;"> </span><span style="color: teal;">[int]</span><span style="color: orangered;">$PercentFree</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$Disk</span><span style="color: darkgrey;">.</span><span style="color: black;">FreeSpace</span><span style="color: black;"> </span><span style="color: darkgrey;">/</span><span style="color: black;"> </span><span style="color: orangered;">$Disk</span><span style="color: darkgrey;">.</span><span style="color: black;">Size</span><span style="color: black;"> </span><span style="color: darkgrey;">*</span><span style="color: black;"> </span><span style="color: purple;">100</span><br />
<span style="color: black;"> </span><span style="color: black;">}</span><br />
<span style="color: black;"> </span><span style="color: darkblue;">Process</span><span style="color: black;">{</span><br />
<span style="color: black;"> </span><span style="color: darkblue;">while</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: orangered;">$PercentFree</span><span style="color: black;"> </span><span style="color: darkgrey;">-lt</span><span style="color: black;"> </span><span style="color: orangered;">$FreeSpaceThreshold</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: black;">{</span><br />
<span style="color: black;"> </span><span style="color: blue;">Get-ChildItem</span><span style="color: black;"> </span><span style="color: orangered;">$Path</span><span style="color: black;"> </span><span style="color: navy;">-Recurse</span><span style="color: black;"> </span><span style="color: navy;">-File</span><span style="color: black;"> </span><span style="color: darkgrey;">|</span><br />
<span style="color: black;"> </span><span style="color: blue;">Sort-Object</span><span style="color: black;"> </span><span style="color: blueviolet;">CreationTime</span><span style="color: black;"> </span><span style="color: darkgrey;">|</span><br />
<span style="color: black;"> </span><span style="color: blue;">Select-Object</span><span style="color: black;"> </span><span style="color: navy;">-First</span><span style="color: black;"> </span><span style="color: purple;">1</span><span style="color: black;"> </span><span style="color: darkgrey;">|</span><br />
<span style="color: black;"> </span><span style="color: blue;">Remove-Item</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$PercentFree</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$Disk</span><span style="color: darkgrey;">.</span><span style="color: black;">FreeSpace</span><span style="color: black;"> </span><span style="color: darkgrey;">/</span><span style="color: black;"> </span><span style="color: orangered;">$Disk</span><span style="color: darkgrey;">.</span><span style="color: black;">Size</span><span style="color: black;"> </span><span style="color: darkgrey;">*</span><span style="color: black;"> </span><span style="color: purple;">100</span><br />
<span style="color: black;"> </span><span style="color: black;">}</span><br />
<span style="color: black;"> </span><span style="color: black;">}</span><br />
<span style="color: black;"> </span><span style="color: darkblue;">end</span><span style="color: black;">{</span><br />
<span style="color: black;"> </span><span style="color: blue;">Write-Output</span><span style="color: black;"> </span><span style="color: darkred;">"Procesing has completed"</span><br />
<span style="color: black;"> </span><span style="color: blue;">Stop-Transcript</span><span style="color: black;"> </span><span style="color: navy;">-Verbose</span><br />
<span style="color: black;"> </span><span style="color: black;">}</span><br />
<span style="color: black;">}</span><span style="color: black;"> </span><span style="color: blue;">Automated-FolderCleanup</span><span style="color: black;"> </span><span style="color: navy;">-WhatIf</span><br />
<span style="color: navy;"><br /></span> Simply remove the <span style="color: navy;">-WhatIf</span> from the last line to allow processing if the script is run with <span style="color: navy;">-WhatIf</span> it will run the script but won't actually make changes it will just give you a verbose output as to what it would do if the <span style="color: navy;">-WhatIf</span> switch isn't specified.<br />
<br />
<h3 style="text-align: center;">
<a href="https://gallery.technet.microsoft.com/scriptcenter/Automated-Folder-Cleanup-5cf859a4">Download the script from the Microsoft Script Repository!</a></h3>
<div>
<br /></div>
<div>
Enjoy!</div>
BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0Minneapolis, MN, USA44.977753 -93.26501080000002744.797043 -93.589107300000023 45.158463 -92.940914300000031tag:blogger.com,1999:blog-6417475995992020348.post-3395772058381108202017-06-27T19:33:00.000-05:002017-06-27T20:04:49.377-05:00AutoHotKey - Control Your Mouse With Your Keyboard A month ago I bought a 40% keyboard. Some people might be wondering what a 40% keyboard is, it is just what you would think it is, it is 40% of the size of the standard 105 key layout. All the keys that have been removed are now stored in programmable layers. so for instance to make an exclamation mark I have to hold down, Fn1 + right shift + Capslock, this might seem insane but it is actually very intuitive after a week or so and now that I have fully adjusted I can hit any key without moving my fingers from the home row. Good-bye wrist pain!<br />
<br />
<div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7Zxfyz0Oig28vfVj51Kx26YL7Rm0SeBsQ88pt38oZ3UiZSPPAGokBqEN1UOlgmdOFL-hrs8PQ0nezmos0FUqPHwReT3tAnJ6FMQa9S5Ui42JcPxUVqJlbcOad38BgQ6UydNx-GYi3vgY/s1600/IMG_20170621_155042.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7Zxfyz0Oig28vfVj51Kx26YL7Rm0SeBsQ88pt38oZ3UiZSPPAGokBqEN1UOlgmdOFL-hrs8PQ0nezmos0FUqPHwReT3tAnJ6FMQa9S5Ui42JcPxUVqJlbcOad38BgQ6UydNx-GYi3vgY/s400/IMG_20170621_155042.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Vortex Core</td></tr>
</tbody></table>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<i><br />
</i></div>
<div>
<i>To be completely honest I did not think I would like using a 40% keyboard, especially as a daily driver. But after a week or two I found myself enjoying typing like seriously, typing is now fun and enjoyable.</i></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5FNVkAxPeZOFufigNJD7CcExCOVSQldZ5bZROX0GAaiXYg6Llhjw3-Zydw5ZRI_4KVhTr3k6z27Axv8USFkyp5M4eRUBcv1c2HdzwAnTsmjjNho-twnC0rn72aIr3u0J7bpqXYcgwtb0/s1600/IMG_20170621_154859.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5FNVkAxPeZOFufigNJD7CcExCOVSQldZ5bZROX0GAaiXYg6Llhjw3-Zydw5ZRI_4KVhTr3k6z27Axv8USFkyp5M4eRUBcv1c2HdzwAnTsmjjNho-twnC0rn72aIr3u0J7bpqXYcgwtb0/s320/IMG_20170621_154859.jpg" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Vortex Core</td></tr>
</tbody></table>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Alright now that we have gotten that out of the way, the point of this post is to share an AutoHotKey script that I have been running which allows me to control my mouse without actually having a mouse!</div>
<div>
<br /></div>
<div>
This script was developed using the AutoHotKey programming language and was aimed towards a 40% keyboard but with some slight modifications, it can work on any keyboard. Please review the comments and adjust accordingly for a full-size keyboard.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div style="text-align: center;">
<span style="font-size: large;">Here's the script in all its glory!</span></div>
</div>
<div>
<div>
;</div>
</div>
<span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">MouseControl.ahk</span><br />
<span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Hold</span><span style="color: black;"> </span><span style="color: blueviolet;">down</span><span style="color: black;"> </span><span style="color: blueviolet;">Control</span><span style="color: black;"> </span><span style="color: blueviolet;">and</span><span style="color: black;"> </span><span style="color: blueviolet;">then</span><span style="color: black;"> </span><span style="color: blueviolet;">use</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">arrow</span><span style="color: black;"> </span><span style="color: blueviolet;">keys</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">move</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">mouse</span><span style="color: black;"> </span><span style="color: blueviolet;">cursor</span><span style="color: black;"> </span><span style="color: blueviolet;">around</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">screen</span><br />
<span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Updated</span><span style="color: black;"> </span><span style="color: blueviolet;">on</span><span style="color: black;"> </span><span style="color: blueviolet;">June</span><span style="color: black;"> </span><span style="color: blueviolet;">22nd</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: purple;">2017</span><span style="color: black;"> </span><span style="color: blueviolet;">by</span><span style="color: black;"> </span><span style="color: blueviolet;">Matt</span><span style="color: black;"> </span><span style="color: blueviolet;">Kerfoot.</span><br />
<span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Updated</span><span style="color: black;"> </span><span style="color: blueviolet;">on</span><span style="color: black;"> </span><span style="color: blueviolet;">June</span><span style="color: black;"> </span><span style="color: blueviolet;">27nd</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: purple;">2017</span><br />
<span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">www.TheOvernightAdmin.com</span><br />
<span style="color: black;">;</span><br />
<span style="color: black;"><br /></span>
<span style="color: darkgreen;">#Persistent ; Keeps the script permanently running (that is, until the user closes it or ExitApp is encountered)</span><br />
<span style="color: darkgreen;"><br /></span>
<span style="color: blue;">SetDefaultMouseSpeed</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: purple;">1</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Mouse</span><span style="color: black;"> </span><span style="color: blueviolet;">speed</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">kind</span><span style="color: black;"> </span><span style="color: blueviolet;">of</span><span style="color: black;"> </span><span style="color: blueviolet;">like</span><span style="color: black;"> </span><span style="color: blueviolet;">reaction</span><span style="color: black;"> </span><span style="color: blueviolet;">time</span><span style="color: black;"> </span><span style="color: blueviolet;">I</span><span style="color: black;"> </span><span style="color: blueviolet;">do</span><span style="color: black;"> </span><span style="color: blueviolet;">believe</span><br />
<span style="color: blue;">distance</span><span style="color: black;"> </span><span style="color: blueviolet;">=</span><span style="color: black;"> </span><span style="color: purple;">30</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">how</span><span style="color: black;"> </span><span style="color: blueviolet;">far</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">mouse</span><span style="color: black;"> </span><span style="color: blueviolet;">moves</span><span style="color: black;"> </span><span style="color: blueviolet;">each</span><span style="color: black;"> </span><span style="color: blueviolet;">turn</span><span style="color: black;"> </span><span style="color: blueviolet;">of</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">timer</span><br />
<span style="color: blue;">multiplier</span><span style="color: black;"> </span><span style="color: blueviolet;">=</span><span style="color: black;"> </span><span style="color: purple;">1.16</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">how</span><span style="color: black;"> </span><span style="color: blueviolet;">much</span><span style="color: black;"> </span><span style="color: blueviolet;">farther</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: blue;">exponentially</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">mouse</span><span style="color: black;"> </span><span style="color: blueviolet;">moves</span><span style="color: black;"> </span><span style="color: blueviolet;">in</span><span style="color: black;"> </span><span style="color: blueviolet;">a</span><span style="color: black;"> </span><span style="color: blueviolet;">direction</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">longer</span><span style="color: black;"> </span><span style="color: blueviolet;">you</span><span style="color: black;"> </span><span style="color: blueviolet;">hold</span><span style="color: black;"> </span><span style="color: blueviolet;">that</span><span style="color: black;"> </span><span style="color: blueviolet;">direction</span><span style="color: black;"> </span><span style="color: blueviolet;">down</span><br />
<span style="color: blue;">CFKM</span><span style="color: black;"> </span><span style="color: blueviolet;">=</span><span style="color: black;"> </span><span style="color: purple;">30</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">how</span><span style="color: black;"> </span><span style="color: blueviolet;">often</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">run</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">timer</span><br />
<span style="color: blue;">SetTimer</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">CheckForKeyMouse</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">%CFKM%</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Controls</span><span style="color: black;"> </span><span style="color: blueviolet;">mouse</span><span style="color: black;"> </span><span style="color: blueviolet;">movement</span><span style="color: black;"> </span><span style="color: blueviolet;">speed</span><br />
<span style="color: darkblue;">return</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">end</span><span style="color: black;"> </span><span style="color: blueviolet;">of</span><span style="color: black;"> </span><span style="color: blueviolet;">mouse</span><span style="color: black;"> </span><span style="color: blueviolet;">control</span><span style="color: black;"> </span><span style="color: blueviolet;">movement</span><span style="color: black;"> </span><span style="color: blueviolet;">control</span><span style="color: black;"> </span><span style="color: blueviolet;">function</span><br />
<br />
<span style="color: blue;">CheckForKeyMouse:</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Beginning</span><span style="color: black;"> </span><span style="color: blueviolet;">of</span><span style="color: black;"> </span><span style="color: blueviolet;">Function</span><span style="color: black;"> </span><span style="color: blueviolet;">statement</span><br />
<span style="color: black;"> </span><span style="color: darkblue;">if</span><span style="color: black;"> </span><span style="color: blue;">not</span><span style="color: black;"> </span><span style="color: blueviolet;">GetKeyState</span><span style="color: black;">(</span><span style="color: darkred;">"Control"</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Requires</span><span style="color: black;"> </span><span style="color: blueviolet;">Ctrl</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">be</span><span style="color: black;"> </span><span style="color: blueviolet;">held</span><span style="color: black;"> </span><span style="color: blueviolet;">down</span><br />
<span style="color: black;"> </span><span style="color: darkblue;">return</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">required</span><span style="color: black;"> </span><span style="color: blueviolet;">otherwise</span><span style="color: black;"> </span><span style="color: blueviolet;">down</span><span style="color: black;"> </span><span style="color: blueviolet;">control</span><span style="color: black;"> </span><span style="color: blueviolet;">will</span><span style="color: black;"> </span><span style="color: blueviolet;">not</span><span style="color: black;"> </span><span style="color: blueviolet;">work</span><br />
<br />
<span style="color: black;"> </span><span style="color: blue;">GetKeyState</span><span style="color: black;">(</span><span style="color: darkred;">"Down"</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: blueviolet;">?</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: blue;">d*=multiplier</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: blueviolet;">:</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: blue;">d:=1</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: darkblue;">While</span><span style="color: black;"> </span><span style="color: blue;">holding</span><span style="color: black;"> </span><span style="color: blueviolet;">down</span><span style="color: black;"> </span><span style="color: blueviolet;">shift</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">down</span><span style="color: black;"> </span><span style="color: blueviolet;">arrow</span><span style="color: black;"> </span><span style="color: blueviolet;">will</span><span style="color: black;"> </span><span style="color: blueviolet;">allow</span><span style="color: black;"> </span><span style="color: blueviolet;">you</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">move</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">mouse</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">down</span><br />
<span style="color: black;"> </span><span style="color: blue;">GetKeyState</span><span style="color: black;">(</span><span style="color: darkred;">"Up"</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: blueviolet;">?</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: blue;">u*=multiplier</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: blueviolet;">:</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: blue;">u:=1</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: darkblue;">While</span><span style="color: black;"> </span><span style="color: blue;">holding</span><span style="color: black;"> </span><span style="color: blueviolet;">down</span><span style="color: black;"> </span><span style="color: blueviolet;">shift</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">up</span><span style="color: black;"> </span><span style="color: blueviolet;">arrow</span><span style="color: black;"> </span><span style="color: blueviolet;">will</span><span style="color: black;"> </span><span style="color: blueviolet;">allow</span><span style="color: black;"> </span><span style="color: blueviolet;">you</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">move</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">mouse</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">up</span><br />
<span style="color: black;"> </span><span style="color: blue;">GetKeyState</span><span style="color: black;">(</span><span style="color: darkred;">"Right"</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: blueviolet;">?</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: blue;">r*=multiplier</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: blueviolet;">:</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: blue;">r:=1</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: darkblue;">While</span><span style="color: black;"> </span><span style="color: blue;">holding</span><span style="color: black;"> </span><span style="color: blueviolet;">down</span><span style="color: black;"> </span><span style="color: blueviolet;">shift</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">right</span><span style="color: black;"> </span><span style="color: blueviolet;">arrow</span><span style="color: black;"> </span><span style="color: blueviolet;">will</span><span style="color: black;"> </span><span style="color: blueviolet;">allow</span><span style="color: black;"> </span><span style="color: blueviolet;">you</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">move</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">mouse</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">down</span><br />
<span style="color: black;"> </span><span style="color: blue;">GetKeyState</span><span style="color: black;">(</span><span style="color: darkred;">"Left"</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: blueviolet;">?</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: blue;">l*=multiplier</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: blueviolet;">:</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: blue;">l:=1</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: darkblue;">While</span><span style="color: black;"> </span><span style="color: blue;">holding</span><span style="color: black;"> </span><span style="color: blueviolet;">down</span><span style="color: black;"> </span><span style="color: blueviolet;">shift</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">left</span><span style="color: black;"> </span><span style="color: blueviolet;">arrow</span><span style="color: black;"> </span><span style="color: blueviolet;">will</span><span style="color: black;"> </span><span style="color: blueviolet;">allow</span><span style="color: black;"> </span><span style="color: blueviolet;">you</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">move</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">mouse</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">left</span><br />
<br />
<span style="color: black;"> </span><span style="color: blue;">y</span><span style="color: black;"> </span><span style="color: blueviolet;">:=</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: blue;">d-u</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: blueviolet;">*</span><span style="color: black;"> </span><span style="color: blueviolet;">distance</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">math</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">tell</span><span style="color: black;"> </span><span style="color: blueviolet;">how</span><span style="color: black;"> </span><span style="color: blueviolet;">far</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">move</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">cursor</span><br />
<span style="color: black;"> </span><span style="color: blue;">x</span><span style="color: black;"> </span><span style="color: blueviolet;">:=</span><span style="color: black;"> </span><span style="color: black;">(</span><span style="color: blue;">r-l</span><span style="color: black;">)</span><span style="color: black;"> </span><span style="color: blueviolet;">*</span><span style="color: black;"> </span><span style="color: blueviolet;">distance</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">more</span><span style="color: black;"> </span><span style="color: blueviolet;">math</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">define</span><span style="color: black;"> </span><span style="color: blueviolet;">how</span><span style="color: black;"> </span><span style="color: blueviolet;">far</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">cursor</span><span style="color: black;"> </span><span style="color: blueviolet;">moves</span><span style="color: black;"> </span><span style="color: blueviolet;">per</span><span style="color: black;"> </span><span style="color: blueviolet;">key</span><span style="color: black;"> </span><span style="color: blueviolet;">press</span><br />
<br />
<span style="color: black;"> </span><span style="color: blue;">MouseMove</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">x</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">y</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">R</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Initiates</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">action</span><span style="color: black;"> </span><span style="color: blueviolet;">of</span><span style="color: black;"> </span><span style="color: blueviolet;">moving</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">mouse</span><br />
<span style="color: black;"> </span><span style="color: blue;">^PgDn::Click</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">right</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Sets</span><span style="color: black;"> </span><span style="color: blueviolet;">Ctrl</span><span style="color: black;"> </span><span style="color: blueviolet;">+</span><span style="color: black;"> </span><span style="color: blueviolet;">PgDn</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">perform</span><span style="color: black;"> </span><span style="color: blueviolet;">a</span><span style="color: black;"> </span><span style="color: blueviolet;">right</span><span style="color: black;"> </span><span style="color: blueviolet;">click</span><br />
<span style="color: black;"> </span><span style="color: blue;">^BackSpace::Click</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">right</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Sets</span><span style="color: black;"> </span><span style="color: blueviolet;">Ctrl</span><span style="color: black;"> </span><span style="color: blueviolet;">+</span><span style="color: black;"> </span><span style="color: blueviolet;">backspace</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">perform</span><span style="color: black;"> </span><span style="color: blueviolet;">a</span><span style="color: black;"> </span><span style="color: blueviolet;">left</span><span style="color: black;"> </span><span style="color: blueviolet;">click</span><br />
<span style="color: black;"> </span><span style="color: blue;">^PgUp::Click</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">left</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Sets</span><span style="color: black;"> </span><span style="color: blueviolet;">Ctrl</span><span style="color: black;"> </span><span style="color: blueviolet;">+</span><span style="color: black;"> </span><span style="color: blueviolet;">PgUp</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">perform</span><span style="color: black;"> </span><span style="color: blueviolet;">a</span><span style="color: black;"> </span><span style="color: blueviolet;">left</span><span style="color: black;"> </span><span style="color: blueviolet;">click</span><br />
<span style="color: black;"> </span><span style="color: blue;">^Esc::Click</span><span style="color: darkgrey;">,</span><span style="color: black;"> </span><span style="color: blueviolet;">left</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Sets</span><span style="color: black;"> </span><span style="color: blueviolet;">Ctrl</span><span style="color: black;"> </span><span style="color: blueviolet;">+</span><span style="color: black;"> </span><span style="color: blueviolet;">Escape</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">perform</span><span style="color: black;"> </span><span style="color: blueviolet;">a</span><span style="color: black;"> </span><span style="color: blueviolet;">left</span><span style="color: black;"> </span><span style="color: blueviolet;">click</span><br />
<span style="color: black;"> </span><span style="color: blue;">^r::Reload</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">Assign</span><span style="color: black;"> </span><span style="color: blueviolet;">Ctrl-R</span><span style="color: black;"> </span><span style="color: blueviolet;">as</span><span style="color: black;"> </span><span style="color: blueviolet;">a</span><span style="color: black;"> </span><span style="color: blueviolet;">hotkey</span><span style="color: black;"> </span><span style="color: blueviolet;">to</span><span style="color: black;"> </span><span style="color: blueviolet;">restart</span><span style="color: black;"> </span><span style="color: blueviolet;">the</span><span style="color: black;"> </span><span style="color: blueviolet;">script.</span><br />
<span style="color: darkblue;">Return</span><span style="color: black;"> </span><span style="color: black;">;</span><span style="color: black;"> </span><span style="color: blue;">End</span><span style="color: black;"> </span><span style="color: blueviolet;">of</span><span style="color: black;"> </span><span style="color: blueviolet;">Function</span><span style="color: black;"> </span><span style="color: blueviolet;">statement</span><br />
<br />
<br />
<span style="font-size: large;"> I hope you enjoy it as much as I do! Any questions, just ask!</span><br />
<span style="font-size: large;"><br /></span> <span style="font-size: large;">-Matt Kerfoot</span>BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com21Minneapolis, MN, USA44.977753 -93.26501080000002744.797043 -93.589107300000023 45.158463 -92.940914300000031tag:blogger.com,1999:blog-6417475995992020348.post-6742505834007695842017-06-12T16:19:00.001-05:002017-06-13T18:11:16.315-05:00Add Devices to LogicMonitor with Speed!Here is a short PowerShell function that was written to speed up the time it takes to add servers to LogicMonitor.<br />
<br />
I use this when a Domain Admin account cannot be obtained, this helps to keep security tight. This gets around it by adding the domain user account to the local Administrators and Distributed COM users group. It does even more than that even, it sets the PS execution policy, PS Remoting and it allows WMI through the windows firewall.<br />
<br />
This script was developed for use with Server 2012R2 and newer however it should be backwards compatible all the way back to PowerShell version 2.0!<br />
<br />
<pre class="PoshConsole">Function Add-ToLogicMonitor {
<#
.Synopsis
Prepares a server to be added to LogicMonitor.
.DESCRIPTION
This function will prepare a server to be added to LogicMonitor by enabling PS remoting, `
setting the PS execution policy, adding LogicMonitorServiceAccountName to both the local administrator's group `
and the Distributed DCOM Users group.
.EXAMPLE
PS C:\> Add-ToLogicMonitor
.FUNCTIONALITY
Used to speed up onboarding of servers into LogicMonitor
#>
[CmdletBinding()]
Param(
$Computer = $env:computername,
$User = "LogicMonitorServiceAccountName",
$ErrorActionPreference = "SilentlyContinue"
)
# Enables PowerShell Remoting
Enable-PSRemoting -Force
Write-Host "PowerShell Remoting has been enabled." -BackgroundColor Black -ForegroundColor Green
# Sets the PowerShell Scripting Execution Policy to allow from the domain.
Set-ExecutionPolicy remotesigned -force
Write-Host "The Windows PowerShell Execution Policy has been set to allow scripts that are remotesigned." -BackgroundColor Black -ForegroundColor Green
# Opens firewall for LogicMonitor support.
netsh advfirewall firewall set rule group="windows management instrumentation (wmi)" new enable=yes
netsh firewall set service RemoteAdmin enable
Write-Host "Enables the required firewall rules for LogicMonitor to speak to the collector." -BackgroundColor Black -ForegroundColor Green
# Enables remote WMI and DCOM
Start-Service RemoteRegistry -Verbose
Set-Service RemoteRegistry -StartupType Automatic -Verbose
Write-Host "Remote WMI and DCOM have been enabled, the remote registry service has also been started and set to automatic startup." -BackgroundColor Black -ForegroundColor Green
# Adds $User to the local administrators group
$Administrators = [ADSI]("WinNT://$Computer/Administrators,group")
$Administrators.add("WinNT://$User,user")
Write-Host "$User has been added to the local Administrators group." -BackgroundColor Black -ForegroundColor Green
# Adds $User to the Distributed COM users group
$Administrators = [ADSI]("WinNT://$Computer/Distributed COM Users,group")
$Administrators.add("WinNT://$User,user")
Write-Host "$User has been added to the Distributed COM Users group." -BackgroundColor Black -ForegroundColor Green
}
</pre>
<div>
<br /></div>
BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0tag:blogger.com,1999:blog-6417475995992020348.post-31185274913908326272016-09-04T07:46:00.000-05:002016-09-04T07:55:08.396-05:00Download Earthporn wallpapersThis little PowerShell function will go out to Reddit and download all jpeg images and save them into the folder of your choosing. I recommend running it for about 5 minutes to get about 100 HD wallpapers. I say this because if you do not stop the script by hitting '[Ctrl] + c' or close the PowerShell window this script will slowly go through every page of this subreddit and could possibly fill up your hard drive.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_Fzg7SbVwLex7j4rbyTcvUiHjuupNlZJ7ensq-yvuBEw-_EHhIEwgqEgjLYZLmrEarb9n6lcg3kBPNG28A0j7mMeBUji9JmhsgLqo4Nq9_URjoDrdw7dCeVv5y3GYrbZj7H9PUkkI_Es/s1600/Captureq.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="168" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_Fzg7SbVwLex7j4rbyTcvUiHjuupNlZJ7ensq-yvuBEw-_EHhIEwgqEgjLYZLmrEarb9n6lcg3kBPNG28A0j7mMeBUji9JmhsgLqo4Nq9_URjoDrdw7dCeVv5y3GYrbZj7H9PUkkI_Es/s640/Captureq.PNG" width="640" /></a></div>
<br />
Enjoy!<br />
<br />
<div style="color: black; font-family: "segoe ui"; font-size: 12; font-style: normal; font-weight: normal; text-align: left;">
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="font-size: 16;"> </span><span style="color: #b2d7a3;">Function</span><span style="color: #eeedf0;"> Download-EarthPorn {</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;"><#</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;">.Synopsis</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;"> Downloads EarthPorn images from Reddit</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;">.DESCRIPTION</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;"> Goes out to reddit's EarthPorn subreddit and downloads all jpg images, `</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;"> then it removes any smaller images that might not look so well as a wallpaper.</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;">.EXAMPLE</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;"> PS:\> Download-EarthPorn</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;">#></span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> [</span><span style="color: #859900;">CmdletBinding</span><span style="color: #eeedf0;">()]</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">Param</span><span style="color: #eeedf0;">(</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># URL to download images from.</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> [</span><span style="color: #859900;">Parameter</span><span style="color: #eeedf0;">(Mandatory=</span><span style="color: red;">$False</span><span style="color: #eeedf0;">, ValueFromPipelineByPropertyName=</span><span style="color: red;">$true</span><span style="color: #eeedf0;">, Position=</span><span style="color: #586e75;">0</span><span style="color: #eeedf0;">)]</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> [</span><span style="color: #b58900;">string</span><span style="color: #eeedf0;">]</span><span style="color: red;">$URL</span><span style="color: #eeedf0;"> = </span><span style="color: #d69d85;">"www.reddit.com/r/earthporn"</span><span style="color: #eeedf0;">,</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># File location that you would like to save the downloaded images to.</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> [</span><span style="color: #859900;">Parameter</span><span style="color: #eeedf0;">(Mandatory=</span><span style="color: red;">$False</span><span style="color: #eeedf0;">, ValueFromPipelineByPropertyName=</span><span style="color: red;">$true</span><span style="color: #eeedf0;">, Position=)]</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> [</span><span style="color: #b58900;">String</span><span style="color: #eeedf0;">]</span><span style="color: red;">$Destination</span><span style="color: #eeedf0;"> = </span><span style="color: #d69d85;">"C:\Users\$env:USERNAME\Desktop\Earthporn_Wallpapers"</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> )</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">Begin</span><span style="color: #eeedf0;"> {</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># Imports bittransfer cmdlets</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">Import-Module</span><span style="color: #eeedf0;"> BitsTransfer -verbose</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> }</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">Process</span><span style="color: #eeedf0;">{</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># checks if the file exists, else creates it.</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">IF</span><span style="color: #eeedf0;"> (!(</span><span style="color: #4ec9b0;">Test-Path</span><span style="color: #eeedf0;"> </span><span style="color: red;">$Destination</span><span style="color: #eeedf0;">)) {</span><span style="color: #4ec9b0;">New-Item</span><span style="color: #eeedf0;"> -Path </span><span style="color: red;">$Destination</span><span style="color: #eeedf0;"> -ItemType Directory -Force | </span><span style="color: #4ec9b0;">Out-Null</span><span style="color: #eeedf0;">}</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">Do</span><span style="color: #eeedf0;"> {</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: red;">$Links</span><span style="color: #eeedf0;"> = (</span><span style="color: #4ec9b0;">Invoke-WebRequest</span><span style="color: #eeedf0;"> -Uri </span><span style="color: red;">$URL</span><span style="color: #eeedf0;">).links </span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> (</span><span style="color: red;">$links</span><span style="color: #eeedf0;"> | </span><span style="color: #4ec9b0;">Where</span><span style="color: #eeedf0;"> { </span><span style="color: red;">$_</span><span style="color: #eeedf0;">.href -match </span><span style="color: #d69d85;">".jpg"</span><span style="color: #eeedf0;"> } | </span><span style="color: #4ec9b0;">Where</span><span style="color: #eeedf0;"> { </span><span style="color: red;">$_</span><span style="color: #eeedf0;">.class -match </span><span style="color: #d69d85;">"title"</span><span style="color: #eeedf0;"> }).href | </span><span style="color: #4ec9b0;">Foreach</span><span style="color: #eeedf0;"> {</span><span style="color: #4ec9b0;">Start-BitsTransfer</span><span style="color: #eeedf0;"> -Source </span><span style="color: red;">$_</span><span style="color: #eeedf0;"> -Destination </span><span style="color: red;">$Destination</span><span style="color: #eeedf0;"> }</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: red;">$URL</span><span style="color: #eeedf0;"> = (</span><span style="color: red;">$Links</span><span style="color: #eeedf0;"> | </span><span style="color: #4ec9b0;">Where</span><span style="color: #eeedf0;"> { </span><span style="color: red;">$_</span><span style="color: #eeedf0;">.innerHTML -eq </span><span style="color: #d69d85;">"next ›"</span><span style="color: #eeedf0;"> }).href</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: red;">$URL</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> } </span><span style="color: #b2d7a3;">While</span><span style="color: #eeedf0;"> (</span><span style="color: #586e75;">1</span><span style="color: #eeedf0;"> -eq </span><span style="color: #586e75;">1</span><span style="color: #eeedf0;">)</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> }</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">End</span><span style="color: #eeedf0;"> {</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># Removes smaller images.</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> (</span><span style="color: #4ec9b0;">Get-ChildItem</span><span style="color: #eeedf0;"> -Filter *.jpg).FullName | </span><span style="color: #4ec9b0;">%</span><span style="color: #eeedf0;"> { </span><span style="color: red;">$img</span><span style="color: #eeedf0;"> = [</span><span style="color: #b58900;">Drawing.Image</span><span style="color: #eeedf0;">]::FromFile(</span><span style="color: red;">$_</span><span style="color: #eeedf0;">)</span><span style="color: white;">;</span><span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">if</span><span style="color: #eeedf0;"> (</span><span style="color: red;">$img</span><span style="color: #eeedf0;">.Width -lt </span><span style="color: #586e75;">1680</span><span style="color: #eeedf0;"> -OR </span><span style="color: red;">$img</span><span style="color: #eeedf0;">.Height -lt </span><span style="color: #586e75;">1050</span><span style="color: #eeedf0;">) { </span><span style="color: #4ec9b0;">Remove-Item</span><span style="color: #eeedf0;"> </span><span style="color: red;">$_</span><span style="color: #eeedf0;"> }}</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> }</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;">} </span><span style="color: lime;"># End of Download-EarthPorn function</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #4ec9b0;">Download-EarthPorn</span></div>
</div>
BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0Minneapolis, MN 55426, USA44.954643999999988 -93.38479689999996944.864746499999988 -93.546158399999968 45.044541499999987 -93.223435399999971tag:blogger.com,1999:blog-6417475995992020348.post-52134541648176509542016-09-04T07:38:00.000-05:002016-09-04T07:52:54.937-05:00Windows Spotlight WallpapersIf you are anything like me then you were super impressed by the new wallpapers Windows has been pushing out to Windows 10 machines. Well here is a PowerShell function that you can run to find them all, rename them and then sort them into two folders based on the width of the images, some will go into a phone wallpaper folder while the larger images will be saved in the default folder on your desktop.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiZH12a285TBfL78PvWKj5jzUkE__-hmZAcSnFgAo1pveh7n-qt_aw8Mtt53kRrjfYQ13youaECX0f_3HIPHkwSGUC7C0tZuZaypm4SEsK5db7m0elJiyTiHdU06COy8lu-8zZQML86EM/s1600/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="230" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiZH12a285TBfL78PvWKj5jzUkE__-hmZAcSnFgAo1pveh7n-qt_aw8Mtt53kRrjfYQ13youaECX0f_3HIPHkwSGUC7C0tZuZaypm4SEsK5db7m0elJiyTiHdU06COy8lu-8zZQML86EM/s640/Capture.PNG" width="640" /></a></div>
<br />
<br />
<div style="color: black; font-family: "segoe ui"; font-size: 12; font-style: normal; font-weight: normal; text-align: left;">
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="font-size: 16;"> </span><span style="color: #b2d7a3;">Function</span><span style="color: #eeedf0;"> Get-WindowsSpotlightWallpapers{</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;"><#</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;">.Synopsis</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;"> Grabs Windows Spotlight Wallpapers</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;">.DESCRIPTION</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;"> Grabs Microsoft Spotlight Wallpapers and moves them to your desktop, filters out the wallpapers by width and moves the skinny images to a folder for phone wallpapers.</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;">.EXAMPLE</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;"> PS :\> Get-WindowsSpotlightWallpapers</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: lime;">#></span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> [</span><span style="color: #859900;">CmdletBinding</span><span style="color: #eeedf0;">()]</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">Param</span><span style="color: #eeedf0;"> (</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># Path to spotlight files</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> [</span><span style="color: #859900;">Parameter</span><span style="color: #eeedf0;">(Mandatory=</span><span style="color: red;">$false</span><span style="color: #eeedf0;">, ValueFromPipelineByPropertyName=</span><span style="color: red;">$true</span><span style="color: #eeedf0;">,Position=</span><span style="color: #586e75;">0</span><span style="color: #eeedf0;">)]</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: red;">$Path</span><span style="color: #eeedf0;"> = </span><span style="color: #d69d85;">"C:\Users\</span><span style="color: red;">$env:USERNAME</span><span style="color: #d69d85;">\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets"</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> )</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># Moves to the directory the wallpapers are stored in.</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">Set-Location</span><span style="color: #eeedf0;"> -Path </span><span style="color: red;">$Path</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># copies wallpapers to folder on you desktop so we don't currupt the originals at all.</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">Copy-Item</span><span style="color: #eeedf0;"> -Path </span><span style="color: red;">$Path</span><span style="color: #eeedf0;"> -Recurse -Destination </span><span style="color: #d69d85;">"C:\Users\</span><span style="color: red;">$env:USERNAME</span><span style="color: #d69d85;">\Desktop\Windows Spotlight Wallpapers\"</span><span style="color: #eeedf0;"> -Verbose</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># renames files with .jpeg extention.</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">Get-ChildItem</span><span style="color: #eeedf0;"> -Path </span><span style="color: #d69d85;">"C:\Users\</span><span style="color: red;">$env:USERNAME</span><span style="color: #d69d85;">\Desktop\Windows Spotlight Wallpapers\"</span><span style="color: #eeedf0;"> | </span><span style="color: #4ec9b0;">Rename-Item</span><span style="color: #eeedf0;"> -NewName { [</span><span style="color: #b58900;">io.path</span><span style="color: #eeedf0;">]::ChangeExtension(</span><span style="color: red;">$_</span><span style="color: #eeedf0;">.name, </span><span style="color: #d69d85;">"jpeg"</span><span style="color: #eeedf0;">) } -Verbose</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># deletes files smaller than 25000</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">Get-ChildItem</span><span style="color: #eeedf0;"> -Path </span><span style="color: #d69d85;">"C:\Users\</span><span style="color: red;">$env:USERNAME</span><span style="color: #d69d85;">\Desktop\Windows Spotlight Wallpapers\"</span><span style="color: #eeedf0;"> | </span><span style="color: #4ec9b0;">Where-Object</span><span style="color: #eeedf0;"> {</span><span style="color: red;">$_</span><span style="color: #eeedf0;">.Length -lt </span><span style="color: #d69d85;">"25000"</span><span style="color: #eeedf0;">} | </span><span style="color: #4ec9b0;">Remove-Item</span><span style="color: #eeedf0;"> -Verbose</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># creates a folder for the phone wallpapers</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">New-Item</span><span style="color: #eeedf0;"> -Path </span><span style="color: #d69d85;">"C:\Users\</span><span style="color: red;">$env:USERNAME</span><span style="color: #d69d85;">\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers"</span><span style="color: #eeedf0;"> -ItemType Directory -Verbose | </span><span style="color: #4ec9b0;">Out-Null</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># filter files by image width then moves small files to phone wallpaper directory.</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">Function</span><span style="color: #eeedf0;"> Get-Image{</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> [</span><span style="color: #b58900;">System.Reflection.Assembly</span><span style="color: #eeedf0;">]::LoadWithPartialName(</span><span style="color: #d69d85;">"System.Drawing"</span><span style="color: #eeedf0;">) | </span><span style="color: #4ec9b0;">Out-Null</span><span style="color: #eeedf0;"> </span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: red;">$fi</span><span style="color: #eeedf0;">=[</span><span style="color: #b58900;">System.IO.FileInfo</span><span style="color: #eeedf0;">]</span><span style="color: red;">$_</span><span style="color: #eeedf0;"> </span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">if</span><span style="color: #eeedf0;">( </span><span style="color: red;">$fi</span><span style="color: #eeedf0;">.Exists){</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: red;">$img</span><span style="color: #eeedf0;"> = [</span><span style="color: #b58900;">System.Drawing.Image</span><span style="color: #eeedf0;">]::FromFile(</span><span style="color: red;">$_</span><span style="color: #eeedf0;">)</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: red;">$img</span><span style="color: #eeedf0;">.Clone()</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: red;">$img</span><span style="color: #eeedf0;">.Dispose() </span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> } </span><span style="color: #b2d7a3;">else</span><span style="color: #eeedf0;"> { </span><span style="color: #4ec9b0;">Write-Host</span><span style="color: #eeedf0;"> </span><span style="color: #d69d85;">"File not found: </span><span style="color: red;">$_</span><span style="color: #d69d85;">"</span><span style="color: #eeedf0;"> -fore yellow } </span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> }</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: red;">$PhoneWallpapers</span><span style="color: #eeedf0;"> = </span><span style="color: #4ec9b0;">Get-ChildItem</span><span style="color: #eeedf0;"> </span><span style="color: #d69d85;">"C:\Users\</span><span style="color: red;">$env:USERNAME</span><span style="color: #d69d85;">\Desktop\Windows Spotlight Wallpapers\*.jpeg"</span><span style="color: #eeedf0;"> -Recurse | </span><span style="color: #4ec9b0;">%</span><span style="color: #eeedf0;"> {</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: red;">$image</span><span style="color: #eeedf0;"> = </span><span style="color: red;">$_</span><span style="color: #eeedf0;"> | </span><span style="color: #4ec9b0;">Get-Image</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">New-Object</span><span style="color: #eeedf0;"> PSObject -Property @{ </span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> File = </span><span style="color: red;">$_</span><span style="color: #eeedf0;">.name</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> Fullname = </span><span style="color: red;">$_</span><span style="color: #eeedf0;">.Fullname</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> Height = </span><span style="color: red;">$image</span><span style="color: #eeedf0;">.Height</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> Width = </span><span style="color: red;">$image</span><span style="color: #eeedf0;">.Width</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> }</span><span style="color: white;">;</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> }</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># starts 5 second sleep timer</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">Start-Sleep</span><span style="color: #eeedf0;"> -Seconds </span><span style="color: #586e75;">5</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># Goes through wallpapers and moved the smaller width files to the phone wallpaper directory.</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">foreach</span><span style="color: #eeedf0;">(</span><span style="color: red;">$p</span><span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">in</span><span style="color: #eeedf0;"> </span><span style="color: red;">$PhoneWallpapers</span><span style="color: #eeedf0;">){</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">if</span><span style="color: #eeedf0;">((</span><span style="color: red;">$p</span><span style="color: #eeedf0;">).Width -lt </span><span style="color: #d69d85;">"1081"</span><span style="color: #eeedf0;">){</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">Move-Item</span><span style="color: #eeedf0;"> -Path (</span><span style="color: red;">$p</span><span style="color: #eeedf0;">).fullname -Destination </span><span style="color: #d69d85;">"C:\Users\</span><span style="color: red;">$env:USERNAME</span><span style="color: #d69d85;">\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers\"</span><span style="color: #eeedf0;"> -Verbose -Force</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> }</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">if</span><span style="color: #eeedf0;">((</span><span style="color: red;">$p</span><span style="color: #eeedf0;">).Width -eq </span><span style="color: #d69d85;">"272"</span><span style="color: #eeedf0;">){</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">Move-Item</span><span style="color: #eeedf0;"> -Path (</span><span style="color: red;">$p</span><span style="color: #eeedf0;">).fullname -Destination </span><span style="color: #d69d85;">"C:\Users\</span><span style="color: red;">$env:USERNAME</span><span style="color: #d69d85;">\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers\"</span><span style="color: #eeedf0;"> -Verbose -Force</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> }</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: lime;"># starts 5 second sleep timer</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">Start-Sleep</span><span style="color: #eeedf0;"> -Seconds </span><span style="color: #586e75;">5</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">if</span><span style="color: #eeedf0;">((</span><span style="color: red;">$p</span><span style="color: #eeedf0;">).Width -lt </span><span style="color: #d69d85;">"1081"</span><span style="color: #eeedf0;">){</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">Move-Item</span><span style="color: #eeedf0;"> -Path (</span><span style="color: red;">$p</span><span style="color: #eeedf0;">).fullname -Destination </span><span style="color: #d69d85;">"C:\Users\</span><span style="color: red;">$env:USERNAME</span><span style="color: #d69d85;">\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers\"</span><span style="color: #eeedf0;"> -ErrorAction SilentlyContinue -Verbose -Force</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> }</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #b2d7a3;">if</span><span style="color: #eeedf0;">((</span><span style="color: red;">$p</span><span style="color: #eeedf0;">).Width -eq </span><span style="color: #d69d85;">"272"</span><span style="color: #eeedf0;">){</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span><span style="color: #4ec9b0;">Move-Item</span><span style="color: #eeedf0;"> -Path (</span><span style="color: red;">$p</span><span style="color: #eeedf0;">).fullname -Destination </span><span style="color: #d69d85;">"C:\Users\</span><span style="color: red;">$env:USERNAME</span><span style="color: #d69d85;">\Desktop\Windows Spotlight Wallpapers\Windows Spotlight Phone Wallpapers\"</span><span style="color: #eeedf0;"> -ErrorAction SilentlyContinue -Verbose -Force</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> }</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> }</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #4ec9b0;">Set-location</span><span style="color: #eeedf0;"> </span><span style="color: #d69d85;">"C:\Users\</span><span style="color: red;">$env:USERNAME</span><span style="color: #d69d85;">\Desktop\Windows Spotlight Wallpapers\"</span><span style="color: #eeedf0;"> </span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #4ec9b0;">Invoke-Item</span><span style="color: #eeedf0;"> </span><span style="color: #d69d85;">"C:\Users\</span><span style="color: red;">$env:USERNAME</span><span style="color: #d69d85;">\Desktop\Windows Spotlight Wallpapers\"</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;">} </span><span style="color: lime;"># end of function.</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #4ec9b0;">Get-WindowsSpotLightWallpapers</span></div>
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #4ec9b0;"><br />
</span></div>
<br />
<div style="background-color: black; font-family: "lucida console"; font-size: 12.666666666666666; margin: 0 0 0 0;">
<span style="color: #eeedf0;"> </span></div>
<br />
After running the script I would recommend setting the newly created folder on your desktop as the folder windows uses to grab you wallpapers from.<br />
<br />
Simply hit the windows key and start tyoing 'wallpaper' and you should see something that says choose background....<br />
<br />
Enjoy!</div>
BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com6St Louis Park, MN, USA44.9597376 -93.37021859999998744.8698346 -93.531580099999985 45.0496406 -93.208857099999989tag:blogger.com,1999:blog-6417475995992020348.post-83592635587764771092015-09-28T17:44:00.000-05:002015-09-28T17:53:04.840-05:00Maximus is coming . . . This has been an ongoing project\side project for myself over the last month or two. It's more or less a PowerShell Module loaded with functions to allow you to do great things at great speeds. In all I think it contains about 30 functions, I'm sure this will continue to fluctuate.... which leads me to why I'm actually writing this, I hope to possible\hopefully treat this page as the HelpURI for Maximus.<br />
<br />
but anyhow..... here is one, one I just wrote today actually. This is what I would call an oldie but a goodie.<br />
<br />
<pre class="PoshConsole">Function Invoke-Speech {
<#
.SYNOPSIS
This functions allows you to make a computer speak.
.DESCRIPTION
This function allows you to make Windows talk with the voice of either Microsoft David or Microsoft Zira.
.EXAMPLE
PS C:\> Invoke-Speech -Gender Female -Message "You Sir, look like you are ready for a coffee break."
.NOTES
Version : 5.0+ Verified
Author/Copyright : © Matthew Kerfoot - All Rights Reserved
Email/Blog/Twitter : mkkerfoot@gmail.com www.TheOvernightAdmin.com @mkkerfoot
Disclaimer : THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK
OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
While these scripts are tested and working in my environment, it is recommended
that you test these scripts in a test environment before using in your production environment
Matthew Kerfoot further disclaims all implied warranties including, without limitation, any
implied warranties of merchantability or of fitness for a particular purpose. The entire risk
arising out of the use or performance of this script and documentation remains with you.
In no event shall Matthew Kerfoot, its authors, or anyone else involved in the creation, production,
or delivery of this script/tool be liable for any damages whatsoever (including, without limitation,
damages for loss of business profits, business comerruption, loss of business information, or other
pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation,
even if Matthew Kerfoot has been advised of the possibility of such damages
Assumptions : ExecutionPolicy of AllSigned (recommended), RemoteSigned or Unrestricted (not recommended)
#>
[CmdletBinding(SupportsShouldProcess)]
Param(
[Parameter(Mandatory=$True, ValueFromPipelineByPropertyName=$true, HelpMessage = "David or Zira?", Position=0)]
$Gender,
[Parameter(Mandatory=$True, ValueFromPipelineByPropertyName=$true, HelpMessage = "What would you like to say?", Position=1)]
$Message
)
$Voice = New-Object -ComObject sapi.spvoice
Switch($Gender)
{
Male { $Voice.Voice = $Voice.GetVoices().Item("0") ; $Voice.Speak($Message) }
Female { $Voice.Voice = $Voice.GetVoices().Item("1") ; $Voice.Speak($Message) }
Default { $Voice.Speak($Message) } <# Microsofts default is Male. #>
}
}
Invoke-Speech -Gender Female -Message "You Sir, look like you are ready for a coffee break."</pre>
BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0tag:blogger.com,1999:blog-6417475995992020348.post-63813824853533435542015-08-02T12:05:00.000-05:002015-08-02T13:47:46.504-05:00How to enable Windows 10 dark themeWell Windows 10 was released to the general public last week on 7/29/2015. Since then I found out about a cool tweak you can make with just a slight adjustment, This will likely be added to the PC Setting context menu in the future as a toggle button but for now you still have to manually add it by creating a single registry key. Wait really that's it, Yes it is!<br />
<br />
I threw in a quick little revert back function called <span style="background-color: white; color: blueviolet; font-family: 'Lucida Console'; font-size: 12px;">Set-LightTheme </span>just in case you don't like the dark theme(I think you are weird).<br />
<br />
<br />
<br />
<h3 style="text-align: center;">
<b><a href="https://gallery.technet.microsoft.com/scriptcenter/Enable-Windows-10-Dark-4bde0173/file/140723/1/Set-DarkTheme.ps1">Please download functions from the Microsoft Script Repository!</a></b></h3>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh04i8_xv-cm-BOwQzXmeSNaUBxmWAfbaY3QtZVVMKdUnj-4g16J1698E3q3HqBU_mA2rALBmpjs_0uEubu5JGd0m8QKmcgUTy1Qt82aBPtfhSiWaWbZMIXz7oZrA1lUOihpYC9aD8OUhg/s1600/theme2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="498" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh04i8_xv-cm-BOwQzXmeSNaUBxmWAfbaY3QtZVVMKdUnj-4g16J1698E3q3HqBU_mA2rALBmpjs_0uEubu5JGd0m8QKmcgUTy1Qt82aBPtfhSiWaWbZMIXz7oZrA1lUOihpYC9aD8OUhg/s640/theme2.PNG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWvaSvhiDfeFCkOtdQ1jcCjPbVa-iViIFKvIU2GndnRPsHsdaiBU7QFKl88HSJlnAMCS7O9ujfud-KVygiKtoRnWSe7xNF1SCUPzUyA5f45rNSfwDh9rzsfcndnOEgAfFQMaQ6hFfNG5M/s1600/darktheme.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="496" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWvaSvhiDfeFCkOtdQ1jcCjPbVa-iViIFKvIU2GndnRPsHsdaiBU7QFKl88HSJlnAMCS7O9ujfud-KVygiKtoRnWSe7xNF1SCUPzUyA5f45rNSfwDh9rzsfcndnOEgAfFQMaQ6hFfNG5M/s640/darktheme.PNG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJrXq5zkfTrqILAAuQctZyISQPeGCXO70ChIo24xyxMUpBI0buQ4SXOzDTHAj3yX7sBVqjGlL59u761xfIqzdmeRyIUyPO7wWwVqnQ17vO9FnqjF1BxP8Qc5cCnaMDjcUvmuXzS-oVRZY/s1600/theme3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="497" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJrXq5zkfTrqILAAuQctZyISQPeGCXO70ChIo24xyxMUpBI0buQ4SXOzDTHAj3yX7sBVqjGlL59u761xfIqzdmeRyIUyPO7wWwVqnQ17vO9FnqjF1BxP8Qc5cCnaMDjcUvmuXzS-oVRZY/s640/theme3.PNG" width="640" /></a></div>
<br />
<br />
<br />
<div style="color: black; font-family: 'Segoe UI'; font-size: 12px; font-style: normal; text-align: left;">
<h2 style="text-align: center;">
Click <a href="https://gallery.technet.microsoft.com/scriptcenter/Enable-Windows-10-Dark-4bde0173/file/140723/1/Set-DarkTheme.ps1">here</a> to download the script from the <a href="https://gallery.technet.microsoft.com/scriptcenter/Enable-Windows-10-Dark-4bde0173/file/140723/1/Set-DarkTheme.ps1">Microsoft Script Repository</a>!</h2>
<div style="font-weight: normal;">
<br /></div>
<div style="font-weight: normal;">
<br /></div>
<div style="font-weight: normal;">
<br /></div>
<div style="font-weight: normal;">
<br /></div>
<div style="font-weight: normal;">
<br /></div>
<div style="font-weight: normal;">
<br /></div>
<div style="font-weight: normal;">
<br /></div>
<div style="font-weight: normal;">
<br /></div>
</div>
BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0Minneapolis, MN 55427, USA45.0155422 -93.37679759999997544.925730699999995 -93.538159099999973 45.1053537 -93.215436099999977tag:blogger.com,1999:blog-6417475995992020348.post-91878752132011164712015-02-18T21:10:00.001-06:002015-02-19T10:24:52.715-06:00Enable AD Recycing Bin and prevent accidental deletion for all objects<div abp="1059"><div abp="1061">We've all have heard about the new recycling bin feature that was introduced with Server 2008 R2, sadly the recycling bin is not enabled by default... I do not know why this is but I feel it is a huge mistake on Microsoft's part...</div></div><div abp="1060"><div abp="1063"><br />
</div></div>So I wrote a little function that will enable the recycling bin. But that's not it, it will also set all OUs, computer accounts and user accounts to be protected from accidental deletion. A log file is saved in C:\windows\temp as well.<br />
<br />
Preventive maintenance can be the most important maintenance. </div><br />
<div abp="1072" style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 850px;"><table abp="1073" border="0" cellpadding="5" cellspacing="0"><tbody abp="1074">
<tr abp="1075"> <td abp="1076" valign="Top"><div abp="1077" style="background: rgb(206, 206, 206); font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;"><div abp="1078">001</div><div abp="1079">002</div><div abp="1080">003</div><div abp="1081">004</div><div abp="1082">005</div><div abp="1083">006</div><div abp="1084">007</div><div abp="1085">008</div><div abp="1086">009</div><div abp="1087">010</div><div abp="1088">011</div><div abp="1089">012</div><div abp="1090">013</div><div abp="1091">014</div><div abp="1092">015</div><div abp="1093">016</div><div abp="1094">017</div><div abp="1095">018</div><div abp="1096">019</div><div abp="1097">020</div><div abp="1098">021</div><div abp="1099">022</div><div abp="1100">023</div><div abp="1101">024</div><div abp="1102">025</div><div abp="1103">026</div><div abp="1104">027</div><div abp="1105">028</div><div abp="1106">029</div><div abp="1107">030</div><div abp="1108">031</div><div abp="1109">032</div><div abp="1110">033</div><div abp="1111">034</div><div abp="1112">035</div><div abp="1113">036</div><div abp="1114">037</div><div abp="1115">038</div><div abp="1116">039</div><div abp="1117">040</div><div abp="1118">041</div><div abp="1119">042</div><div abp="1120">043</div><div abp="1121">044</div><div abp="1122">045</div><div abp="1123">046</div><div abp="1124">047</div><div abp="1125">048</div><div abp="1126">049</div><div abp="1127">050</div><div abp="1128">051</div><div abp="1129">052</div><div abp="1130">053</div><div abp="1131">054</div><div abp="1132">055</div><div abp="1133">056</div><div abp="1134">057</div><div abp="1135">058</div><div abp="1136">059</div><div abp="1137">060</div><div abp="1138">061</div><div abp="1139">062</div><div abp="1140">063</div><div abp="1141">064</div><div abp="1142">065</div></div></td> <td abp="1143" nowrap="NOWRAP" valign="Top"><div abp="1144" style="background: rgb(252, 252, 252); font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;"><div abp="1145"><span abp="1146" style="color: darkblue;">Function</span><span abp="1147" style="color: black;"> </span><span abp="1148" style="color: blueviolet;">Set-ADSafeMode</span><span abp="1149" style="color: black;"> </span><span abp="1150" style="color: black;">{</span></div><div abp="1151"><span abp="1152" style="color: darkgreen;"><#<br abp="1153" /> .CREATED BY:<br abp="1154" /> Matthew A. Kerfoot<br abp="1155" /> .CREATED ON:<br abp="1156" /> 2/18/2015<br abp="1157" /> .Synopsis<br abp="1158" /> Enables the AD recycling Bin and prevents all OUs\computer\users accounts from accidental deletion.<br abp="1159" /> .DESCRIPTION<br abp="1160" /> Checks the AD recycling bin to see if it is enabled, if not it will enable it. Then it checks all OUs `<br abp="1161" /> in the domain to see if they are being prevented from accidental deletion, if not it will check the `<br abp="1162" /> check box that prevents them from accidental deletion. This is also done for all user and computer accounts on your domain.<br abp="1163" /> .FUNCTIONALITY<br abp="1164" /> PowerShell v2 (must be ran from a DC(the activedirectory module is required))<br abp="1165" /> #></span></div><div abp="1166"><span abp="1167" style="color: darkgrey;">[</span><span abp="1168" style="color: deepskyblue;">CmdletBinding</span><span abp="1169" style="color: black;">(</span><span abp="1170" style="color: black;">SupportsShouldProcess</span><span abp="1171" style="color: darkgrey;">=</span><span abp="1172" style="color: orangered;">$True</span><span abp="1173" style="color: black;">)</span><span abp="1174" style="color: darkgrey;">]</span></div><div abp="1175"><span abp="1176" style="color: darkblue;">param</span><span abp="1177" style="color: black;">(</span></div><div abp="1178"><span abp="1179" style="color: black;"> </span><span abp="1180" style="color: darkgrey;">[</span><span abp="1181" style="color: deepskyblue;">Parameter</span><span abp="1182" style="color: black;">(</span><span abp="1183" style="color: black;">Mandatory</span><span abp="1184" style="color: darkgrey;">=</span><span abp="1185" style="color: orangered;">$false</span><span abp="1186" style="color: darkgrey;">,</span><span abp="1187" style="color: black;">ValueFromPipeline</span><span abp="1188" style="color: darkgrey;">=</span><span abp="1189" style="color: orangered;">$true</span><span abp="1190" style="color: black;">)</span><span abp="1191" style="color: darkgrey;">]</span></div><div abp="1192"><span abp="1193" style="color: black;"> </span><span abp="1194" style="color: teal;">[string]</span><span abp="1195" style="color: orangered;">$VerbosePreference</span><span abp="1196" style="color: black;"> </span><span abp="1197" style="color: darkgrey;">=</span><span abp="1198" style="color: black;"> </span><span abp="1199" style="color: darkred;">"SilentlyContinue"</span><span abp="1200" style="color: darkgrey;">,</span></div><div abp="1201"><span abp="1202" style="color: black;"> </span><span abp="1203" style="color: darkgrey;">[</span><span abp="1204" style="color: deepskyblue;">Parameter</span><span abp="1205" style="color: black;">(</span><span abp="1206" style="color: black;">Mandatory</span><span abp="1207" style="color: darkgrey;">=</span><span abp="1208" style="color: orangered;">$false</span><span abp="1209" style="color: darkgrey;">,</span><span abp="1210" style="color: black;">ValueFromPipeline</span><span abp="1211" style="color: darkgrey;">=</span><span abp="1212" style="color: orangered;">$true</span><span abp="1213" style="color: black;">)</span><span abp="1214" style="color: darkgrey;">]</span></div><div abp="1215"><span abp="1216" style="color: black;"> </span><span abp="1217" style="color: teal;">[string]</span><span abp="1218" style="color: orangered;">$ErrorActionPreference</span><span abp="1219" style="color: black;"> </span><span abp="1220" style="color: darkgrey;">=</span><span abp="1221" style="color: black;"> </span><span abp="1222" style="color: darkred;">"SilentlyContinue"</span><span abp="1223" style="color: darkgrey;">,</span></div><div abp="1224"><span abp="1225" style="color: black;"> </span><span abp="1226" style="color: darkgrey;">[</span><span abp="1227" style="color: deepskyblue;">Parameter</span><span abp="1228" style="color: black;">(</span><span abp="1229" style="color: black;">Mandatory</span><span abp="1230" style="color: darkgrey;">=</span><span abp="1231" style="color: orangered;">$false</span><span abp="1232" style="color: darkgrey;">,</span><span abp="1233" style="color: black;">ValueFromPipeline</span><span abp="1234" style="color: darkgrey;">=</span><span abp="1235" style="color: orangered;">$true</span><span abp="1236" style="color: black;">)</span><span abp="1237" style="color: darkgrey;">]</span></div><div abp="1238"><span abp="1239" style="color: black;"> </span><span abp="1240" style="color: teal;">[string[]]</span><span abp="1241" style="color: orangered;">$LogDate</span><span abp="1242" style="color: black;"> </span><span abp="1243" style="color: darkgrey;">=</span><span abp="1244" style="color: black;"> </span><span abp="1245" style="color: black;">(</span><span abp="1246" style="color: blue;">get-date</span><span abp="1247" style="color: black;"> </span><span abp="1248" style="color: navy;">-format</span><span abp="1249" style="color: black;"> </span><span abp="1250" style="color: darkred;">"MM-d-yy-HH"</span><span abp="1251" style="color: black;">)</span></div><div abp="1252"><span abp="1253" style="color: black;"> </span><span abp="1254" style="color: black;">)</span></div><div abp="1255"><br />
</div><div abp="1256"><span abp="1257" style="color: darkblue;">Function</span><span abp="1258" style="color: black;"> </span><span abp="1259" style="color: blueviolet;">global:Write-Verbose</span><span abp="1260" style="color: black;"> </span><span abp="1261" style="color: black;">{</span><span abp="1262" style="color: black;"> </span><span abp="1263" style="color: teal;">[string]</span><span abp="1264" style="color: black;"> </span><span abp="1265" style="color: orangered;">$Message</span><span abp="1266" style="color: black;"> </span><span abp="1267" style="color: black;">}</span></div><div abp="1268"><br />
</div><div abp="1269"><span abp="1270" style="color: blue;">Import-Module</span><span abp="1271" style="color: black;"> </span><span abp="1272" style="color: blueviolet;">activedirectory</span></div><div abp="1273"><br />
</div><div abp="1274"><span abp="1275" style="color: orangered;">$VerbosePreference</span><span abp="1276" style="color: black;"> </span><span abp="1277" style="color: darkgrey;">=</span><span abp="1278" style="color: black;"> </span><span abp="1279" style="color: darkred;">"Continue"</span></div><div abp="1280"><br />
</div><div abp="1281"><span abp="1282" style="color: blue;">Start-Transcript</span><span abp="1283" style="color: black;"> </span><span abp="1284" style="color: navy;">-Path</span><span abp="1285" style="color: black;"> </span><span abp="1286" style="color: darkred;">"C:\Windows\temp\$LogDate.log"</span></div><div abp="1287"><br />
</div><div abp="1288"><span abp="1289" style="color: darkgreen;">#More or less turns on and\or enables logging to begin.</span></div><div abp="1290"><span abp="1291" style="color: blue;">Write-Verbose</span></div><div abp="1292"><br />
</div><div abp="1293"><span abp="1294" style="color: orangered;">$Bin</span><span abp="1295" style="color: black;"> </span><span abp="1296" style="color: darkgrey;">=</span><span abp="1297" style="color: black;"> </span><span abp="1298" style="color: blue;">Get-ADOptionalFeature</span><span abp="1299" style="color: black;"> </span><span abp="1300" style="color: navy;">-Filter</span><span abp="1301" style="color: black;"> </span><span abp="1302" style="color: darkred;">'name -like "Recycle Bin Feature"'</span><span abp="1303" style="color: black;"> </span><span abp="1304" style="color: navy;">-Properties</span><span abp="1305" style="color: black;"> </span><span abp="1306" style="color: blueviolet;">IsDisableable</span><span abp="1307" style="color: black;"> </span><span abp="1308" style="color: darkgrey;">|</span><span abp="1309" style="color: black;"> </span>`</div><div abp="1310"><span abp="1311" style="color: black;"> </span><span abp="1312" style="color: blue;">Select</span><span abp="1313" style="color: black;"> </span><span abp="1314" style="color: black;">@{</span><span abp="1315" style="color: black;"> </span><span abp="1316" style="color: black;">Name</span><span abp="1317" style="color: black;"> </span><span abp="1318" style="color: darkgrey;">=</span><span abp="1319" style="color: black;"> </span><span abp="1320" style="color: darkred;">"NeedsToBeEnabled"</span><span abp="1321" style="color: black;"> </span><span abp="1322" style="color: black;">;</span><span abp="1323" style="color: black;"> </span><span abp="1324" style="color: black;">Expression</span><span abp="1325" style="color: black;"> </span><span abp="1326" style="color: darkgrey;">=</span><span abp="1327" style="color: black;"> </span><span abp="1328" style="color: black;">{</span><span abp="1329" style="color: black;"> </span><span abp="1330" style="color: black;">(</span><span abp="1331" style="color: black;"> </span><span abp="1332" style="color: orangered;">$_</span><span abp="1333" style="color: darkgrey;">.</span><span abp="1334" style="color: black;">IsDisableable</span><span abp="1335" style="color: black;"> </span><span abp="1336" style="color: black;">)</span><span abp="1337" style="color: black;"> </span><span abp="1338" style="color: black;">}</span><span abp="1339" style="color: black;"> </span><span abp="1340" style="color: black;">}</span></div><div abp="1341"><br />
</div><div abp="1342"><span abp="1343" style="color: black;"> </span><span abp="1344" style="color: darkblue;">If</span><span abp="1345" style="color: black;"> </span><span abp="1346" style="color: black;">(</span><span abp="1347" style="color: orangered;">$Bin</span><span abp="1348" style="color: darkgrey;">.</span><span abp="1349" style="color: black;">NeedsToBeEnabled</span><span abp="1350" style="color: black;"> </span><span abp="1351" style="color: darkgrey;">-eq</span><span abp="1352" style="color: black;"> </span><span abp="1353" style="color: orangered;">$False</span><span abp="1354" style="color: black;">)</span></div><div abp="1355"><span abp="1356" style="color: black;"> </span><span abp="1357" style="color: black;">{</span></div><div abp="1358"><span abp="1359" style="color: black;"> </span><span abp="1360" style="color: blue;">Write-Host</span><span abp="1361" style="color: black;"> </span><span abp="1362" style="color: darkred;">"The Active Directory Recycling Bin has already been enabled!"</span><span abp="1363" style="color: black;"> </span><span abp="1364" style="color: navy;">-ForegroundColor</span><span abp="1365" style="color: black;"> </span><span abp="1366" style="color: darkred;">"Green"</span></div><div abp="1367"><span abp="1368" style="color: black;"> </span><span abp="1369" style="color: black;">}</span></div><div abp="1370"><span abp="1371" style="color: black;"> </span><span abp="1372" style="color: darkblue;">Else</span></div><div abp="1373"><span abp="1374" style="color: black;"> </span><span abp="1375" style="color: black;">{</span></div><div abp="1376"><span abp="1377" style="color: black;"> </span><span abp="1378" style="color: blue;">Write-Host</span><span abp="1379" style="color: black;"> </span><span abp="1380" style="color: darkred;">"The Active Directory Recycling Bin NEEDS TO BE ENABLED!"</span><span abp="1381" style="color: black;"> </span><span abp="1382" style="color: navy;">-ForegroundColor</span><span abp="1383" style="color: black;"> </span><span abp="1384" style="color: darkred;">"Red"</span></div><div abp="1385"><br />
</div><div abp="1386"><span abp="1387" style="color: black;"> </span><span abp="1388" style="color: blue;">Enable-ADOptionalFeature</span><span abp="1389" style="color: black;"> </span><span abp="1390" style="color: darkred;">'Recycle Bin Feature'</span><span abp="1391" style="color: black;"> </span><span abp="1392" style="color: navy;">-Scope</span><span abp="1393" style="color: black;"> </span><span abp="1394" style="color: blueviolet;">ForestOrConfigurationSet</span><span abp="1395" style="color: black;"> </span><span abp="1396" style="color: navy;">-Target</span><span abp="1397" style="color: black;"> </span><span abp="1398" style="color: orangered;">$env:USERDOMAIN</span><span abp="1399" style="color: black;"> </span><span abp="1400" style="color: navy;">-WhatIf</span></div><div abp="1401"><br />
</div><div abp="1402"><span abp="1403" style="color: black;"> </span><span abp="1404" style="color: blue;">Write-Host</span><span abp="1405" style="color: black;"> </span><span abp="1406" style="color: darkred;">"The Active Directory Recycling has now been enabled!!"</span><span abp="1407" style="color: black;"> </span><span abp="1408" style="color: navy;">-ForegroundColor</span><span abp="1409" style="color: black;"> </span><span abp="1410" style="color: darkred;">"Red"</span></div><div abp="1411"><span abp="1412" style="color: black;"> </span><span abp="1413" style="color: black;">}</span></div><div abp="1414"><br />
</div><div abp="1415"><span abp="1416" style="color: black;"> </span><span abp="1417" style="color: darkgreen;">#Sets all OU to be protewcted against accidental deletion</span></div><div abp="1418"><span abp="1419" style="color: black;"> </span><span abp="1420" style="color: blue;">Get-ADOrganizationalUnit</span><span abp="1421" style="color: black;"> </span><span abp="1422" style="color: navy;">-filter</span><span abp="1423" style="color: black;"> </span><span abp="1424" style="color: blueviolet;">*</span><span abp="1425" style="color: black;"> </span><span abp="1426" style="color: navy;">-Properties</span><span abp="1427" style="color: black;"> </span><span abp="1428" style="color: blueviolet;">ProtectedFromAccidentalDeletion</span><span abp="1429" style="color: black;"> </span><span abp="1430" style="color: darkgrey;">|</span><span abp="1431" style="color: black;"> </span>`</div><div abp="1432"><span abp="1433" style="color: black;"> </span><span abp="1434" style="color: blue;">Set-ADOrganizationalUnit</span><span abp="1435" style="color: black;"> </span><span abp="1436" style="color: navy;">-ProtectedFromAccidentalDeletion</span><span abp="1437" style="color: black;"> </span><span abp="1438" style="color: orangered;">$true</span><span abp="1439" style="color: black;"> </span><span abp="1440" style="color: navy;">-Verbose</span><span abp="1441" style="color: black;"> </span><span abp="1442" style="color: navy;">-WhatIf</span></div><div abp="1443"><br />
</div><div abp="1444"><span abp="1445" style="color: black;"> </span><span abp="1446" style="color: darkgreen;">#Sets all user and Computer accounts to be protected from accidental deletion</span></div><div abp="1447"><span abp="1448" style="color: black;"> </span><span abp="1449" style="color: blue;">Get-ADObject</span><span abp="1450" style="color: black;"> </span><span abp="1451" style="color: navy;">-filter</span><span abp="1452" style="color: black;"> </span><span abp="1453" style="color: blueviolet;">*</span><span abp="1454" style="color: black;"> </span><span abp="1455" style="color: navy;">-Properties</span><span abp="1456" style="color: black;"> </span><span abp="1457" style="color: blueviolet;">ProtectedFromAccidentalDeletion</span><span abp="1458" style="color: black;"> </span><span abp="1459" style="color: darkgrey;">|</span><span abp="1460" style="color: black;"> </span><span abp="1461" style="color: blue;">Where-Object</span><span abp="1462" style="color: black;"> </span><span abp="1463" style="color: black;">{</span><span abp="1464" style="color: orangered;">$_</span><span abp="1465" style="color: darkgrey;">.</span><span abp="1466" style="color: black;">ObjectClass</span><span abp="1467" style="color: black;"> </span><span abp="1468" style="color: darkgrey;">-eq</span><span abp="1469" style="color: black;"> </span><span abp="1470" style="color: darkred;">"user"</span><span abp="1471" style="color: black;"> </span><span abp="1472" style="color: darkgrey;">-or</span><span abp="1473" style="color: black;"> </span><span abp="1474" style="color: orangered;">$_</span><span abp="1475" style="color: darkgrey;">.</span><span abp="1476" style="color: black;">ObjectClass</span><span abp="1477" style="color: black;"> </span><span abp="1478" style="color: darkgrey;">-eq</span><span abp="1479" style="color: black;"> </span><span abp="1480" style="color: darkred;">"Computer"</span><span abp="1481" style="color: black;">}</span><span abp="1482" style="color: black;"> </span><span abp="1483" style="color: darkgrey;">|</span><span abp="1484" style="color: black;"> </span><span abp="1485" style="color: blue;">Set-ADObject</span><span abp="1486" style="color: black;"> </span><span abp="1487" style="color: navy;">-ProtectedFromAccidentalDeletion</span><span abp="1488" style="color: black;"> </span><span abp="1489" style="color: orangered;">$true</span><span abp="1490" style="color: black;"> </span><span abp="1491" style="color: navy;">-WhatIf</span></div><div abp="1492"><br />
</div><div abp="1493"><span abp="1494" style="color: black;"> </span><span abp="1495" style="color: blue;">Write-Host</span><span abp="1496" style="color: black;"> </span><span abp="1497" style="color: darkred;">"Script Completed Successfully!"</span><span abp="1498" style="color: black;"> </span><span abp="1499" style="color: navy;">-ForegroundColor</span><span abp="1500" style="color: black;"> </span><span abp="1501" style="color: darkred;">"Green"</span><span abp="1502" style="color: black;"> </span><span abp="1503" style="color: darkgrey;">|</span><span abp="1504" style="color: black;"> </span><span abp="1505" style="color: blue;">Tee-Object</span><span abp="1506" style="color: black;"> </span><span abp="1507" style="color: darkred;">"C:\Windows\temp\$LogDate.log"</span><span abp="1508" style="color: black;"> </span><span abp="1509" style="color: navy;">-Verbose</span></div><div abp="1510"><br />
</div><div abp="1511"><span abp="1512" style="color: darkgreen;">#Ends the logfile</span></div><div abp="1513"><span abp="1514" style="color: blue;">Stop-Transcript</span></div><div abp="1515"><br />
</div><div abp="1516"><span abp="1517" style="color: black;"> </span><span abp="1518" style="color: black;">}</span><span abp="1519" style="color: black;"> </span><span abp="1520" style="color: blue;">Set-ADSafeMode</span> </div></div></td> </tr>
</tbody> </table></div><div abp="1521"><br />
</div><div abp="1438" style="text-align: center;"><div abp="1439"><div abp="1524">If you prevent fires you don't have to put out fires...</div></div></div></div>BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0Hennepin County, MN, USA44.991267058408312 -93.413876457421844.901455558408308 -93.575237957421791 45.081078558408315 -93.2525149574218tag:blogger.com,1999:blog-6417475995992020348.post-51257658596107657822014-12-04T09:50:00.000-06:002015-02-19T10:25:53.460-06:00PowerShell Counters<div abp="999"> Last night we received an alert for the following "SQLServer:Locks: Average Wait Time (ms) is above it's currently configured threshold"... What an obscure alert, that I see far too often. Here’s the PowerShell way to check if this has been resolved.</div><div abp="1000"><br />
</div><div abp="1001"><a abp="1002" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghNr0Ufls3mQvs2H15N9SnN0GIoYtK-lYVbfsAmfpIIh6Bj2ff4dmspGcfwGd_Mjv00vWSARKi8hYI4FA3J2tuJvmDLUVxTbMD1Wtg4bX6MYDHApKVFxRFLRboJplGvh3RVyibGO0yqvA/s1600/admin.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img abp="1003" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghNr0Ufls3mQvs2H15N9SnN0GIoYtK-lYVbfsAmfpIIh6Bj2ff4dmspGcfwGd_Mjv00vWSARKi8hYI4FA3J2tuJvmDLUVxTbMD1Wtg4bX6MYDHApKVFxRFLRboJplGvh3RVyibGO0yqvA/s1600/admin.jpg" height="168" width="200" /></a></div><div abp="1004"><br />
</div><div abp="1005">First we need to open a PowerShell console on the machine in question as an Administrator to get the correct SQL counter set name.</div><div abp="1006"><br />
</div><div abp="1007" style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 425px;"><table abp="1008" border="0" cellpadding="5" cellspacing="0"><tbody abp="1009">
<tr abp="1010"> <td abp="1011" valign="Top"><div abp="1012" style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><div abp="1013">001</div></div></td> <td abp="1014" nowrap="NOWRAP" valign="Top"><div abp="1015" style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><div abp="1016"><span abp="1017" style="color: blue;">Get-Counter</span> <span abp="1018" style="color: navy;">-ListSet</span> <span abp="1019" style="color: blueviolet;">*</span> <span abp="1020" style="color: darkgrey;">|</span> <span abp="1021" style="color: blue;">select</span> <span abp="1022" style="color: blueviolet;">CounterSetName</span> </div></div></td> </tr>
</tbody> </table></div><div abp="1023"><br />
</div><div abp="1024" class="separator" style="clear: both; text-align: center;"><a abp="1025" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1bxMR-dOjVMrRCs2dZsyvyCSnQADrO570_fvPQIPc3d27WxDnlhIFy1ytZBfWcJVBGZDGvpIchxc_kL0626gyMjaHTs7Ro9pY2NqINW8QLpUUlD98QL44679YAAU7HgWLoyV8o4ikWhQ/s1600/SQL_COUNTER3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img abp="1026" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1bxMR-dOjVMrRCs2dZsyvyCSnQADrO570_fvPQIPc3d27WxDnlhIFy1ytZBfWcJVBGZDGvpIchxc_kL0626gyMjaHTs7Ro9pY2NqINW8QLpUUlD98QL44679YAAU7HgWLoyV8o4ikWhQ/s1600/SQL_COUNTER3.png" /></a></div><div abp="1027"><br />
</div><div abp="1028">Okay so that does give us all the information we are requesting but in order to get a nice output that only contains SQL counters we could filter out all counters that do NOT have <span abp="1029" style="background-color: #fcfcfc; color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13px; white-space: nowrap;">*SQL*</span> in the name.</div><div abp="1030"><br />
</div><div abp="1031" style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750px;"><table abp="1032" border="0" cellpadding="5" cellspacing="0"><tbody abp="1033">
<tr abp="1034"> <td abp="1035" valign="Top"><div abp="1036" style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><div abp="1037">001</div></div></td> <td abp="1038" nowrap="NOWRAP" valign="Top"><div abp="1039" style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><div abp="1040"><span abp="1041" style="color: blue;">Get-Counter</span> <span abp="1042" style="color: navy;">-ListSet</span> <span abp="1043" style="color: blueviolet;">*</span> <span abp="1044" style="color: darkgrey;">|</span> <span abp="1045" style="color: blue;">select</span> <span abp="1046" style="color: blueviolet;">CounterSetName</span> <span abp="1047" style="color: darkgrey;">|</span> <span abp="1048" style="color: blue;">Where-Object</span> {<span abp="1049" style="color: orangered;">$_</span><span abp="1050" style="color: darkgrey;">.</span>CounterSetName <span abp="1051" style="color: darkgrey;">-like</span> <span abp="1052" style="color: darkred;">"*SQL*"</span>} </div></div></td> </tr>
</tbody> </table></div><div abp="1053"><br />
</div><div abp="1054" class="separator" style="clear: both; text-align: center;"><br />
</div><div abp="1055" class="separator" style="clear: both; text-align: center;"><a abp="1056" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisHymQbJv3Qnqk8oyOHMlWw0aaNi5Oca4op4VEx8I1eMrGhKIU8CwZafGYUa8mktPJwX6IhZJLl0094nYU2YQIK5RA9gK8hV61MSXk-85ZH6BjLhCTp2pQ-G3XVUtGbjROyb8cmKmMqdg/s1600/sql_counter5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img abp="1057" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisHymQbJv3Qnqk8oyOHMlWw0aaNi5Oca4op4VEx8I1eMrGhKIU8CwZafGYUa8mktPJwX6IhZJLl0094nYU2YQIK5RA9gK8hV61MSXk-85ZH6BjLhCTp2pQ-G3XVUtGbjROyb8cmKmMqdg/s1600/sql_counter5.png" /></a></div><div abp="1058"><br />
</div><div abp="1059">Now that we know the counter set name is "SQLServer:Locks" we can run the following command to see a list of the counters within SQLServer:Locks.</div><div abp="1060"><br />
</div><div abp="1061" style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750px;"><table abp="1062" border="0" cellpadding="5" cellspacing="0"><tbody abp="1063">
<tr abp="1064"> <td abp="1065" valign="Top"><div abp="1066" style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><div abp="1067">001</div></div></td> <td abp="1068" nowrap="NOWRAP" valign="Top"><div abp="1069" style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><div abp="1070"><span abp="1071" style="color: blue;">Get-Counter</span> <span abp="1072" style="color: navy;">-ListSet</span> <span abp="1073" style="color: blueviolet;">SQLServer:Locks</span> <span abp="1074" style="color: darkgrey;">|</span> <span abp="1075" style="color: blue;">Select-Object</span> <span abp="1076" style="color: blueviolet;">Counter</span> <span abp="1077" style="color: navy;">-ExpandProperty</span> <span abp="1078" style="color: blueviolet;">Counter</span> </div></div></td> </tr>
</tbody> </table></div><div abp="1079"><br />
</div><div abp="1080" class="separator" style="clear: both; text-align: center;"><a abp="1081" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMT2sCeUXH1OZwmjDugmVtSOiWFKPqqugiLNAHAUYvzLi_NgRv6wVuOI-3d9HPf_B4SfLjiPemHf1mEjS8QrqlIFye6rPkDMDqjlm-P8tCAO72IWzvKVeeXaOyHUFWn0dU_HGiOz6UdAc/s1600/SQL_COUNTER6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img abp="1082" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMT2sCeUXH1OZwmjDugmVtSOiWFKPqqugiLNAHAUYvzLi_NgRv6wVuOI-3d9HPf_B4SfLjiPemHf1mEjS8QrqlIFye6rPkDMDqjlm-P8tCAO72IWzvKVeeXaOyHUFWn0dU_HGiOz6UdAc/s1600/SQL_COUNTER6.png" /></a></div><div abp="1083"><br />
</div><div abp="1084">From here it is as easy as:</div><div abp="1085"><br />
</div><div abp="1086" style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750px;"><table abp="1087" border="0" cellpadding="5" cellspacing="0"><tbody abp="1088">
<tr abp="1089"> <td abp="1090" valign="Top"><div abp="1091" style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><div abp="1092">001</div></div></td> <td abp="1093" nowrap="NOWRAP" valign="Top"><div abp="1094" style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><div abp="1095"><span abp="1096" style="color: blue;">Get-Counter</span> <span abp="1097" style="color: navy;">-Counter</span> <span abp="1098" style="color: darkred;">"\SQLServer:Locks(*)\Lock Wait Time (ms)"</span> </div></div></td> </tr>
</tbody> </table></div><div abp="1099"><br />
</div><div abp="1100">There are a few gotchas however, you will <span style="color: red;">need quotes around the counter name</span> because it contains spaces and this<span style="color: red;"> must be ran in an administrative shell</span>.</div><div abp="1101" class="separator" style="clear: both; text-align: center;"><br />
</div><div abp="1102"><br />
</div><div abp="1103" class="separator" style="clear: both; text-align: center;"><a abp="1104" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwABsFFdFvAHewXphyphenhyphen0pOZQVpwfXYFPb_OBmgtnaH6zVWoIHCvwXG9WaSmAQ9BBCX__A1sv54DrmWbGO8JPvmf_22_K-7QM9cyL9e8j3K0Vo9ersd3J7baqlssxnqV5Ek0BdBAZ7uSfws/s1600/SQL_COUNTER7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img abp="1105" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwABsFFdFvAHewXphyphenhyphen0pOZQVpwfXYFPb_OBmgtnaH6zVWoIHCvwXG9WaSmAQ9BBCX__A1sv54DrmWbGO8JPvmf_22_K-7QM9cyL9e8j3K0Vo9ersd3J7baqlssxnqV5Ek0BdBAZ7uSfws/s1600/SQL_COUNTER7.png" /></a></div><div abp="1106"><br />
</div><div abp="1107">As shown above the average lock wait time has been reduced to 0 which tells me this alert has now cleared out. Below I've added some more popular cmdlets to this command to get a little more data at an interval that you can specify.</div><div abp="1108"><br />
</div><div abp="1109" style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750px;"><table abp="1110" border="0" cellpadding="5" cellspacing="0"><tbody abp="1111">
<tr abp="1112"> <td abp="1113" valign="Top"><div abp="1114" style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><div abp="1115">001</div></div></td> <td abp="1116" nowrap="NOWRAP" valign="Top"><div abp="1117" style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><div abp="1118"><span abp="1119" style="color: blue;">Get-Counter</span> <span abp="1120" style="color: navy;">-Counter</span> <span abp="1121" style="color: darkred;">"\SQLServer:Locks(*)\Lock Wait Time (ms)"</span> <span abp="1122" style="color: navy;">-SampleInterval</span> <span abp="1123" style="color: purple;">10</span> <span abp="1124" style="color: navy;">-MaxSamples</span> <span abp="1125" style="color: purple;">3</span> </div></div></td> </tr>
</tbody> </table></div><div abp="1126" class="MsoNormal"><div abp="1127"><o:p abp="1128"></o:p><br />
</div></div><div abp="1129" class="separator" style="clear: both; text-align: center;"><br />
</div><div abp="1130"><br />
</div><div abp="1131" class="separator" style="clear: both; text-align: center;"><br />
</div>BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0United States37.09024 -95.712891000000013-36.4181565 99.052733999999987 90 69.521483999999987tag:blogger.com,1999:blog-6417475995992020348.post-40200509289072632892014-11-01T09:21:00.000-05:002014-11-11T03:18:21.617-06:00PowerShell Desired State Configuration Pull Server (To be continued)PowerShell Desired State Configuration was just released with PowerShell v4.0 and\or Windows Server 2012 R2 and Windows 8.1.<br />
<br />
First off if you are not already familiar with DSC please take a look at Windows <a href="http://technet.microsoft.com/en-us/library/dn249912.aspx">PowerShell Desired State Configuration Overview</a>. PowerShell Desired State Configuration or DSC for short can be used to either setup or keep a specified configuration<br />
<pre class="PoshConsole">Add-WindowsFeature Dsc-Service</pre><h1><b>Defining $ConfigurationData</b></h1>I started my Script off by defining $ConfigurationData [Shown Below]. This is where you can specify the computer names you want the pull server to create .MOFs for. Everything listed after NodeName will automatically installed on the given server and will be constantly monitored at any specified interval Fifteen minutes or above. So by just adding ,"Server-Gui-Shell" to the inside of any NodeName bracket you can install server graphical shell. You could also prevent server graphical shell and ensure it doesn't get installed for more than Fifteen minutes, but that come later.<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;"><table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014</div></td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><span style="color: orangered;">$ConfigurationData</span> <span style="color: darkgrey;">=</span> @{<br />
AllNodes <span style="color: darkgrey;">=</span> @(<br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"MKDC-02"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"AD-Domain-Services"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"DHCP"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"DNS"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"SERVER2012R2-01"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span>;Service<span style="color: darkgrey;">=</span><span style="color: darkred;">"BITS"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"vmms"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"SERVER2012R2-02"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span>;Service<span style="color: darkgrey;">=</span><span style="color: darkred;">"BITS"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"vmms"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"SERVER2012R2-03"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span>;Service<span style="color: darkgrey;">=</span><span style="color: darkred;">"BITS"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"vmms"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"PSDSCPULLSERVER"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"DSC-Service"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span>;Service<span style="color: darkgrey;">=</span><span style="color: darkred;">"BITS"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"vmms"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"MKDFS-01"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"Web"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"MKDFS-02"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"FileShare"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"RODC"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"Web"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"AD-Domain-Services"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"MKPSWA"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"FileShare"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"WindowsPowerShellWebAccess"</span>}<br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"PSWAW12"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"FileShare"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"WindowsPowerShellWebAccess"</span>}<br />
)<br />
} </div></td> </tr>
</tbody> </table></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><h1>Defining LCM</h1>Next I defined my Local Configuration Manager, which is more or less the brains of the operation by telling all client computers where to retrieve their .MOF configuration files from. This is also where you specify the intervals and setting that are needed while configuring a PS DSC Server. I created a pull server which basically means I'll have a Server 2012R2 or maybe a Windows 8.1 box hosting the .MOF configuration files for all the servers to go reach out to. This will happen at the time specified in the ConfigurationModeFrequencyMins variable.<br />
<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;"><table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015<br />
016<br />
017<br />
018<br />
019<br />
020<br />
021<br />
022</div></td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><span style="color: darkblue;">Configuration</span> <span style="color: blueviolet;">Copy_PowerShell_Scripts</span> {<br />
Node <span style="color: orangered;">$AllNodes</span><span style="color: darkgrey;">.</span>NodeName<br />
{<br />
file <span style="color: darkred;">"PowerShell_PROFILE_script"</span><br />
{<br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
type <span style="color: darkgrey;">=</span> <span style="color: darkred;">"File"</span><br />
SourcePath <span style="color: darkgrey;">=</span> <span style="color: darkred;">"\\PSDSCPULLSERVER\DSC Configurations\PowerShellScripts\profile.ps1"</span><br />
MatchSource <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$True"</span><br />
DestinationPath <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$PROFILE"</span><br />
}<br />
file <span style="color: darkred;">"Copy_\\PSDSCPULLSERVER\DSC_Configurations\PowerShellScripts__TO__$env:USERPROFILE\Desktop\PowerShell"</span><br />
{<br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
type <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Directory"</span><br />
SourcePath <span style="color: darkgrey;">=</span> <span style="color: darkred;">"\\PSDSCPULLSERVER\DSC Configurations\PowerShellScripts"</span><br />
MatchSource <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$True"</span><br />
Recurse <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$True"</span><br />
DestinationPath <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$env:USERPROFILE\Desktop\PowerShell"</span><br />
}<br />
}<br />
} </div></td> </tr>
</tbody> </table></div><h1>Defining Configuration 1 of 3</h1>Next is to define all Configurations. I've included 3 configurations within my script. The first Configuration is used to ensure my saved PowerShell Profile script is copied to $PROFILE on all servers and that my saved PowerShell Scripts directory(including contents) are copied to all servers as well. <br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;"><table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015<br />
016<br />
017<br />
018<br />
019<br />
020<br />
021<br />
022</div></td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><span style="color: darkblue;">Configuration</span> <span style="color: blueviolet;">Copy_PowerShell_Scripts</span> {<br />
Node <span style="color: orangered;">$AllNodes</span><span style="color: darkgrey;">.</span>NodeName<br />
{<br />
file <span style="color: darkred;">"PowerShell_PROFILE_script"</span><br />
{<br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
type <span style="color: darkgrey;">=</span> <span style="color: darkred;">"File"</span><br />
SourcePath <span style="color: darkgrey;">=</span> <span style="color: darkred;">"\\PSDSCPULLSERVER\DSC Configurations\PowerShellScripts\profile.ps1"</span><br />
MatchSource <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$True"</span><br />
DestinationPath <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$PROFILE"</span><br />
}<br />
file <span style="color: darkred;">"Copy_\\PSDSCPULLSERVER\DSC_Configurations\PowerShellScripts__TO__$env:USERPROFILE\Desktop\PowerShell"</span><br />
{<br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
type <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Directory"</span><br />
SourcePath <span style="color: darkgrey;">=</span> <span style="color: darkred;">"\\PSDSCPULLSERVER\DSC Configurations\PowerShellScripts"</span><br />
MatchSource <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$True"</span><br />
Recurse <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$True"</span><br />
DestinationPath <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$env:USERPROFILE\Desktop\PowerShell"</span><br />
}<br />
}<br />
} </div></td> </tr>
</tbody> </table></div><h1>Defining Configuration 2 of 3</h1>In the Configuration below I set the following services to automatically start a boot [wuauserv, WinRm, EventLog, and VSS] Not only will those services bet set to start at boot -- they will also be check at the interval you configure in you LCM<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;"><table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015<br />
016<br />
017<br />
018<br />
019<br />
020<br />
021<br />
022<br />
023<br />
024<br />
025<br />
026<br />
027<br />
028<br />
029<br />
030<br />
031<br />
032<br />
033<br />
034<br />
035<br />
036<br />
037<br />
038<br />
039<br />
040<br />
041<br />
042<br />
043<br />
044<br />
045<br />
046<br />
047<br />
048<br />
049<br />
050<br />
051<br />
052<br />
053<br />
054<br />
055<br />
056<br />
057<br />
058<br />
059<br />
060<br />
061<br />
062<br />
063<br />
064<br />
065<br />
066<br />
067<br />
068<br />
069<br />
070<br />
071<br />
072<br />
073<br />
074<br />
075<br />
076<br />
077<br />
078<br />
079<br />
080<br />
081<br />
082<br />
083</div></td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><span style="color: darkblue;">Configuration</span> <span style="color: blueviolet;">Configure_Services</span> {<br />
Node <span style="color: orangered;">$AllNodes</span><span style="color: darkgrey;">.</span>NodeName<br />
{<br />
Service <span style="color: blueviolet;">wuauserv</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"wuauserv"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
Service <span style="color: blueviolet;">WinRM</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"WinRM"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
Service <span style="color: blueviolet;">EventLog</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"EventLog"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
Service <span style="color: blueviolet;">winmgmt</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"winmgmt"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
Service <span style="color: blueviolet;">VSS</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"VSS"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
<span style="color: darkblue;">switch</span> (<span style="color: orangered;">$Node</span><span style="color: darkgrey;">.</span>Service)<br />
{<br />
<span style="color: darkred;">"BITS"</span><br />
{<br />
Service <span style="color: blueviolet;">BITS</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"BITS"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
}<br />
<span style="color: darkred;">"IISADMIN"</span><br />
{<br />
Service <span style="color: blueviolet;">IISADMIN</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"IISADMIN"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
}<br />
<span style="color: darkred;">"vmms"</span><br />
{<br />
Service <span style="color: blueviolet;">vmms</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"vmms"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
}<br />
<span style="color: darkred;">"msexchange"</span><br />
{<br />
Service <span style="color: blueviolet;">msexchange</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"msexchange"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
}<br />
<span style="color: darkred;">"cryptsvc"</span><br />
{<br />
Service <span style="color: blueviolet;">crypysvc</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"cryptsvc"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
}<br />
}<br />
}<br />
} </div></td> </tr>
</tbody> </table></div><h1>Defining Configuration 3 of 3</h1><br />
In this Configuration called "Add_Features" I start off by ensuring the following features (FilSharing, PowerShell and PowerShell_ISE) are installed on all servers specified under $AllNodes.NodeName which will is all servers listed in my $ConfigurationData array. However for the rest of the WindowsFeatures will not be installed unless they are called out within $ConfigurationData as shown with my Domain Controller MKDC-02 below.<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;"><table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">001</div></td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"MKDC-02"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"AD-Domain-Services"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"DHCP"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"DNS"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span>}<span style="color: darkgrey;">,</span> </div></td> </tr>
</tbody> </table></div><br />
So MKDC-02 will be configured with the following features (FS-FileServer, PowerShell, PowerShell-ISE <b>AND</b> AD-Domain-Services, DHCP, DNS,Server-Gui-Shell, and Server-Gui-Mgmt-Infra)<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;"><table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015<br />
016<br />
017<br />
018<br />
019<br />
020<br />
021<br />
022<br />
023<br />
024<br />
025<br />
026<br />
027<br />
028<br />
029<br />
030<br />
031<br />
032<br />
033<br />
034<br />
035<br />
036<br />
037<br />
038<br />
039<br />
040<br />
041<br />
042<br />
043<br />
044<br />
045<br />
046<br />
047<br />
048<br />
049<br />
050<br />
051<br />
052<br />
053<br />
054<br />
055<br />
056<br />
057<br />
058<br />
059<br />
060<br />
061<br />
062<br />
063<br />
064<br />
065<br />
066<br />
067<br />
068<br />
069<br />
070<br />
071<br />
072<br />
073<br />
074<br />
075<br />
076<br />
077<br />
078<br />
079<br />
080<br />
081<br />
082<br />
083<br />
084<br />
085<br />
086<br />
087<br />
088<br />
089</div></td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><span style="color: darkblue;">Configuration</span> <span style="color: blueviolet;">Add_Features</span> {<br />
Node <span style="color: orangered;">$AllNodes</span><span style="color: darkgrey;">.</span>NodeName<br />
{<br />
WindowsFeature <span style="color: blue;">FS-FileServer</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"FS-FileServer"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
WindowsFeature <span style="color: blueviolet;">PowerShell</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"PowerShell"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
WindowsFeature <span style="color: blue;">PowerShell-ISE</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"PowerShell-ISE"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
<span style="color: darkgreen;">#Source = "wim:d:\sources\install.wim:2"</span><br />
}<br />
<span style="color: darkblue;">switch</span> (<span style="color: orangered;">$Node</span><span style="color: darkgrey;">.</span>Role)<br />
{<br />
<span style="color: darkred;">"SNMP"</span><br />
{<br />
WindowsFeature <span style="color: blueviolet;">snmp</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"SNMP-Service"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
<span style="color: darkred;">"Web-Server"</span><br />
{<br />
WindowsFeature <span style="color: blue;">Web-Server</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Web-Server"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
<span style="color: darkred;">"DHCP"</span><br />
{<br />
WindowsFeature <span style="color: blueviolet;">DHCP</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"DHCP"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
<span style="color: darkred;">"DNS"</span><br />
{<br />
WindowsFeature <span style="color: blueviolet;">DNS</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"DNS"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
<span style="color: darkred;">"Server-Gui-Shell"</span><br />
{<br />
WindowsFeature <span style="color: blue;">Server-Gui-Shell</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Server-Gui-Shell"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
<span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span><br />
{<br />
WindowsFeature <span style="color: blue;">Server-Gui-Mgmt-Infra</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
<span style="color: darkgreen;">#Source = "wim:d\sources\install.wim:2"</span><br />
}<br />
}<br />
<span style="color: darkred;">"AD-Domain-Services"</span><br />
{<br />
WindowsFeature <span style="color: blue;">AD-Domain-Services</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"AD-Domain-Services"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
<span style="color: darkred;">"DSC-Service"</span><br />
{<br />
WindowsFeature <span style="color: blue;">DSC-Service</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"DSC-Service"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
}<br />
}<br />
} </div></td> </tr>
</tbody> </table></div><h1>Creating the .MOFs</h1><br />
The next step in my script was to move to the folder that IIS is hosting as this is where the .MOFs need to be created.<br />
<br />
<pre class="PoshConsole">Set-Location "C:\Program Files\WindowsPowerShell\DscService"</pre><br />
NOTE: instead of moving to the directory you can specify the -OutputPath Parameter.<br />
<br />
<br />
The following creates the .MOF file for the Local Configuration Manager<br />
<pre class="PoshConsole">DSC_LCM -ConfigurationData $ConfigurationData -OutputPath .\DSC_LCM</pre><br />
The below Creates the .MOF file for the corresponding "Configuration"<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;"> <table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"> <div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"> 001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
</div></td> <td nowrap="NOWRAP" valign="Top"> <div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><span style="color: darkgreen;">## Creates the .MOF file for the Local Configuration Manager</span><br />
<span style="color: blue;"> DSC_LCM</span> <span style="color: navy;">-ConfigurationData</span> <span style="color: orangered;">$ConfigurationData</span> <span style="color: navy;">-OutputPath</span> <span style="color: blueviolet;">.\DSC_LCM</span><br />
<br />
<span style="color: darkgreen;">## Creates the .MOF file for the corresonding "Configuration"</span><br />
<span style="color: blue;">Add_Features</span> <span style="color: navy;">-OutputPath</span> <span style="color: blueviolet;">.\Add_Features</span> <span style="color: navy;">-ConfigurationData</span> <span style="color: orangered;">$ConfigurationData</span><br />
<span style="color: blue;">Configure_Services</span> <span style="color: navy;">-OutputPath</span> <span style="color: blueviolet;">.\Configure_Services</span> <span style="color: navy;">-ConfigurationData</span> <span style="color: orangered;">$ConfigurationData</span><br />
<span style="color: blue;">Copy_PowerShell_Scripts</span> <span style="color: navy;">-OutputPath</span> <span style="color: blueviolet;">.\Copy_PowerShell_Scripts</span> <span style="color: navy;">-ConfigurationData</span> <span style="color: orangered;">$ConfigurationData</span><br />
</div></td> </tr>
</tbody> </table></div><div class="separator" style="clear: both; text-align: center;"></div><br />
<h1>"Make it so"</h1><div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;"><table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">001<br />
002<br />
003<br />
004<br />
005</div></td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><span style="color: blue;">Set-DscLocalConfigurationManager</span> <span style="color: navy;">-Path</span> <span style="color: blueviolet;">.\DSC_LCM</span> <span style="color: navy;">-ComputerName</span> <span style="color: orangered;">$AllNodes</span> <span style="color: navy;">-ErrorAction</span> <span style="color: blueviolet;">SilentlyContinue</span><br />
<span style="color: darkgreen;">## runs the desired .MOF configuration file</span><br />
<span style="color: blue;">Start-DscConfiguration</span> <span style="color: navy;">-Path</span> <span style="color: blueviolet;">.\Copy_PowerShell_Scripts</span> <span style="color: navy;">-ComputerName</span> <span style="color: orangered;">$AllNodes</span> <span style="color: navy;">-ErrorAction</span> <span style="color: blueviolet;">SilentlyContinue</span><br />
<span style="color: blue;">Start-DscConfiguration</span> <span style="color: navy;">-Path</span> <span style="color: blueviolet;">.\Add_Features</span> <span style="color: navy;">-ComputerName</span> <span style="color: orangered;">$AllNode</span> <span style="color: navy;">-ErrorAction</span> <span style="color: blueviolet;">SilentlyContinue</span><br />
<span style="color: blue;">Start-DscConfiguration</span> <span style="color: navy;">-Path</span> <span style="color: blueviolet;">.\Configure_Services</span> <span style="color: navy;">-ComputerName</span> <span style="color: orangered;">$AllNodes</span> <span style="color: navy;">-ErrorAction</span> <span style="color: blueviolet;">SilentlyContinue</span> </div></td> </tr>
</tbody> </table></div><br />
<div class="separator" style="clear: both; text-align: center;"></div><br />
<br />
My thoughts on DSC -- Setup can be a little time consuming <b>but </b>now I can boot up any number of servers and have them configure with any number of roles or features installed with very little modification.<br />
<br />
<div style="text-align: center;">Good-Bye Configuration Drift -- Good-Bye failed backups</div><br />
What it looks like when it's running:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaoUNhcZJn-Dgex65EwcwLY2135sbu4JMyOAZlq5DoerYi6hxrAApDxEvK8IIhawP3YLAZCJLzbc62Co_YkKpPsyoDAIkaI2XZouk4au6y7RC33fnxa6utOfyySTki4MrNHQvnGJRT-5o/s1600/dsc6.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaoUNhcZJn-Dgex65EwcwLY2135sbu4JMyOAZlq5DoerYi6hxrAApDxEvK8IIhawP3YLAZCJLzbc62Co_YkKpPsyoDAIkaI2XZouk4au6y7RC33fnxa6utOfyySTki4MrNHQvnGJRT-5o/s1600/dsc6.JPG" height="302" width="640" /></a></div><br />
<br />
Here's my full Pull Server Configuration Script<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;"><table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015<br />
016<br />
017<br />
018<br />
019<br />
020<br />
021<br />
022<br />
023<br />
024<br />
025<br />
026<br />
027<br />
028<br />
029<br />
030<br />
031<br />
032<br />
033<br />
034<br />
035<br />
036<br />
037<br />
038<br />
039<br />
040<br />
041<br />
042<br />
043<br />
044<br />
045<br />
046<br />
047<br />
048<br />
049<br />
050<br />
051<br />
052<br />
053<br />
054<br />
055<br />
056<br />
057<br />
058<br />
059<br />
060<br />
061<br />
062<br />
063<br />
064<br />
065<br />
066<br />
067<br />
068<br />
069<br />
070<br />
071<br />
072<br />
073<br />
074<br />
075<br />
076<br />
077<br />
078<br />
079<br />
080<br />
081<br />
082<br />
083<br />
084<br />
085<br />
086<br />
087<br />
088<br />
089<br />
090<br />
091<br />
092<br />
093<br />
094<br />
095<br />
096<br />
097<br />
098<br />
099<br />
100<br />
101<br />
102<br />
103<br />
104<br />
105<br />
106<br />
107<br />
108<br />
109<br />
110<br />
111<br />
112<br />
113<br />
114<br />
115<br />
116<br />
117<br />
118<br />
119<br />
120<br />
121<br />
122<br />
123<br />
124<br />
125<br />
126<br />
127<br />
128<br />
129<br />
130<br />
131<br />
132<br />
133<br />
134<br />
135<br />
136<br />
137<br />
138<br />
139<br />
140<br />
141<br />
142<br />
143<br />
144<br />
145<br />
146<br />
147<br />
148<br />
149<br />
150<br />
151<br />
152<br />
153<br />
154<br />
155<br />
156<br />
157<br />
158<br />
159<br />
160<br />
161<br />
162<br />
163<br />
164<br />
165<br />
166<br />
167<br />
168<br />
169<br />
170<br />
171<br />
172<br />
173<br />
174<br />
175<br />
176<br />
177<br />
178<br />
179<br />
180<br />
181<br />
182<br />
183<br />
184<br />
185<br />
186<br />
187<br />
188<br />
189<br />
190<br />
191<br />
192<br />
193<br />
194<br />
195<br />
196<br />
197<br />
198<br />
199<br />
200<br />
201<br />
202<br />
203<br />
204<br />
205<br />
206<br />
207<br />
208<br />
209<br />
210<br />
211<br />
212<br />
213<br />
214<br />
215<br />
216<br />
217<br />
218<br />
219<br />
220<br />
221<br />
222<br />
223<br />
224<br />
225<br />
226<br />
227<br />
228<br />
229<br />
230<br />
231<br />
232<br />
233<br />
234<br />
235<br />
236<br />
237<br />
238<br />
239<br />
240<br />
241<br />
242<br />
243<br />
244<br />
245<br />
246<br />
247<br />
248<br />
249<br />
250<br />
251<br />
252<br />
253<br />
254<br />
255<br />
256<br />
257<br />
258<br />
259<br />
260<br />
261<br />
262<br />
263<br />
264<br />
265<br />
266<br />
267<br />
268<br />
269<br />
270<br />
271<br />
272<br />
273<br />
274<br />
275<br />
276<br />
277<br />
278<br />
279<br />
280<br />
281<br />
282<br />
283<br />
284<br />
285<br />
286<br />
287<br />
288<br />
289<br />
290<br />
291<br />
292<br />
293<br />
294<br />
295<br />
296<br />
297<br />
298<br />
299<br />
300<br />
301<br />
302<br />
303<br />
304<br />
305<br />
306<br />
307<br />
308<br />
309<br />
310</div></td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"><span style="color: darkgreen;"><#<br />
.CREATED BY:<br />
Matthew A. Kerfoot<br />
.CREATED ON:<br />
07\14\2014<br />
.UPDATED ON:<br />
07/22/2014<br />
.SYNOPSIS <br />
Automating the world one line of code at a time.<br />
.DESCRIPTION<br />
This is a PowerShell Desired State Push Configuration.<br />
.EXAMPLE<br />
Run the script as an administrator PS:\>G\DSC\DSC.ps1<br />
.NOTES<br />
This is a PowerShell Desired State Push Configuration.<br />
.NOTES <br />
<br />
Version : 4.0<br />
<br />
Author/Copyright : © Matthew Kerfoot - All Rights Reserved<br />
<br />
Email/Blog/Twitter : mkkerfoot@gmail.com www.matthewkerfoot.com @mkkerfoot<br />
<br />
Disclaimer : THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK<br />
OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.<br />
While these scripts are tested and working in my environment, it is recommended <br />
that you test these scripts in a test environment before using in your production <br />
environment<br />
Matthew Kerfoot further disclaims all implied warranties including, without limitation, any <br />
implied warranties of merchantability or of fitness for a particular purpose. The entire risk <br />
arising out of the use or performance of this script and documentation remains with you. <br />
In no event shall Matthew Kerfoot, its authors, or anyone else involved in the creation, production, <br />
or delivery of this script/tool be liable for any damages whatsoever (including, without limitation, <br />
damages for loss of business profits, business interruption, loss of business information, or other <br />
pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, <br />
even if Matthew Kerfoot has been advised of the possibility of such damages<br />
<br />
<br />
Assumptions : ExecutionPolicy of AllSigned (recommended), RemoteSigned or Unrestricted (not recommended)<br />
<br />
Limitations : This is a Push Configuration which is limited compared to a pull configuration.<br />
<br />
Ideas/Wish list : backupexec ; Veeam <br />
<br />
Known issues : Some Paths have been hardcoded<br />
<br />
Authors notes : This is my first attempt at DSC<br />
##></span><br />
<span style="color: darkgreen;">###################################################################################################</span><br />
<span style="color: darkgreen;">## # # # # # Variables that need to be edited # # # # # # ##</span><br />
<span style="color: darkgreen;">###################################################################################################</span><br />
<span style="color: orangered;">$ConfigurationData</span> <span style="color: darkgrey;">=</span> @{<br />
AllNodes <span style="color: darkgrey;">=</span> @(<br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"MKDC-02"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"DHCP"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"DNS"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"SERVER2012R2-01"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span>;Service<span style="color: darkgrey;">=</span><span style="color: darkred;">"BITS"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"vmms"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"SERVER2012R2-02"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span>;Service<span style="color: darkgrey;">=</span><span style="color: darkred;">"BITS"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"vmms"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"SERVER2012R2-03"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span>;Service<span style="color: darkgrey;">=</span><span style="color: darkred;">"BITS"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"vmms"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"PSDSCPULLSERVER"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"DSC-Service"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span>;Service<span style="color: darkgrey;">=</span><span style="color: darkred;">"BITS"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"vmms"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"MKDFS-01"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"Web"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"MKDFS-02"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"FileShare"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"RODC"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"Web"</span>}<span style="color: darkgrey;">,</span><br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"MKPSWA"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"FileShare"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"WindowsPowerShellWebAccess"</span>}<br />
@{NodeName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"PSWAW12"</span>;Role<span style="color: darkgrey;">=</span><span style="color: darkred;">"FileShare"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Shell"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span><span style="color: darkgrey;">,</span><span style="color: darkred;">"WindowsPowerShellWebAccess"</span>}<br />
)<br />
}<br />
<br />
<span style="color: orangered;">$StartTime</span> <span style="color: darkgrey;">=</span> (<span style="color: blue;">Get-Date</span>) <span style="color: darkgreen;">## Begin the timer</span><br />
<br />
<span style="color: blue;">Clear-Host</span> <span style="color: darkgreen;">## Clears the screen</span><br />
<br />
<span style="color: darkgreen;">## Creates Logfile of all messages, verbose and host</span><br />
<span style="color: blue;">Start-Transcript</span> <span style="color: navy;">-Path</span> <span style="color: darkred;">"C:\Windows\Temp\DSC_$( get-date -f MM-dd-hh-mm ).log"</span><br />
<br />
<span style="color: darkgreen;">## moves to the newly created directory</span><br />
<span style="color: blue;">Set-Location</span> <span style="color: darkred;">"C:\Program Files\WindowsPowerShell\DscService"</span><br />
<br />
<span style="color: darkgreen;">## Local Configuration Manager -- Sets all DSC intervals and settings</span><br />
<span style="color: darkblue;">Configuration</span> <span style="color: blueviolet;">DSC_LCM</span> {<br />
Node <span style="color: orangered;">$AllNodes</span><span style="color: darkgrey;">.</span>NodeName<br />
{<br />
LocalConfigurationManager<br />
{ <br />
AllowModuleOverwrite <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$True"</span><br />
ConfigurationID <span style="color: darkgrey;">=</span> <span style="color: darkred;">"a9c09333-54f7-4a25-8a58-ebee9647e313"</span>; <br />
DownloadManagerName <span style="color: darkgrey;">=</span> <span style="color: darkred;">"WebDownloadManager"</span><br />
DownloadManagerCustomData <span style="color: darkgrey;">=</span> @{ ServerUrl<span style="color: darkgrey;">=</span><span style="color: darkred;">"http://PSDSCPULLSERVER.kerfoot.com:8080/PSDSCPullServer.svc"</span> ; AllowUnsecureConnection<span style="color: darkgrey;">=</span> <span style="color: darkred;">"True"</span> }<br />
RefreshMode <span style="color: darkgrey;">=</span> <span style="color: darkred;">"PULL"</span><br />
ConfigurationMode <span style="color: darkgrey;">=</span> <span style="color: darkred;">"ApplyAndAutoCorrect"</span><br />
RebootNodeIfNeeded <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$True"</span><br />
RefreshFrequencyMins <span style="color: darkgrey;">=</span> <span style="color: darkred;">"15"</span><br />
ConfigurationModeFrequencyMins <span style="color: darkgrey;">=</span> <span style="color: darkred;">"30"</span><br />
}<br />
}<br />
}<br />
<span style="color: darkgreen;">## grabs the profile.ps1 file from $D_DSC and adds it to the logged in users PS $PROFILE</span><br />
<span style="color: darkblue;">Configuration</span> <span style="color: blueviolet;">Copy_PowerShell_Scripts</span> {<br />
Node <span style="color: orangered;">$AllNodes</span><span style="color: darkgrey;">.</span>NodeName<br />
{<br />
file <span style="color: darkred;">"PowerShell_PROFILE_script"</span><br />
{<br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
type <span style="color: darkgrey;">=</span> <span style="color: darkred;">"File"</span><br />
SourcePath <span style="color: darkgrey;">=</span> <span style="color: darkred;">"\\PSDSCPULLSERVER\DSC Configurations\PowerShellScripts\profile.ps1"</span><br />
MatchSource <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$True"</span><br />
DestinationPath <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$PROFILE"</span><br />
}<br />
file <span style="color: darkred;">"Copy_\\PSDSCPULLSERVER\DSC_Configurations\PowerShellScripts__TO__$env:USERPROFILE\Desktop\PowerShell"</span><br />
{<br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
type <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Directory"</span><br />
SourcePath <span style="color: darkgrey;">=</span> <span style="color: darkred;">"\\PSDSCPULLSERVER\DSC Configurations\PowerShellScripts"</span><br />
MatchSource <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$True"</span><br />
Recurse <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$True"</span><br />
DestinationPath <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$env:USERPROFILE\Desktop\PowerShell"</span><br />
}<br />
}<br />
}<br />
<span style="color: darkblue;">Configuration</span> <span style="color: blueviolet;">Configure_Services</span> {<br />
Node <span style="color: orangered;">$AllNodes</span><span style="color: darkgrey;">.</span>NodeName<br />
{ <br />
Service <span style="color: blueviolet;">wuauserv</span> <br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"wuauserv"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
} <br />
Service <span style="color: blueviolet;">WinRM</span> <br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"WinRM"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
Service <span style="color: blueviolet;">EventLog</span> <br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"EventLog"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
} <br />
Service <span style="color: blueviolet;">winmgmt</span> <br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"winmgmt"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
} <br />
Service <span style="color: blueviolet;">VSS</span> <br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"VSS"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
<span style="color: darkblue;">switch</span> (<span style="color: orangered;">$Node</span><span style="color: darkgrey;">.</span>Service)<br />
{<br />
<span style="color: darkred;">"BITS"</span><br />
{<br />
Service <span style="color: blueviolet;">BITS</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"BITS"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
}<br />
<span style="color: darkred;">"IISADMIN"</span><br />
{<br />
Service <span style="color: blueviolet;">IISADMIN</span> <br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"IISADMIN"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
}<br />
<span style="color: darkred;">"vmms"</span><br />
{<br />
Service <span style="color: blueviolet;">vmms</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"vmms"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
}<br />
<span style="color: darkred;">"msexchange"</span><br />
{<br />
Service <span style="color: blueviolet;">msexchange</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"msexchange"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
}<br />
<span style="color: darkred;">"cryptsvc"</span><br />
{<br />
Service <span style="color: blueviolet;">crypysvc</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"cryptsvc"</span><br />
State <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Running"</span><br />
StartupType <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Automatic"</span><br />
}<br />
}<br />
}<br />
}<br />
}<br />
<span style="color: darkblue;">Configuration</span> <span style="color: blueviolet;">Add_Features</span> {<br />
Node <span style="color: orangered;">$AllNodes</span><span style="color: darkgrey;">.</span>NodeName<br />
{<br />
WindowsFeature <span style="color: blueviolet;">FileSharing</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"FS-FileServer"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
WindowsFeature <span style="color: blueviolet;">PowerShell</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"PowerShell"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
WindowsFeature <span style="color: blue;">PowerShell-ISE</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"PowerShell-ISE"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
<span style="color: darkgreen;">#Source = "wim:d:\sources\install.wim:2"</span><br />
}<br />
<span style="color: darkblue;">switch</span> (<span style="color: orangered;">$Node</span><span style="color: darkgrey;">.</span>Role)<br />
{<br />
<span style="color: darkred;">"SNMP"</span><br />
{<br />
WindowsFeature <span style="color: blueviolet;">snmp</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"SNMP-Service"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
<span style="color: darkred;">"Web-Server"</span><br />
{<br />
WindowsFeature <span style="color: blue;">Web-Server</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Web-Server"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
<span style="color: darkred;">"DHCP"</span><br />
{<br />
WindowsFeature <span style="color: blueviolet;">DHCP</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"DHCP"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
<span style="color: darkred;">"DNS"</span><br />
{<br />
WindowsFeature <span style="color: blueviolet;">DNS</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"DNS"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
<span style="color: darkred;">"Server-Gui-Shell"</span><br />
{<br />
WindowsFeature <span style="color: blue;">Server-Gui-Shell</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Server-Gui-Shell"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
<span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span><br />
{<br />
WindowsFeature <span style="color: blue;">Server-Gui-Mgmt-Infra</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Server-Gui-Mgmt-Infra"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
<span style="color: darkgreen;">#Source = "wim:d\sources\install.wim:2"</span><br />
}<br />
}<br />
<span style="color: darkred;">"AD-Domain-Services"</span><br />
{<br />
WindowsFeature <span style="color: blue;">AD-Domain-Services</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"AD-Domain-Services"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
<span style="color: darkred;">"DSC-Service"</span><br />
{<br />
WindowsFeature <span style="color: blue;">DSC-Service</span><br />
{<br />
Name <span style="color: darkgrey;">=</span> <span style="color: darkred;">"DSC-Service"</span><br />
Ensure <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Present"</span><br />
}<br />
}<br />
}<br />
}<br />
}<br />
<br />
<span style="color: darkgreen;">## Creates the .MOF file for the Local Configuration Manager</span><br />
<span style="color: blue;">DSC_LCM</span> <span style="color: navy;">-ConfigurationData</span> <span style="color: orangered;">$ConfigurationData</span> <span style="color: navy;">-OutputPath</span> <span style="color: blueviolet;">.\DSC_LCM</span><br />
<br />
<span style="color: darkgreen;">## Creates the .MOF file for the corresonding "Configuration"</span><br />
<span style="color: blue;">Add_Features</span> <span style="color: navy;">-OutputPath</span> <span style="color: blueviolet;">.\Add_Features</span> <span style="color: navy;">-ConfigurationData</span> <span style="color: orangered;">$ConfigurationData</span><br />
<span style="color: blue;">Configure_Services</span> <span style="color: navy;">-OutputPath</span> <span style="color: blueviolet;">.\Configure_Services</span> <span style="color: navy;">-ConfigurationData</span> <span style="color: orangered;">$ConfigurationData</span><br />
<span style="color: blue;">Copy_PowerShell_Scripts</span> <span style="color: navy;">-OutputPath</span> <span style="color: blueviolet;">.\Copy_PowerShell_Scripts</span> <span style="color: navy;">-ConfigurationData</span> <span style="color: orangered;">$ConfigurationData</span><br />
<br />
<span style="color: darkgreen;">## runs the desired .MOF configuration file</span><br />
<span style="color: blue;">Set-DscLocalConfigurationManager</span> <span style="color: navy;">-Path</span> <span style="color: blueviolet;">.\DSC_LCM</span> <span style="color: navy;">-ComputerName</span> <span style="color: orangered;">$AllNodes</span> <span style="color: navy;">-ErrorAction</span> <span style="color: blueviolet;">SilentlyContinue</span><br />
<span style="color: blue;">Start-DscConfiguration</span> <span style="color: navy;">-Path</span> <span style="color: blueviolet;">.\Copy_PowerShell_Scripts</span> <span style="color: navy;">-ComputerName</span> <span style="color: orangered;">$AllNodes</span> <span style="color: navy;">-ErrorAction</span> <span style="color: blueviolet;">SilentlyContinue</span><br />
<span style="color: blue;">Start-DscConfiguration</span> <span style="color: navy;">-Path</span> <span style="color: blueviolet;">.\Add_Features</span> <span style="color: navy;">-ComputerName</span> <span style="color: orangered;">$AllNode</span> <span style="color: navy;">-ErrorAction</span> <span style="color: blueviolet;">SilentlyContinue</span><br />
<span style="color: blue;">Start-DscConfiguration</span> <span style="color: navy;">-Path</span> <span style="color: blueviolet;">.\Configure_Services</span> <span style="color: navy;">-ComputerName</span> <span style="color: orangered;">$AllNodes</span> <span style="color: navy;">-ErrorAction</span> <span style="color: blueviolet;">SilentlyContinue</span><br />
<br />
<span style="color: orangered;">$EndTime</span> <span style="color: darkgrey;">=</span> (<span style="color: blue;">Get-Date</span>) <span style="color: darkgreen;">## Stops the timer</span><br />
<br />
<span style="color: darkred;">"Elapsed Time: $(($EndTime - $StartTime).totalseconds) seconds"</span> <span style="color: darkgreen;">## Calculate amount of seconds your code takes to complete.</span><br />
<span style="color: blue;">Set-Location</span> <span style="color: darkred;">"B:\DSC\"</span><br />
<br />
<span style="color: blue;">Stop-Transcript</span> <span style="color: navy;">-Verbose</span> </div></td> </tr>
</tbody> </table></div>BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0Minneapolis, MN 55427, USA45.0155422 -93.37679759999997544.925730699999995 -93.538159099999973 45.1053537 -93.215436099999977tag:blogger.com,1999:blog-6417475995992020348.post-68367847551929788432014-09-24T07:46:00.000-05:002014-09-24T07:46:44.770-05:00Set users HomeDirectory attribute in Active Directory with PowerShellLast night I received a request to move a share that holds all users <span style="background-color: #fcfcfc; color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">-HomeDirectory</span>'s' from an old file server to a newly configured Server 2012 R2 machine and to reconfigure every ones <span style="background-color: #fcfcfc; color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">-HomeDirectory</span>'s' to point to the new share.<br />
<br />
Sweet, this should be pretty fun, first I started by creating the new folder at C:\Shared\UserProfiles on the Server 2012 R2 box. For this I used the <span style="background-color: #fcfcfc; color: blue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">New-Item</span> cmdlet as shown below.<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td valign="Top"><div style="background: rgb(206, 206, 206); font-size: 10pt; padding: 5px;">
001</div>
</td>
<td nowrap="NOWRAP" valign="Top"><div style="background: rgb(252, 252, 252); font-size: 10pt; padding: 5px;">
<span style="color: blue;">New-Item</span> <span style="color: navy;">-ItemType</span> <span style="color: blueviolet;">Directory</span> <span style="color: navy;">-Path</span> <span style="color: blueviolet;">C:\Shared\UserProfiles</span> <span style="color: navy;">-Verbose</span></div>
</td></tr>
</tbody></table>
</div>
<br />
After Creating the new directory its ready to be shared, I have to say I really utilize PowerShell_ISE.exe and tab completion every time I create a new SMB or Server Message Block share with PSv3.0+<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggAX68MwpDVHqJvja3LPXM50g0WaQ6aWY2SM-S8ka8Fc_KGP4S3_r18U1cBQZ0-LzGhaC_VLey0aaAxV5KQrUNMrfBDHXGbLXPU1L1yu25jvhaqTzHONn0x_egmrCNlHAd64Q4mD5av4I/s1600/smmmb.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggAX68MwpDVHqJvja3LPXM50g0WaQ6aWY2SM-S8ka8Fc_KGP4S3_r18U1cBQZ0-LzGhaC_VLey0aaAxV5KQrUNMrfBDHXGbLXPU1L1yu25jvhaqTzHONn0x_egmrCNlHAd64Q4mD5av4I/s1600/smmmb.png" height="125" width="200" /></a><br />
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td valign="Top"><div style="background: rgb(206, 206, 206); font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007</div>
</td>
<td nowrap="NOWRAP" valign="Top"><div style="background: rgb(252, 252, 252); font-size: 10pt; padding: 5px;">
<span style="color: blue;">New-SmbShare</span> <span style="color: navy;">–Name</span> <span style="color: blueviolet;">UserProfiles</span> `<br />
<span style="color: navy;">–Path</span> <span style="color: blueviolet;">C:\Shared\UserProfiles</span> `<br />
<span style="color: navy;">–Description</span> <span style="color: darkred;">‘User Profiles’</span> `<br />
<span style="color: navy;">–FullAccess</span> <span style="color: blueviolet;">Administrator</span> `<br />
<span style="color: navy;">–ReadAccess</span> <span style="color: blueviolet;">Everyone</span> `<br />
<span style="color: navy;">-EncryptData</span> <span style="color: orangered;">$true</span> `<br />
<span style="color: navy;">-verbose</span></div>
</td></tr>
</tbody></table>
</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Here is some output: <i><span style="font-size: x-small;">( Note: the paths are not all aligned as I'm recreating the output from home.)</span></i></div>
<div style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSChU4diwLv7JcAFKZtmW7MSKbAWUa99Y7So__BkDdpWTpUY-c1T3HC3eN3YpOe3ijlSdSHepQU7WmkkV76uP3O2vP-odf8MVW1O887H5hgytf3SP7F4HiMMXB3y1lj46PQ2ENBuduXps/s1600/create_the_Share.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSChU4diwLv7JcAFKZtmW7MSKbAWUa99Y7So__BkDdpWTpUY-c1T3HC3eN3YpOe3ijlSdSHepQU7WmkkV76uP3O2vP-odf8MVW1O887H5hgytf3SP7F4HiMMXB3y1lj46PQ2ENBuduXps/s1600/create_the_Share.png" height="219" width="640" /></a></div>
<br />
<br />
Next was to copy all of the data from the old server at location A to the new server at location B. For this I used robocopy by opening an administrative CMD prompt and running the below commands :<br />
<br />
<h4 style="text-align: center;">
robocopy \\oldserver\shared \\newserver\shared</h4>
<div>
<br /></div>
8 hours later I left work and the robocopy was still only about a 1/4th of the way through copying the data to the new share(100+ GBs). . Seeing how the data transfer didn't complete during my shift I ended up asking someone to keep an eye on it as the data transfers and then gave them the below script to run. I turned this script into a function weather that was a good idea or not... but I prefer functions so I went with one. :) This function will go through all Active Directory users with <span style="background-color: #fcfcfc; color: blue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">Get-ADUser</span> and filter them for only the accounts that have a <span style="background-color: #fcfcfc; color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">P:</span> drive set for their HomeDrive ( <span style="background-color: #fcfcfc; color: blue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">where</span><span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;"> {</span><span style="background-color: #fcfcfc; color: orangered; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">$_</span><span style="background-color: #fcfcfc; color: darkgrey; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">.</span><span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">HomeDrive </span><span style="background-color: #fcfcfc; color: darkgrey; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">-eq</span><span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;"> </span><span style="background-color: #fcfcfc; color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">"P:"</span><span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">}</span>). From there I used a <span style="background-color: #fcfcfc; color: darkblue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">foreach</span> statement to set each user account and then ended it off with a <span style="background-color: #fcfcfc; color: blue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">Get-ADUser</span> to display a formatted output to the screen.<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td valign="Top"><div style="background: rgb(206, 206, 206); font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015<br />
016<br />
017<br />
018<br />
019<br />
020<br />
021<br />
022<br />
023<br />
024<br />
025<br />
026<br />
027<br />
028<br />
029<br />
030<br />
031<br />
032<br />
033<br />
034<br />
035<br />
036<br />
037<br />
038<br />
039<br />
040<br />
041<br />
042<br />
043<br />
044<br />
045<br />
046<br />
047<br />
048<br />
049<br />
050</div>
</td>
<td nowrap="NOWRAP" valign="Top"><div style="background: rgb(252, 252, 252); font-size: 10pt; padding: 5px;">
<span style="color: darkgreen;"><#<br />
.Synopsis<br />
Finds all users with a P: drive as their home drive and resets their homedirectory to equal the New Directory.<br />
.DESCRIPTION<br />
Retrieves all users with A P: drive and then sets their Home Directory to whatever is specified.<br />
.EXAMPLE<br />
Set-HomeDirectory<br />
.NOTES<br />
**New HomeDirectory is hardcoded**<br />
.FUNCTIONALITY<br />
PowerShell v3.0+<br />
.EXAMPLE<br />
PS C:\> Set-HomeDirectory -HomeDrive P:<br />
.CREATED BY<br />
Matthew A. Kerfoot on 8/12/2014<br />
#></span><br />
<span style="color: darkgrey;">[</span><span style="color: deepskyblue;">CmdletBinding</span>()<span style="color: darkgrey;">]</span><br />
<span style="color: darkblue;">param</span>(<span style="color: darkgrey;">[</span><span style="color: deepskyblue;">Parameter</span>( Mandatory <span style="color: darkgrey;">=</span> <span style="color: orangered;">$False</span><span style="color: darkgrey;">,</span><br />
ValueFromPipelineByPropertyName <span style="color: darkgrey;">=</span> <span style="color: orangered;">$true</span> )<span style="color: darkgrey;">]</span><br />
<span style="color: orangered;">$Share</span> <span style="color: darkgrey;">=</span> <span style="color: darkred;">"\\SERVERNAME\Shared"</span><span style="color: darkgrey;">,</span><br />
<span style="color: darkgrey;">[</span><span style="color: deepskyblue;">Parameter</span>( Mandatory <span style="color: darkgrey;">=</span> <span style="color: orangered;">$False</span><span style="color: darkgrey;">,</span><br />
ValueFromPipelineByPropertyName <span style="color: darkgrey;">=</span> <span style="color: orangered;">$true</span> )<span style="color: darkgrey;">]</span><br />
<span style="color: orangered;">$HomeDrive</span> <span style="color: darkgrey;">=</span> <span style="color: darkred;">"P:"</span><span style="color: darkgrey;">,</span><br />
<span style="color: darkgrey;">[</span><span style="color: deepskyblue;">Parameter</span>( Mandatory <span style="color: darkgrey;">=</span> <span style="color: orangered;">$False</span><span style="color: darkgrey;">,</span><br />
ValueFromPipelineByPropertyName <span style="color: darkgrey;">=</span> <span style="color: orangered;">$true</span> )<span style="color: darkgrey;">]</span><br />
<span style="color: orangered;">$VerbosePreference</span> <span style="color: darkgrey;">=</span> <span style="color: darkred;">"Continue"</span><br />
)<br />
<br />
<span style="color: darkblue;">Begin</span>{ <span style="color: darkgreen;"># Find all users with a P: Drive</span><br />
<span style="color: blue;">Import-Module</span> <span style="color: blueviolet;">ActiveDirectory</span><br />
<span style="color: orangered;">$users</span> <span style="color: darkgrey;">=</span> <span style="color: blue;">Get-ADUser</span> <span style="color: navy;">-Filter</span> <span style="color: blueviolet;">*</span> <span style="color: navy;">-Properties</span> <span style="color: blueviolet;">*</span> <span style="color: darkgrey;">|</span><br />
<span style="color: blue;">where</span> {<span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>homedrive <span style="color: darkgrey;">-eq</span> <span style="color: darkred;">"P:"</span>} <span style="color: darkgrey;">|</span><br />
<span style="color: blue;">select</span> <span style="color: navy;">-ExpandProperty</span> <span style="color: blueviolet;">samaccountname</span><br />
}<br />
<br />
<span style="color: darkblue;">Process</span>{ <span style="color: darkgreen;"># changes each users home drive and homedirectory</span><br />
<span style="color: darkblue;">foreach</span> (<span style="color: orangered;">$U</span> <span style="color: darkblue;">in</span> <span style="color: orangered;">$Users</span>)<br />
{<br />
<span style="color: blue;">Set-ADUser</span> <span style="color: navy;">-Identity</span> <span style="color: orangered;">$U</span> <span style="color: navy;">-HomeDrive</span> <span style="color: orangered;">$HomeDrive</span> <span style="color: navy;">-HomeDirectory</span> <span style="color: darkred;">"$Share\$u"</span> <span style="color: navy;">-Verbose</span><br />
<br />
}<br />
}<br />
<br />
<span style="color: darkblue;">End</span> { <span style="color: darkgreen;"># gives a formated output of the changes</span><br />
<span style="color: blue;">Get-ADUser</span> <span style="color: navy;">-Filter</span> <span style="color: blueviolet;">*</span> <span style="color: navy;">-Properties</span> <span style="color: blueviolet;">*</span> <span style="color: darkgrey;">|</span><br />
<span style="color: blue;">where</span> {<span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>HomeDrive <span style="color: darkgrey;">-eq</span> <span style="color: darkred;">"$HomeDrive"</span>} <span style="color: darkgrey;">|</span><br />
<span style="color: blue;">Select-Object</span> <span style="color: blueviolet;">samaccountname</span><span style="color: darkgrey;">,</span> <span style="color: blueviolet;">homedrive</span><span style="color: darkgrey;">,</span> <span style="color: blueviolet;">homedirectory</span> `<br />
<span style="color: darkgreen;">#| Format-Table -AutoSize</span><br />
}</div>
</td>
</tr>
</tbody>
</table>
</div>
<br />
Output:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3wbxAfGTedpcJkiDxJnj15zBdkihvmJ9L97LP9avsIOGFwUPcq7ZoU_9IyzE8XPe4uXrq-G5VflOkBe_BCieesoUOUQH7waV43wmR27wtPgpgrzQibSwA4L2hJEwd_3xJtnD5cUHhxTQ/s1600/for_example.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3wbxAfGTedpcJkiDxJnj15zBdkihvmJ9L97LP9avsIOGFwUPcq7ZoU_9IyzE8XPe4uXrq-G5VflOkBe_BCieesoUOUQH7waV43wmR27wtPgpgrzQibSwA4L2hJEwd_3xJtnD5cUHhxTQ/s1600/for_example.png" height="304" width="640" /></a></div>
<br />
<div style="text-align: center;">
<i>And I just realized the time on this machine is 2 hours behind...</i></div>
<div style="text-align: center;">
<i><br /></i></div>
<div style="text-align: center;">
<i>Until next time...</i></div>
BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0Minneapolis, MN 55427, USA45.0155422 -93.37679759999997544.925730699999995 -93.538159099999973 45.1053537 -93.215436099999977tag:blogger.com,1999:blog-6417475995992020348.post-67730267459839901112014-09-11T12:37:00.000-05:002014-09-12T05:07:43.828-05:00Pop up window with PowerShellPowerShell popup with use of xaml for formatting the output. Enjoy! I know I did, I used this with a gpo login script to help remind users what to do...<br />
<div>
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015<br />
016<br />
017<br />
018<br />
019<br />
020<br />
021<br />
022<br />
023<br />
024<br />
025<br />
026<br />
027<br />
028<br />
029<br />
030<br />
031<br />
032<br />
033<br />
034<br />
035<br />
036<br />
037<br />
038<br />
039<br />
040<br />
041</div>
</td>
<td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
<span style="color: darkgreen;">## creates the runspace</span><br />
<span style="color: orangered;">$run</span> <span style="color: darkgrey;">=</span> <span style="color: teal;">[RunspaceFactory]</span><span style="color: darkgrey;">::</span>CreateRunspace()<br />
<span style="color: orangered;">$run</span><span style="color: darkgrey;">.</span>ApartmentState <span style="color: darkgrey;">=</span> <span style="color: darkred;">“STA”</span><br />
<span style="color: orangered;">$run</span><span style="color: darkgrey;">.</span>Open()<br />
<span style="color: darkgreen;">## opens PowerShell.exe</span><br />
<span style="color: orangered;">$ps</span> <span style="color: darkgrey;">=</span> {<span style="color: blue;">Add-Type</span> <span style="color: navy;">-AssemblyName</span> <span style="color: blueviolet;">PresentationCore</span>}<span style="color: darkgrey;">.</span>GetPowerShell()<br />
<span style="color: orangered;">$ps</span><span style="color: darkgrey;">.</span>Runspace <span style="color: darkgrey;">=</span> <span style="color: orangered;">$run</span><br />
<span style="color: darkgreen;">## specify xaml formatting</span><br />
<span style="color: orangered;">$ps</span><span style="color: darkgrey;">.</span>AddScript({<br />
<span style="color: teal;">[xml]</span><span style="color: orangered;">$xaml</span> <span style="color: darkgrey;">=</span> <span style="color: darkred;">@"<br />
<Window<br />
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'<br />
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'<br />
x:Name='Window' WindowStartupLocation = 'CenterScreen' Width = '1000' Height = '500' ShowInTaskbar = 'True' WindowStyle = 'None' AllowsTransparency = 'true'><br />
<Window.Background><br />
<SolidColorBrush Opacity= '0' ></SolidColorBrush><br />
</Window.Background><br />
<Grid x:Name = 'Grid' ShowGridLines='false' ><br />
<Grid.ColumnDefinitions><br />
<ColumnDefinition Width="*"/><br />
</Grid.ColumnDefinitions><br />
<Grid.RowDefinitions><br />
<RowDefinition Height = '*'/><br />
</Grid.RowDefinitions><br />
<Viewbox Stretch = 'Fill'> <br />
<Label x:Name='Content' FontWeight = 'Bold' Content = 'PowerShell Rules!' FontSize = '30' FontStyle = 'Normal' Foreground = 'Blue' /><br />
</Viewbox><br />
</Grid><br />
</Window><br />
"@</span><br />
<span style="color: darkgreen;">## read xaml code</span><br />
<span style="color: orangered;">$reader</span><span style="color: darkgrey;">=</span>(<span style="color: blue;">New-Object</span> <span style="color: blueviolet;">System.Xml.XmlNodeReader</span> <span style="color: orangered;">$xaml</span>)<br />
<span style="color: orangered;">$Global:popup</span><span style="color: darkgrey;">=</span><span style="color: teal;">[Windows.Markup.XamlReader]</span><span style="color: darkgrey;">::</span>Load( <span style="color: orangered;">$reader</span> )<br />
<span style="color: darkgreen;">## sets right click to "Close Window"</span><br />
<span style="color: orangered;">$popup</span><span style="color: darkgrey;">.</span>Add_MouseRightButtonUp({<span style="color: orangered;">$this</span><span style="color: darkgrey;">.</span>close()})<br />
<span style="color: darkgreen;">## sets left click to "Drag\move Window"</span><br />
<span style="color: orangered;">$popup</span><span style="color: darkgrey;">.</span>Add_MouseLeftButtonDown({<span style="color: orangered;">$This</span><span style="color: darkgrey;">.</span>DragMove()})<br />
<span style="color: darkgreen;">## Always on top of all other windows</span><br />
<span style="color: orangered;">$popup</span><span style="color: darkgrey;">.</span>Topmost <span style="color: darkgrey;">=</span> <span style="color: orangered;">$True</span><br />
<span style="color: orangered;">$popup</span><span style="color: darkgrey;">.</span>ShowDialog()<br />
})<span style="color: darkgrey;">.</span>BeginInvoke() <span style="color: darkgrey;">|</span> <span style="color: blue;">Out-Null</span></div>
</td></tr>
</tbody></table>
</div>
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPgWz2qgA8QUfToO3FzzPMLkBFkzq-scb0KAiAklJ_PiIflEFgtD1MHpUZb4Ci-t3iZ4tAJ5gozIzdy_Cu8kr8we-X3Qb06NQS7pXBN-dxdBbF0qWcqB9K9EHWstiMf1A4PNyoIx4WPbw/s1600/popup.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPgWz2qgA8QUfToO3FzzPMLkBFkzq-scb0KAiAklJ_PiIflEFgtD1MHpUZb4Ci-t3iZ4tAJ5gozIzdy_Cu8kr8we-X3Qb06NQS7pXBN-dxdBbF0qWcqB9K9EHWstiMf1A4PNyoIx4WPbw/s1600/popup.png" height="352" width="640" /></a></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2mlHhaVn6L6-nJCbH3sMBXUaxu9cILRiXDrw2kcjRj04lcnoLb82g_3MU-iCgEgWoRNXmaFIb3GEKax03aa4wMTTTuaXzCRHRmBAuWZjmNK160SyOtDmI8f7QkXifUsqeLJIa3cvY13w/s1600/popupalone.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2mlHhaVn6L6-nJCbH3sMBXUaxu9cILRiXDrw2kcjRj04lcnoLb82g_3MU-iCgEgWoRNXmaFIb3GEKax03aa4wMTTTuaXzCRHRmBAuWZjmNK160SyOtDmI8f7QkXifUsqeLJIa3cvY13w/s1600/popupalone.png" height="360" width="640" /></a></div>
BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0United States37.09024 -95.712891000000013-36.612596 98.349608999999987 90 70.224608999999987tag:blogger.com,1999:blog-6417475995992020348.post-29613829466552136142014-09-11T08:29:00.000-05:002014-09-12T05:06:40.213-05:00Cleanup WinSxS<div>
Cleanup WinSxS with PowerShell, remove features on demand in Windows Server 2012.</div>
<div>
<br /></div>
<div>
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
001</div>
</td>
<td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
<span style="color: blue;">Get-WindowsFeature</span> <span style="color: darkgrey;">|</span> <span style="color: blue;">where-object</span>{<span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>Installed <span style="color: darkgrey;">-eq</span> <span style="color: purple;">0</span> <span style="color: darkgrey;">-and</span> <span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>InstallState <span style="color: darkgrey;">-eq</span> <span style="color: darkred;">'Available'</span>}
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig0r87-ygCSSLSOfaTKilEjJPDSpQZzM8oNjvIWiR3zs-hBAk5oZKrIwPsVERWMcfObg9KgwwTcF6nQMj7kl47wrLcz4cr2jHlXXFeiUJCIOI00PjNajeaLNuKlK6I5GPgoVELZB6FBS0/s1600/winsxs.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig0r87-ygCSSLSOfaTKilEjJPDSpQZzM8oNjvIWiR3zs-hBAk5oZKrIwPsVERWMcfObg9KgwwTcF6nQMj7kl47wrLcz4cr2jHlXXFeiUJCIOI00PjNajeaLNuKlK6I5GPgoVELZB6FBS0/s1600/winsxs.png" /></a></div>
<div>
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
001</div>
</td>
<td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
<span style="color: blue;">Get-WindowsFeature</span> <span style="color: darkgrey;">|</span> <span style="color: blue;">where-object</span>{<span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>Installed <span style="color: darkgrey;">-eq</span> <span style="color: purple;">0</span> <span style="color: darkgrey;">-and</span> <span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>InstallState <span style="color: darkgrey;">-eq</span> <span style="color: darkred;">'Available'</span>} <span style="color: darkgrey;">|</span> <span style="color: blue;">uninstall-windowsfeature</span> <span style="color: navy;">-remove</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkC6TUGQ-MNIoa17LqJfyLfIY63akKu-ERDET53XPbKMGHRgyEr6_pDbeaxREKq5mcWVMNCaLWO_Wv9cahlgvxGikgUE6mOa_H5DLAZX84gPSBqUlJ0ufSdNGBMNAwTZJbcP7Xu-23bOs/s1600/doit.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkC6TUGQ-MNIoa17LqJfyLfIY63akKu-ERDET53XPbKMGHRgyEr6_pDbeaxREKq5mcWVMNCaLWO_Wv9cahlgvxGikgUE6mOa_H5DLAZX84gPSBqUlJ0ufSdNGBMNAwTZJbcP7Xu-23bOs/s1600/doit.png" /></a></div>
BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0United States37.09024 -95.712891000000013-36.612596 98.349608999999987 90 70.224608999999987tag:blogger.com,1999:blog-6417475995992020348.post-2361121693933754552014-08-17T00:32:00.001-05:002014-08-17T01:46:38.306-05:00Bored?The below script with go through a list of PowerShell links and open them each up one at a time within a single tab. Every 2 seconds a new article will appear -- when you find something good just hit [CTRL]+C to stop the script form continuing.<br />
<body> <br />
<!--StartFragment--> <br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;"><table border="0" cellpadding="5" cellspacing="0"><tr> <td valign="Top"> <br />
<div style="background: #cecece; font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;">001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
</div></td> <td nowrap="NOWRAP" valign="Top"> <br />
<div style="background: #fcfcfc; font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;"><span style="color: orangered;">$blog</span><span style="color: black;"></span><span style="color: darkgrey;">=</span><span style="color: black;"></span><span style="color: darkred;">"http://www.matthewkerfoot.com/p/powershell-links.html"</span><br />
<span style="color: orangered;">$ie</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: blue;">new-object</span><span style="color: black;"> </span><span style="color: navy;">-com</span><span s="" tyle="color:#000000"> </span><span style="color: blueviolet;">internetexplorer.application</span><br />
<span style="color: orangered;">$iwr</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: blue;">Invoke-WebRequest</span><span style="color: black;"> </span><span style="color: navy;">-Uri</span><span style="color: black;"> </span><span style="color: orangered;">$blog</span><br />
<span style="color: orangered;">$links</span><span style="color: black;"> </span><span style="color: darkgrey;">=</span><span style="color: black;"> </span><span style="color: orangered;">$iwr</span><span style="color: darkgrey;">.</span><span style="color: black;">Links</span><span style="olor: #000000;"> </span><span style="color: darkgrey;">|</span><span style="color: black;"> </span><span style="color: blue;">Select-Object</span><span style="color: black;"> </span><span style="color: navy;">-skip</span><span style="color: black;"> </span><span style="olor: #800080;">7</span><span style="color: black;"> </span><span style="color: navy;">-ExpandProperty</span><span style="color: black;"> </span><span style="color: blueviolet;">href</span><br />
<span style="color: darkblue;">foreach</span><span style="color: black;">(</span><span style="color: orangered;">$l</span><span style="color: black;"> </span><span style="color: darkblue;">in</span><span style="color: black;"> </span><span style="color: orangered;">$links</span><span style="color: black;">)</span><span style="color: black;">{</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$ie</span><span style="color: darkgrey;">.</span><span style="color: black;">visible</span><span style="color: darkgrey;">=</span><span style="color: orangered;">$true</span><br />
<span style="color: black;"> </span><span style="color: orangered;">$ie</span><span style="color: darkgrey;">.</span><span style="color: black;">navigate</span><span style="color: black;">(</span><span style="color: darkred;">"$l"</span><span style="color: black;">)</span><br />
<span style="color: black;"> </span><span style="color: darkblue;">while</span><span style="color: #0 00000;"> </span><span style="color: black;">(</span><span style="color: orangered;">$ie</span><span style="color: darkgrey;">.</span><span style="color: black;">Busy</span><span style="color: black;"> </span><span style="color: darkgrey;">-eq</span><span style="color: black;"> </span><span style="color: orangered;">$true</span><span style="color: black;">)</span><span style="color: black;">{</span><span style="color: black;"> </span><br />
<span style="color: black;"> </span><span style="color: blue;">Wait-Event</span><span style="color: black;"> </span><span style="color: navy;">-Timeout</span><span style="color: black;"> </span><span style="color: purple;">2</span><br />
<span style="color: black;"> </span><span style="color: black;">}</span><br />
<span style="color: black;">}</span> <br />
</div></td> </tr>
</table></div></body> <!--EndFragment--> BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0tag:blogger.com,1999:blog-6417475995992020348.post-68905425904058499932014-08-12T09:29:00.000-05:002014-08-12T09:29:47.401-05:00Easiest way to create a lot of AD accounts.<br />
If <span style="background-color: #fcfcfc; color: orangered; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">$number</span> is an array from 1 to <span style="background-color: #fcfcfc; color: purple; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">300</span> and for every number or <span style="background-color: #fcfcfc; color: orangered; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">$n</span> we run <span style="color: blue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">New-ADUser</span><span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;"> </span><span style="color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">-name</span><span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;"> </span><span style="color: orangered; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">$n</span> were going to get <span style="background-color: #fcfcfc; color: purple; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">300</span> users with names like <span style="background-color: #fcfcfc; color: purple; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">1</span>, 2 , 3, 4..<span style="background-color: #fcfcfc; color: purple; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">300</span>.<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td valign="Top">
<div style="background: rgb(206, 206, 206); font-size: 10pt; padding: 5px;">
001<br />002<br />003<br />004<br />005<br />006<br />
</div>
</td>
<td nowrap="NOWRAP" valign="Top">
<div style="background: rgb(252, 252, 252); font-size: 10pt; padding: 5px;">
<span style="color: blue;">PS</span> <span style="color: blueviolet;">C:\></span> <span style="color: blueviolet;">1..5</span> <span style="color: darkgreen;"># sample Array</span><br />
<span style="color: purple;">1</span><br />
<span style="color: purple;">2</span><br />
<span style="color: purple;">3</span><br />
<span style="color: purple;">4</span><br />
<span style="color: purple;">5</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td valign="Top">
<div style="background: rgb(206, 206, 206); font-size: 10pt; padding: 5px;">
001<br />002<br />003<br />004<br />
</div>
</td>
<td nowrap="NOWRAP" valign="Top">
<div style="background: rgb(252, 252, 252); font-size: 10pt; padding: 5px;">
<span style="color: orangered;">$number</span> <span style="color: darkgrey;">=</span> <span style="color: purple;">1</span><span style="color: darkgrey;">..</span><span style="color: purple;">300</span><br />
<span style="color: darkblue;">foreach</span> (<span style="color: orangered;">$n</span> <span style="color: darkblue;">in</span> <span style="color: orangered;">$number</span>){<br />
<span style="color: blue;">New-ADUser</span> <span style="color: navy;">-name</span> <span style="color: orangered;">$n</span> <span style="color: navy;">-verbose</span><br />
}
</div>
</td>
</tr>
</tbody>
</table>
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_qbeODa7oFKXvemWSqRn2Z9hGEFaBXVCvELnI0BGDvJ0x7z9_ZFfXzdd2dlpuERE03C47RZ1u9HdoKVbXZpgnaNvMUseijLEYJIYGMMZ3z0IE1cYp_vuqjp2LN-oeJtPNgyvWSFFXcp8/s1600/300.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_qbeODa7oFKXvemWSqRn2Z9hGEFaBXVCvELnI0BGDvJ0x7z9_ZFfXzdd2dlpuERE03C47RZ1u9HdoKVbXZpgnaNvMUseijLEYJIYGMMZ3z0IE1cYp_vuqjp2LN-oeJtPNgyvWSFFXcp8/s1600/300.png" height="537" width="640" /></a></div>
<br />BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0Minneapolis, MN 55427, USA45.0155422 -93.37679759999997545.0155422 -93.376797599999975 45.0155422 -93.376797599999975tag:blogger.com,1999:blog-6417475995992020348.post-28253386351922190572014-08-11T09:10:00.001-05:002014-08-11T09:17:44.802-05:00Start a Google search from within a PowerShell ConsoleHere is what I like to call a little <i>fun function,</i> this function allows you to easily search <a href="http://www.google.com/">www.google.com</a> for anything your heart desires. By default it will search for <span style="background-color: #fcfcfc; color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">"The Overnight Admin"</span> unless you specify with the <span style="background-color: #fcfcfc; color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">-Search</span> parameter like I did as an example on line 34.<br />
<br />
The reason that just typing <span style="background-color: #fcfcfc; color: blueviolet; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">Start-Google </span>at will search for <span style="background-color: #fcfcfc; color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">"The Overnight Admin"</span> is because within the <span style="background-color: #fcfcfc; color: darkblue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">param</span> block I've set the <span style="background-color: #fcfcfc; color: orangered; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">$Search</span> parameter to equal the <span style="background-color: #fcfcfc; color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">"The Overnight Admin"</span>, but if you type <span style="color: blue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">Start-Google</span><span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;"> </span><span style="color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">-Search</span><span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;"> </span><span style="color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">"</span><span style="color: darkred; font-family: Consolas, Lucida Console; font-size: x-small;"><span style="white-space: nowrap;">powershell</span></span><span style="color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">"</span> that will overwrite the <span style="background-color: #fcfcfc; color: orangered; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">$Search</span> parameter and open the Google search page for <span style="color: darkred; font-family: Consolas, 'Lucida Console'; font-size: x-small; white-space: nowrap;">powershell</span>.<br />
<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td valign="Top"><div style="background: rgb(206, 206, 206); font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004<br />
005</div>
</td>
<td nowrap="NOWRAP" valign="Top"><div style="background: rgb(252, 252, 252); font-size: 10pt; padding: 5px;">
<span style="color: darkblue;">param</span> (<span style="color: darkgrey;">[</span><span style="color: deepskyblue;">Parameter</span>(Mandatory<span style="color: darkgrey;">=</span><span style="color: orangered;">$false</span><span style="color: darkgrey;">,</span><br />
ValueFromPipelineByPropertyName<span style="color: darkgrey;">=</span><span style="color: orangered;">$true</span><span style="color: darkgrey;">,</span><br />
Position<span style="color: darkgrey;">=</span><span style="color: purple;">0</span>)<span style="color: darkgrey;">]</span><br />
<span style="color: orangered;">$Search</span> <span style="color: darkgrey;">=</span> <span style="color: darkred;">"The Overnight Admin"</span><br />
)
</div>
</td>
</tr>
</tbody>
</table>
</div>
<br />
<br />
Enjoy!<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td valign="Top"><div style="background: rgb(206, 206, 206); font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015<br />
016<br />
017<br />
018<br />
019<br />
020<br />
021<br />
022<br />
023<br />
024<br />
025<br />
026<br />
027<br />
028<br />
029<br />
030<br />
031<br />
032<br />
033<br />
034</div>
</td>
<td nowrap="NOWRAP" valign="Top"><div style="background: rgb(252, 252, 252); font-size: 10pt; padding: 5px;">
<span style="color: darkblue;">Function</span> <span style="color: blueviolet;">Start-Google</span><br />
{<br />
<span style="color: darkgreen;"><#<br />
.Synopsis<br />
Searches the Googes<br />
.DESCRIPTION<br />
Lets you quickly start a search Google from within Powershell<br />
.EXAMPLE<br />
Start-Google -search PowerShell<br />
#></span><br />
<span style="color: darkgrey;">[</span><span style="color: deepskyblue;">CmdletBinding</span>()<span style="color: darkgrey;">]</span><br />
<span style="color: darkblue;">Param</span> ( <span style="color: darkgrey;">[</span><span style="color: deepskyblue;">Parameter</span>(Mandatory<span style="color: darkgrey;">=</span><span style="color: orangered;">$false</span><span style="color: darkgrey;">,</span><br />
ValueFromPipelineByPropertyName<span style="color: darkgrey;">=</span><span style="color: orangered;">$true</span><span style="color: darkgrey;">,</span><br />
Position<span style="color: darkgrey;">=</span><span style="color: purple;">0</span>)<span style="color: darkgrey;">]</span><br />
<span style="color: orangered;">$Search</span> <span style="color: darkgrey;">=</span> <span style="color: darkred;">"The Overnight Admin"</span><span style="color: darkgrey;">,</span><br />
<span style="color: darkgrey;">[</span><span style="color: deepskyblue;">Parameter</span>(Mandatory<span style="color: darkgrey;">=</span><span style="color: orangered;">$false</span><span style="color: darkgrey;">,</span><br />
ValueFromPipelineByPropertyName<span style="color: darkgrey;">=</span><span style="color: orangered;">$true</span><span style="color: darkgrey;">,</span><br />
Position<span style="color: darkgrey;">=</span><span style="color: purple;">0</span>)<span style="color: darkgrey;">]</span><br />
<span style="color: orangered;">$google</span> <span style="color: darkgrey;">=</span> <span style="color: darkred;">"https://www.google.com/search?q="</span><br />
)<br />
<span style="color: darkblue;">Begin</span> {<br />
<span style="color: orangered;">$ie</span> <span style="color: darkgrey;">=</span> <span style="color: blue;">new-object</span> <span style="color: navy;">-com</span> <span style="color: blueviolet;">internetexplorer.application</span><br />
}<br />
<span style="color: darkblue;">Process</span> {<br />
<span style="color: orangered;">$Search</span> <span style="color: darkgrey;">|</span> <span style="color: blue;">ForEach-Object</span> { <span style="color: orangered;">$google</span> <span style="color: darkgrey;">=</span> <span style="color: orangered;">$google</span> <span style="color: darkgrey;">+</span> <span style="color: darkred;">"$_+"</span>}<br />
}<br />
<span style="color: darkblue;">End</span><br />
{<br />
<span style="color: orangered;">$url</span> <span style="color: darkgrey;">=</span> <span style="color: orangered;">$google</span><span style="color: darkgrey;">.</span>Substring(<span style="color: purple;">0</span><span style="color: darkgrey;">,</span><span style="color: orangered;">$google</span><span style="color: darkgrey;">.</span>Length<span style="color: darkgrey;">-</span><span style="color: purple;">1</span>)<br />
<span style="color: orangered;">$ie</span><span style="color: darkgrey;">.</span>navigate( <span style="color: orangered;">$url</span> )<br />
<span style="color: orangered;">$ie</span><span style="color: darkgrey;">.</span>visible <span style="color: darkgrey;">=</span> <span style="color: orangered;">$true</span><br />
}<br />
}<br />
<span style="color: blue;">Start-Google</span> <span style="color: navy;">-Search</span> <span style="color: darkred;">"Enter Hilarious Search Here"</span></div>
</td></tr>
</tbody></table>
</div>
BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0United States37.09024 -95.712891000000013-36.4181565 99.052733999999987 90 69.521483999999987tag:blogger.com,1999:blog-6417475995992020348.post-85756940420570542462014-08-11T07:25:00.000-05:002017-06-29T18:34:46.774-05:00Download all images from a web page with PowerShellWeb Scraping also known as Screen Scraping, Web Data Extraction, or Web Harvesting is a technique used to extract large amounts of data from one or multiple web sites.<br />
<br />
Most websites don't offer the functionality to save the data from their site onto your computer. Typically the only option is to <i>Right Click > Save As</i>, which can become a very tedious task very quickly. Being able to scrap a site of its content could most certainly have it's uses, such as; perhaps you want to download <a href="http://en.wikipedia.org/wiki/Main_Page" target="_blank">Wikipidia</a>(which I heard is only 14GBs with no pictures), or your really into something like PowerShell, you could search Google for all images with powershell in the name and then download them to you computer.[Next Upcoming Post]<br />
<br />
In the below function I scrape my web sites homepage for all of it's images, this means that my computer will do a search of my homepage [http://www.matthewkerfooot.com] for all image files and then download them to my local machine.<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004</div>
</td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
<span style="color: orangered;">$Url</span> <span style="color: darkgrey;">=</span> <span style="color: darkred;">"http://www.TheOvernightAdmin.com"</span><br />
<span style="color: orangered;">$iwr</span> <span style="color: darkgrey;">=</span> <span style="color: blue;">Invoke-WebRequest</span> <span style="color: navy;">-Uri</span> <span style="color: orangered;">$Url</span><br />
<span style="color: orangered;">$images</span> <span style="color: darkgrey;">=</span> (<span style="color: orangered;">$iwr</span>)<span style="color: darkgrey;">.</span>Images <span style="color: darkgrey;">|</span> <span style="color: blue;">select</span> <span style="color: blueviolet;">src</span><br />
<span style="color: orangered;">$images</span></div>
</td></tr>
</tbody></table>
</div>
<br />
Output:<br />
<br />
<pre class="PoshConsole">PS C:\> $images
src
---
http://img1.blogblog.com/img/icon18_wrench_allbkg.png
http://img1.blogblog.com/img/icon18_wrench_allbkg.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2-MeZf9LB70psOUNXQR5bZdkDZCCgfohOI25DusGLDSQqVDFubnV52a-mdwqgCSa9FkvHOUh9J_UYk52AUGP9G7ciSrV-4YxSH8DVeZ2RRSn5bu8CRljguqkfBXmrG18c6bLcJKlgFJI/s1600/3spaces.JPG
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2-MeZf9LB70psOUNXQR5bZdkDZCCgfohOI25DusGLDSQqVDFubnV52a-mdwqgCSa9FkvHOUh9J_UYk52AUGP9G7ciSrV-4YxSH8DVeZ2RRSn5bu8CRljguqkfBXmrG18c6bLcJKlgFJI/s1600/3spaces.JPG
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5-DOrMYIyvCdHe5St3MIAPgjoguh4YYoPK8VqFiL3N1wRAH7VBv_KzS2suq7HV8sAtnLnvEsBUeqNVEKAMKRCUzYVvRj9SPjyiAuhRVQ_bUNweRhyphenhyphenh5DuIjoA35A2_zKLfuMkvpy8BQ/s1600/computerlists.JPG
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAEjZ1mUkKD2oFHcE1zOlFIwvbx4JQn8FZYJqgemAKJeB1oU09vFRle1VrMg19wCLdVeWgx_nUxMrnWkEc8Ued4EdhxXh9erASTtXzgmJhzp-mMMLDW8QWBCWZHnmGzA9fC30jtWGXwQg/s1600/finalproduct.JPG
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsjHq0MYuYo_iR-ztwv9_k9Jrz7uDj9TJ-SOmOkKEsynQvBYoGNJpC_BZtVTdorBG2SJdi3SfnB5Z-1lVVxtcS6GFTBXsKNMr3uUzdePb1OENcUkpngnx2f1KP2PuhWeeE7Pt4mA3rxmc/s1600/sysadminbeer.png
Continued...
PS C:\> </pre>
<br />
The <span style="background-color: #fcfcfc; color: blue; font-family: "consolas" , "lucida console"; font-size: 13px; white-space: nowrap;">Invoke-WebRequest</span> cmdlet used above will filter my webpage for all image files via <span style="color: blue; font-family: "consolas" , "lucida console"; font-size: 13px; white-space: nowrap;">select</span><span style="background-color: #fcfcfc; font-family: "consolas" , "lucida console"; font-size: 13px; white-space: nowrap;"> </span><span style="color: blueviolet; font-family: "consolas" , "lucida console"; font-size: 13px; white-space: nowrap;">src</span> . Which would give us a list of all of the image paths that we will be downloading later.<br />
<br />
The only difference from web scraping and web browsing is that when you are scraping it is usually automated and you are also saving the data, not just viewing it.<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
Here is the full function</div>
<div>
<br /></div>
<div>
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015<br />
016<br />
017<br />
018<br />
019<br />
020<br />
021<br />
022<br />
023<br />
024<br />
025<br />
026<br />
027<br />
028<br />
029<br />
030<br />
031<br />
032<br />
033<br />
034<br />
035<br />
036<br />
037<br />
038<br />
039<br />
040<br />
041<br />
042<br />
043<br />
044<br />
045<br />
046</div>
</td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
<span style="color: darkblue;">function</span> <span style="color: blueviolet;">Get-WebPageImages</span><br />
{<br />
<span style="color: darkgreen;"><# <br />
.CREATED BY: <br />
Matt Kerfoot <br />
.CREATED ON: <br />
08/11/2014 <br />
.Synopsis <br />
Downloads all available images from the specified $URL (A mandatory Variable)<br />
.DESCRIPTION <br />
This funciton will download all images from a specific web page and save them to your desktop by default.<br />
Requires PSv3+ <br />
.EXAMPLE <br />
PS C:\> Get-WebPageImages -Url http://www.matthewkerfoot.com -outputpath c:\<br />
#></span><br />
<span style="color: darkgrey;">[</span><span style="color: deepskyblue;">CmdletBinding</span>()<span style="color: darkgrey;">]</span><br />
<span style="color: darkblue;">Param</span> ( <span style="color: darkgrey;">[</span><span style="color: deepskyblue;">Parameter</span>(Mandatory<span style="color: darkgrey;">=</span><span style="color: orangered;">$false</span><span style="color: darkgrey;">,</span><br />
ValueFromPipelineByPropertyName<span style="color: darkgrey;">=</span><span style="color: orangered;">$true</span><span style="color: darkgrey;">,</span><br />
Position<span style="color: darkgrey;">=</span><span style="color: purple;">0</span>)<span style="color: darkgrey;">]</span><br />
<span style="color: orangered;">$Url</span> <span style="color: darkgrey;">=</span> <span style="color: darkred;">"http://www.TheOvernightAdmin.com"</span><span style="color: darkgrey;">,</span><br />
<span style="color: orangered;">$OutputPath</span> <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$env:USERPROFILE\Desktop\"</span><br />
)<br />
<br />
<span style="color: darkblue;">Begin</span> {<br />
<br />
<span style="color: orangered;">$iwr</span> <span style="color: darkgrey;">=</span> <span style="color: blue;">Invoke-WebRequest</span> <span style="color: navy;">-Uri</span> <span style="color: orangered;">$Url</span><br />
<span style="color: orangered;">$images</span> <span style="color: darkgrey;">=</span> (<span style="color: orangered;">$iwr</span>)<span style="color: darkgrey;">.</span>Images <span style="color: darkgrey;">|</span> <span style="color: blue;">select</span> <span style="color: blueviolet;">src</span><br />
<br />
}<br />
<br />
<span style="color: darkblue;">Process</span> {<br />
<br />
<span style="color: orangered;">$wc</span> <span style="color: darkgrey;">=</span> <span style="color: blue;">New-Object</span> <span style="color: blueviolet;">System.Net.WebClient</span><br />
<span style="color: orangered;">$images</span> <span style="color: darkgrey;">|</span> <span style="color: blue;">foreach</span> { <span style="color: orangered;">$wc</span><span style="color: darkgrey;">.</span>DownloadFile( <span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>src<span style="color: darkgrey;">,</span> (<span style="color: darkred;">"$OutputPath\"</span><span style="color: darkgrey;">+</span><span style="color: teal;">[io.path]</span><span style="color: darkgrey;">::</span>GetFileName(<span style="color: orangered;">$_</span><span style="color: darkgrey;">.</span>src) ) ) }<br />
}<br />
<br />
<span style="color: darkblue;">End</span> {<br />
<br />
<span style="color: blue;">Write-Host</span> <span style="color: darkred;">"Downloading all images from $Url to $OutputPath"</span><br />
<br />
}<br />
<br />
}<br />
<br />
<span style="color: blue;">Get-WebPageImages</span></div>
</td> </tr>
</tbody> </table>
</div>
</div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI0fbrocwXcLEm415FFXC6ow5VtR0KW-y0jtyeHOU0PQ8nJIs6CptNPDTXTksZUFKaufiVZTZ8huYXfM3qC1rsz48-bvjIS5LuXUyZAjvVH3L5HkY0cd7KBHq44U7Ly4uYvF1L4iiKDJE/s1600/imagesssssssssssssssssssssssssssss.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI0fbrocwXcLEm415FFXC6ow5VtR0KW-y0jtyeHOU0PQ8nJIs6CptNPDTXTksZUFKaufiVZTZ8huYXfM3qC1rsz48-bvjIS5LuXUyZAjvVH3L5HkY0cd7KBHq44U7Ly4uYvF1L4iiKDJE/s1600/imagesssssssssssssssssssssssssssss.JPG" /></a><br />
<br />
<br />
<br />
<br />
<br />BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0Minneapolis, MN 55427, USA45.0155422 -93.37679759999997544.925730699999995 -93.538159099999973 45.1053537 -93.215436099999977tag:blogger.com,1999:blog-6417475995992020348.post-51942777004774091632014-08-09T19:08:00.000-05:002014-08-09T19:40:21.509-05:00Create a list of Computer Names with no spaces with PowerShellA few months back a co-worker of mine shot an email my way asking what the best way to create a list of all of the servers in the domain so that he could run a script against them way.<br />
<br />
If you haven't ever done this before it can be a little trickier than you might originally think. The best way I've found to do this is with a function. A function allows you to name a block of code. Once defined you can then call that function block anywhere in a script or just at the console. Personally functions are one of my favorite things about PowerShell, well at least its up their with <a href="http://www.matthewkerfoot.com/2014/01/powershell-remoting-invoke-command.html" target="_blank">PS-Remoting</a>, <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/12/26/powershell-workflows-the-basics.aspx" target="_blank">Workflows</a>, and <a href="http://www.matthewkerfoot.com/2014/07/powershell-desired-state-configuration.html" target="_blank">Desired State Configuration</a>. Functions have 6 main parts; The Functions Name, a help file, param block, and a begin, Process, and End Block [Shown Below].<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background: rgb(206, 206, 206); font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015<br />
016<br />
017</div>
</td> <td nowrap="NOWRAP" valign="Top"><div style="background: rgb(252, 252, 252); font-size: 10pt; padding: 5px;">
<span style="color: darkblue;">function</span> <span style="color: blueviolet;">Get-ComputerList</span> { <span style="color: darkgreen;"># The Funtions Name</span><br />
<br />
<span style="color: darkgreen;"><#...#></span> <span style="color: darkgreen;">#Help File</span><br />
<br />
<span style="color: darkgrey;">[</span><span style="color: deepskyblue;">CmdletBinding</span>()<span style="color: darkgrey;">]</span><br />
<span style="color: darkblue;">Param</span> ( <span style="color: darkgreen;">#Param Block</span><br />
)<br />
<br />
<span style="color: darkblue;">Begin</span> { <span style="color: darkgreen;">#Begin Block</span><br />
}<br />
<br />
<span style="color: darkblue;">Process</span> { <span style="color: darkgreen;">#Process Block</span><br />
}<br />
<br />
<span style="color: darkblue;">End</span> { <span style="color: darkgreen;">#End Block</span><br />
} <br />
} </div>
</td> </tr>
</tbody> </table>
</div>
<br />
Now lets take a look at what I've chosen to place into the Param, Begin, Process, and End blocks.<br />
<br />
<br />
<h3>
Param</h3>
First off I always like to define the location of the text file in the parameter block but this comes down to personal preference.<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004<br />
005</div>
</td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
<span style="color: darkblue;">Param</span> ( <span style="color: darkgrey;">[</span><span style="color: deepskyblue;">Parameter</span>(Mandatory<span style="color: darkgrey;">=</span><span style="color: orangered;">$false</span><span style="color: darkgrey;">,</span><br />
ValueFromPipelineByPropertyName<span style="color: darkgrey;">=</span><span style="color: orangered;">$true</span><span style="color: darkgrey;">,</span><br />
Position<span style="color: darkgrey;">=</span><span style="color: purple;">0</span>)<span style="color: darkgrey;">]</span><br />
<span style="color: orangered;">$OutputPath</span> <span style="color: darkgrey;">=</span> <span style="color: darkred;">"$env:USERPROFILE\Desktop\ComputerList.txt"</span><br />
) </div>
</td> </tr>
</tbody> </table>
</div>
<br />
I made <span style="background-color: #fcfcfc; color: orangered; font-family: Consolas, 'Lucida Console'; font-size: 13px; white-space: nowrap;">$OutputPath</span> above equal <span style="background-color: #fcfcfc; color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13px; white-space: nowrap;">"$env:USERPROFILE\Desktop\ComputerList.txt" </span>which is where the newly created computer list will be <span style="background-color: #fcfcfc; color: blue; font-family: Consolas, 'Lucida Console'; font-size: 13px; white-space: nowrap;">Out-File</span>'d' too.<br />
<br />
<br />
<h3>
Begin</h3>
<div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2-MeZf9LB70psOUNXQR5bZdkDZCCgfohOI25DusGLDSQqVDFubnV52a-mdwqgCSa9FkvHOUh9J_UYk52AUGP9G7ciSrV-4YxSH8DVeZ2RRSn5bu8CRljguqkfBXmrG18c6bLcJKlgFJI/s1600/3spaces.JPG" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><br />
</a>The Begin Block -- This is where we I've chosen to gather the computer names and output them to the <span style="background-color: #fcfcfc; color: orangered; font-family: Consolas, 'Lucida Console'; font-size: 12.800000190734863px; white-space: nowrap;">$OutputPath</span> defined above in the <span style="background-color: #fcfcfc; color: darkblue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">Param</span> block. If we were to run only the cmdlets in the <span style="background-color: #fcfcfc; color: darkblue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">Param</span> block and the Begin block we would have a text file on our Desktop called ComputerList.txt.<br />
<br /></div>
<div>
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background: rgb(206, 206, 206); font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004</div>
</td> <td nowrap="NOWRAP" valign="Top"><div style="background: rgb(252, 252, 252); font-size: 10pt; padding: 5px;">
<span style="color: darkblue;">Begin</span> {<br />
<span style="color: darkgreen;"># requires PSv3.0+ -- retrieves all computer and server OS names</span><br />
<span style="color: blue;">Get-ADComputer</span> <span style="color: navy;">-Filter</span> <span style="color: blueviolet;">*</span> <span style="color: navy;">-Properties</span> <span style="color: blueviolet;">*</span> <span style="color: darkgrey;">|</span> <span style="color: blue;">Select-Object</span> <span style="color: navy;">-ExpandProperty</span> <span style="color: blueviolet;">name</span> <span style="color: darkgrey;">|</span> <span style="color: blue;">Out-File</span> <span style="color: orangered;">$OutputPath</span><br />
}</div>
</td></tr>
</tbody></table>
</div>
<br /></div>
<div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2-MeZf9LB70psOUNXQR5bZdkDZCCgfohOI25DusGLDSQqVDFubnV52a-mdwqgCSa9FkvHOUh9J_UYk52AUGP9G7ciSrV-4YxSH8DVeZ2RRSn5bu8CRljguqkfBXmrG18c6bLcJKlgFJI/s1600/3spaces.JPG" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2-MeZf9LB70psOUNXQR5bZdkDZCCgfohOI25DusGLDSQqVDFubnV52a-mdwqgCSa9FkvHOUh9J_UYk52AUGP9G7ciSrV-4YxSH8DVeZ2RRSn5bu8CRljguqkfBXmrG18c6bLcJKlgFJI/s1600/3spaces.JPG" /></a>Another commonly used parameter is the <span style="background-color: #fcfcfc; color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13px; white-space: nowrap;">-Filter </span>parameter which I've used to only retrieve computer names whose <span style="background-color: #fcfcfc; color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">OperatingSystem</span> field have <span style="background-color: #fcfcfc; color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13px; white-space: nowrap;">*Server* </span>in the name. From there the generated computer list is piped to <span style="background-color: #fcfcfc; color: blue; font-family: Consolas, 'Lucida Console'; font-size: 13.63636302947998px; line-height: 16.969696044921875px; white-space: nowrap;">Select-Object</span><span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13.63636302947998px; line-height: 16.969696044921875px; white-space: nowrap;"> </span><span style="background-color: #fcfcfc; color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; line-height: 16.969696044921875px; white-space: nowrap;">-ExpandProperty</span><span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13.63636302947998px; line-height: 16.969696044921875px; white-space: nowrap;"> </span><span style="background-color: #fcfcfc; color: blueviolet; font-family: Consolas, 'Lucida Console'; font-size: 13.63636302947998px; line-height: 16.969696044921875px; white-space: nowrap;">name</span>. A key thing to note, the <span style="background-color: #fcfcfc; color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; line-height: 16.969696044921875px; white-space: nowrap;">-ExpandProperty</span> parameter will give us a list of computers ready to run commands against. If we didn't use the <span style="background-color: #fcfcfc; color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; line-height: 16.969696044921875px; white-space: nowrap;">-ExpandProperty</span> parameter the output would contain header information as shown on the right. There is a way to make it work without using the <span style="background-color: #fcfcfc; color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; line-height: 16.969696044921875px; white-space: nowrap;">-ExpandProperty</span> parameter but I'll talk about that in the next section. After the list is generated and filtered everything is <span style="background-color: #fcfcfc; color: blue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">Out-File</span>'d' to <span style="background-color: #fcfcfc; color: orangered; font-family: Consolas, 'Lucida Console'; font-size: 13px; white-space: nowrap;">$OutputPath</span><span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13px; white-space: nowrap;"> </span>also known as<span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13px; white-space: nowrap;"> </span><span style="background-color: #fcfcfc; color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13px; white-space: nowrap;">$env:USERPROFILE\Desktop\ComputerList.txt.</span></div>
<div>
<span style="background-color: #fcfcfc; color: darkred; font-family: Consolas, 'Lucida Console'; font-size: 13px; white-space: nowrap;"><br />
</span></div>
<div>
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004</div>
</td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; padding: 5px;">
<div style="font-size: 10pt;">
<span style="color: darkblue;">Begin</span> {</div>
<div style="font-size: 10pt;">
<span style="color: darkgreen;"># requires PSv3.0+ -- </span><span style="color: darkgreen;"><b>retrieves all server OS names</b></span></div>
<span style="font-size: x-small;"> </span><span style="color: blue; font-size: 10pt;">Get-ADComputer</span><span style="font-size: x-small;"> </span><span style="color: navy; font-size: 10pt;">-Filter</span><span style="font-size: x-small;"> </span><span style="color: darkred; font-size: 10pt;">'OperatingSystem -like "*Server*"'</span><span style="font-size: x-small;"> </span><span style="color: darkgrey; font-size: 10pt;">|</span><span style="font-size: x-small;"> </span><span style="font-size: 10pt;"><span style="color: blue; font-size: 13.63636302947998px; line-height: 16.969696044921875px;">Select-Object</span><span style="font-size: 13.63636302947998px; line-height: 16.969696044921875px;"> </span><span style="color: navy; font-size: 13.63636302947998px; line-height: 16.969696044921875px;">-ExpandProperty</span><span style="font-size: 13.63636302947998px; line-height: 16.969696044921875px;"> </span><span style="color: blueviolet; font-size: 13.63636302947998px; line-height: 16.969696044921875px;">name</span> </span><span style="color: darkgrey; font-size: 10pt;">|</span><span style="font-size: 10pt;"> </span><span style="color: blue; font-size: 10pt;">Out-File</span><span style="font-size: 10pt;"> </span><span style="color: orangered; font-size: 10pt;">$OutputPath</span><br />
<div style="font-size: 10pt;">
} </div>
</div>
</td> </tr>
</tbody> </table>
</div>
</div>
<div>
<br />
<br /></div>
<h3>
Process</h3>
<div>
There are multiple different ways to extract or remove white spaces from a document.<br />
<br />
My favorite being:</div>
<div>
<br /></div>
<div>
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
001</div>
</td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
(<span style="color: blue;">Get-Content</span> <span style="color: orangered;">$OutputPath</span>)<span style="color: darkgrey;">.</span>replace(<span style="color: darkred;">" "</span><span style="color: darkgrey;">,</span><span style="color: darkred;">""</span>) </div>
</td> </tr>
</tbody> </table>
</div>
</div>
<div>
<br /></div>
<div>
<div>
<br /></div>
</div>
<div>
Here is another way to remove the white spaces from a file.</div>
<div>
<br /></div>
<div>
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
001</div>
</td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
(<span style="color: blue;">get-content</span> <span style="color: orangered;">$ComputerList</span>) <span style="color: darkgrey;">-replace</span> <span style="color: darkred;">"\s+"</span><span style="color: darkgrey;">,</span> <span style="color: darkred;">""</span> </div>
</td> </tr>
</tbody> </table>
</div>
</div>
<div>
<br />
<br />
<div>
<div>
Okay so lets say we didn't use <span style="background-color: #fcfcfc; color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13.63636302947998px; line-height: 16.969696044921875px; white-space: nowrap;">-ExpandProperty</span> in the <span style="background-color: #fcfcfc; color: darkblue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">Begin</span> block, If that were the case we could get around the problem of the output containing the header information by using the below line of code. </div>
<div>
<br /></div>
<br />
<div>
<div style="border: 1px solid black; font-family: Consolas, 'Lucida Console'; font-size: 10pt; overflow: auto; padding: 5px; width: 750px;">
<table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr><td valign="Top"><div style="background-color: #cecece; font-size: 10pt; padding: 5px;">
001</div>
</td><td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; font-size: 10pt; padding: 5px;">
(<span style="color: blue;">Get-Content</span> <span style="color: orangered;">$OutputPath</span> <span style="color: darkgrey;">|</span> <span style="color: blue;">Select-Object</span> <span style="color: navy;">-Skip</span> <span style="color: purple;">3</span>)<span style="color: darkgrey;">.</span>replace(<span style="color: darkred;">" "</span><span style="color: darkgrey;">,</span><span style="color: darkred;">""</span>)</div>
</td></tr>
</tbody></table>
</div>
</div>
</div>
<br />
<div>
</div>
<br />
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">
<div style="font-weight: normal; margin: 0px;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2-MeZf9LB70psOUNXQR5bZdkDZCCgfohOI25DusGLDSQqVDFubnV52a-mdwqgCSa9FkvHOUh9J_UYk52AUGP9G7ciSrV-4YxSH8DVeZ2RRSn5bu8CRljguqkfBXmrG18c6bLcJKlgFJI/s1600/3spaces.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2-MeZf9LB70psOUNXQR5bZdkDZCCgfohOI25DusGLDSQqVDFubnV52a-mdwqgCSa9FkvHOUh9J_UYk52AUGP9G7ciSrV-4YxSH8DVeZ2RRSn5bu8CRljguqkfBXmrG18c6bLcJKlgFJI/s1600/3spaces.JPG" /></a></div>
<div style="font-weight: normal; margin: 0px;">
<br /></div>
<b>The <span style="background-color: #fcfcfc; color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">-Skip</span><span style="background-color: #fcfcfc; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;"> </span><span style="background-color: #fcfcfc; color: purple; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">3 </span>will successfully <span style="background-color: #fcfcfc; color: navy; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">-Skip </span>the first three lines of the output which would need to be done before we could successfully run a script or function against it.</b></div>
<br /></div>
<div>
<br />
<div style="text-align: center;">
The process block in its entirety.</div>
</div>
<h2>
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004<br />
005</div>
</td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
<span style="color: darkblue;">Process</span> {<br />
<span style="color: darkgreen;"># removes empty spaces from txt document</span><br />
<span style="color: darkgreen;"># Alternate Way --> (get-content $ComputerList) -replace '\s+', '' </span><br />
<div style="text-align: center;">
<span style="color: orangered;">$ComputerList</span> <span style="color: darkgrey;">=</span> (<span style="color: blue;">Get-Content</span> <span style="color: orangered;">$OutputPath</span>)<span style="color: darkgrey;">.</span>replace(<span style="color: darkred;">" "</span><span style="color: darkgrey;">,</span><span style="color: darkred;">""</span>)</div>
} </div>
</td> </tr>
</tbody> </table>
</div>
</h2>
<h2>
</h2>
<h3>
</h3>
<br />
<br />
<h3>
End</h3>
<div>
The end block should be where you wrap up the function, this is where all <span style="background-color: #fcfcfc; color: blue; font-family: Consolas, 'Lucida Console'; font-size: 13.600000381469727px; white-space: nowrap;">Out-File'</span>s' will output their final products.This is where any formatting would be if you must place some in your script. However it is best practice not to do any formatting to the output as the next user who runs this script might want all the data to be displayed differently and this will allow he\she to simply format the data if they feel the need.</div>
<div>
<br /></div>
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;">
<table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"><div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
001<br />
002<br />
003<br />
004<br />
005<br />
006</div>
</td> <td nowrap="NOWRAP" valign="Top"><div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;">
<span style="color: darkblue;">End</span> {<br />
<span style="color: orangered;">$ComputerList</span> <span style="color: darkgrey;">|</span> <span style="color: blue;">Out-File</span> <span style="color: orangered;">$OutputPath</span><br />
<span style="color: blue;">write-verbose</span> <span style="color: darkred;">"The Computer list has been saved to $OutputPath"</span><br />
<span style="color: blue;">write-verbose</span> <span style="color: darkred;">"Opening file $OutputPath at this time"</span><br />
<span style="color: blue;">Invoke-Item</span> <span style="color: orangered;">$OutputPath</span><br />
} </div>
</td> </tr>
</tbody> </table>
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5-DOrMYIyvCdHe5St3MIAPgjoguh4YYoPK8VqFiL3N1wRAH7VBv_KzS2suq7HV8sAtnLnvEsBUeqNVEKAMKRCUzYVvRj9SPjyiAuhRVQ_bUNweRhyphenhyphenh5DuIjoA35A2_zKLfuMkvpy8BQ/s1600/computerlists.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5-DOrMYIyvCdHe5St3MIAPgjoguh4YYoPK8VqFiL3N1wRAH7VBv_KzS2suq7HV8sAtnLnvEsBUeqNVEKAMKRCUzYVvRj9SPjyiAuhRVQ_bUNweRhyphenhyphenh5DuIjoA35A2_zKLfuMkvpy8BQ/s1600/computerlists.JPG" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
The full function called <span style="background-color: #fcfcfc; color: blueviolet; font-family: Consolas, 'Lucida Console'; font-size: 13px; white-space: nowrap;">Get-ComputerList</span> can be downloaded at the <a href="http://gallery.technet.microsoft.com/scriptcenter/Create-a-computerlist-full-20e66a0d" target="_blank">Microsoft Script Repository</a>.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAEjZ1mUkKD2oFHcE1zOlFIwvbx4JQn8FZYJqgemAKJeB1oU09vFRle1VrMg19wCLdVeWgx_nUxMrnWkEc8Ued4EdhxXh9erASTtXzgmJhzp-mMMLDW8QWBCWZHnmGzA9fC30jtWGXwQg/s1600/finalproduct.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAEjZ1mUkKD2oFHcE1zOlFIwvbx4JQn8FZYJqgemAKJeB1oU09vFRle1VrMg19wCLdVeWgx_nUxMrnWkEc8Ued4EdhxXh9erASTtXzgmJhzp-mMMLDW8QWBCWZHnmGzA9fC30jtWGXwQg/s1600/finalproduct.JPG" height="470" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<!-- Blogger automated replacement: "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2-MeZf9LB70psOUNXQR5bZdkDZCCgfohOI25DusGLDSQqVDFubnV52a-mdwqgCSa9FkvHOUh9J_UYk52AUGP9G7ciSrV-4YxSH8DVeZ2RRSn5bu8CRljguqkfBXmrG18c6bLcJKlgFJI/s1600/3spaces.JPG" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2-MeZf9LB70psOUNXQR5bZdkDZCCgfohOI25DusGLDSQqVDFubnV52a-mdwqgCSa9FkvHOUh9J_UYk52AUGP9G7ciSrV-4YxSH8DVeZ2RRSn5bu8CRljguqkfBXmrG18c6bLcJKlgFJI/s1600/3spaces.JPG" --><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F3.bp.blogspot.com%2F-2ItS8yq1wxc%2FU-ShLKlbx7I%2FAAAAAAAAG3g%2FnH0vl6mt2Kw%2Fs1600%2F3spaces.JPG&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2-MeZf9LB70psOUNXQR5bZdkDZCCgfohOI25DusGLDSQqVDFubnV52a-mdwqgCSa9FkvHOUh9J_UYk52AUGP9G7ciSrV-4YxSH8DVeZ2RRSn5bu8CRljguqkfBXmrG18c6bLcJKlgFJI/s1600/3spaces.JPG" -->BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.comMinneapolis, MN 55427, USA45.0155422 -93.37679759999997544.925730699999995 -93.538159099999973 45.1053537 -93.215436099999977tag:blogger.com,1999:blog-6417475995992020348.post-51591564890594422592014-08-06T08:14:00.000-05:002014-08-18T09:24:58.422-05:00Which Hyper-V Host is hosting this VMLast night I was working on resolving a Veeam backup failure and needed to know which Hyper-V server was hosting the VM I was currently logged onto. As I do with everything server related alert I thought to myself -- hmm how can I retrieve this with PowerShell. The answer is simple, you just need to know where to look and in this case it was in the registry and I guarantee that running the below code in an Administrative PowerShell prompt is much more efficient than opening regedit and navigating to "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters". But to each their own, that is how some may prefer to gather their information...<br />
<br />
Oh and one more thing; If the hostname returned is a mix of letters and numbers about 10 characters long its hosted in Azure.<br />
<br />
<div style="border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750;"> <table border="0" cellpadding="5" cellspacing="0"><tbody>
<tr> <td valign="Top"> <div style="background-color: #cecece; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"> 001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
</div></td> <td nowrap="NOWRAP" valign="Top"> <div style="background-color: #fcfcfc; background-position: initial initial; background-repeat: initial initial; font-size: 10pt; padding: 5px;"> <span style="color: darkgreen;"># Retieves $env:COMPUTERNAME's Hyper-V Host Server Name</span><br />
<br />
<span style="color: darkblue;">Function</span> <span style="color: blueviolet;">Get-VMHostname</span><br />
<br />
{<br />
<br />
(<span style="color: blue;">Get-Item</span> <span style="color: darkred;">"HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters"</span>)<span style="color: darkgrey;">.</span>GetValue(<span style="color: darkred;">"HostName"</span>)<br />
<br />
}<br />
<br />
<span style="color: blue;">Get-VMHostname</span> </div></td> </tr>
</tbody> </table></div>BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0Minneapolis, MN 55427, USA45.0155422 -93.37679759999997544.925730699999995 -93.538159099999973 45.1053537 -93.215436099999977tag:blogger.com,1999:blog-6417475995992020348.post-4167404553408229652014-07-25T07:30:00.000-05:002014-07-26T03:40:07.992-05:00Happy Sys Admin Day!<h1>Star Wars Theme Song with PowerShell</h1><br />
In celebration of Sys Admin Day I bring to you the Star Wars theme song via PowerShell!<br />
<br />
<h1 style="text-align: center;">Enjoy!</h1><div><br />
</div><pre class="PoshConsole">[console]::beep(440,500)
[console]::beep(440,500)
[console]::beep(440,500)
[console]::beep(349,350)
[console]::beep(523,150)
[console]::beep(440,500)
[console]::beep(349,350)
[console]::beep(523,150)
[console]::beep(440,1000)
[console]::beep(659,500)
[console]::beep(659,500)
[console]::beep(659,500)
[console]::beep(698,350)
[console]::beep(523,150)
[console]::beep(415,500)
[console]::beep(349,350)
[console]::beep(523,150)
[console]::beep(440,1000)
</pre><br />
<div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;">Oh and don't forget to buy your Sys Admin a beer.</div><div class="separator" style="clear: both; text-align: center;"><br />
</div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsjHq0MYuYo_iR-ztwv9_k9Jrz7uDj9TJ-SOmOkKEsynQvBYoGNJpC_BZtVTdorBG2SJdi3SfnB5Z-1lVVxtcS6GFTBXsKNMr3uUzdePb1OENcUkpngnx2f1KP2PuhWeeE7Pt4mA3rxmc/s1600/sysadminbeer.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsjHq0MYuYo_iR-ztwv9_k9Jrz7uDj9TJ-SOmOkKEsynQvBYoGNJpC_BZtVTdorBG2SJdi3SfnB5Z-1lVVxtcS6GFTBXsKNMr3uUzdePb1OENcUkpngnx2f1KP2PuhWeeE7Pt4mA3rxmc/s1600/sysadminbeer.png" /></a></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;">All Sys Admins Like beer! </div>BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0tag:blogger.com,1999:blog-6417475995992020348.post-85269850754614747982014-07-08T09:44:00.000-05:002014-07-09T03:46:44.262-05:00Super Mario Theme Song with PowerShellHere's a little PowerShell script that plays the Super Mario Theme Song!!<br />
I hope you enjoy this as much as I enjoyed making it!!<br />
<pre class="PoshConsole"><##Super Mario Intro ##>
$i = 1
do {$i++
[console]::beep(659,250) ## E
[console]::beep(659,250) ## E
[console]::beep(659,300) ## E
[console]::beep(523,250) ## C
[console]::beep(659,250) ## E
[console]::beep(784,300) ## G
[console]::beep(392,300) ## G
[console]::beep(523,275) ## C
[console]::beep(392,275) ## G
[console]::beep(330,275) ## E
[console]::beep(440,250) ## A
[console]::beep(494,250) ## B
[console]::beep(466,275) ## A
[console]::beep(440,275) ## A
[console]::beep(392,275) ## G
[console]::beep(659,250) ## E
[console]::beep(784,250) ## G
[console]::beep(880,275) ## A
[console]::beep(698,275) ## F
[console]::beep(784,225) ## G
[console]::beep(659,250) ## E
[console]::beep(523,250) ## C
[console]::beep(587,225) ## D
[console]::beep(494,225) ## B
}until ($i -gt 1)</pre>BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0United States37.09024 -95.712891000000013-36.4181565 99.052733999999987 90 69.521483999999987tag:blogger.com,1999:blog-6417475995992020348.post-19692207031049309952014-07-08T09:11:00.000-05:002014-07-09T03:16:08.606-05:00Modify multiple Active Directory Accounts with PowerShellHas you company recently moved to a new location? If so here is a script to modify the "StreetAddress" Active Directory attribute for multiple users at once.<br />
<pre class="PoshConsole"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiILASr4q4cGwpPIbFhj0rOhMFDP0B_RtWiw_EOHqyabC86gVv0lC6h5kMSNQtnDpPye4xFnSxCYJw0qI44bl9D52CdsfDG7PH3DHG8QsWqr5Sa7mRGnbCB8EhDg65bo-4DD5mCnEp5jcI/s1600/ad.PNG" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiILASr4q4cGwpPIbFhj0rOhMFDP0B_RtWiw_EOHqyabC86gVv0lC6h5kMSNQtnDpPye4xFnSxCYJw0qI44bl9D52CdsfDG7PH3DHG8QsWqr5Sa7mRGnbCB8EhDg65bo-4DD5mCnEp5jcI/s200/ad.PNG" /></a>Import-Module ActiveDirectory
$users = $i = $null
$users = Get-ADUser -filter * -property StreetAddress
ForEach($user in $users)
{
if([string]::isNullOrEmpty($user.StreetAddress))
{
"modifying $($user.name)"
Set-ADUser -Identity $user.distinguishedName -StreetAddress "1600 Pennsylvania Ave NW"
$i++
}
} </pre>
<br />
This could be used to modify any of the Active Directory attributes by simply editing the -property being queried.BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0United States37.09024 -95.712891000000013-36.4181565 99.052733999999987 90 69.521483999999987tag:blogger.com,1999:blog-6417475995992020348.post-31776766071277335222014-07-08T09:02:00.000-05:002014-07-09T03:15:17.799-05:00PowerShell function to modify Active Directory IP Phone AttributesI follow many different PowerShell Scripting blogs and discussion groups, today someone said to the group, "I need to Update AD Attribute (IP Phone) for Bulk Users at a time."<br />
<br />
Here's what I came up with;<br />
<br />
<pre class="PoshConsole"><#
.CREATED BY:
Matthew A. Kerfoot
.CREATED ON:
07/08/2014
.SYNOPSIS
create and set IP Phone number in AD
.DESCRIPTION
This function will create and set the IP Phone attribute in Active Directory per user specified.
.EXAMPLE
Set-IPPhone -username mkerfoot -New_IP_Phone_Number 555-555-5555
#>
function Set-IPPhone {
[CmdletBinding()]
Param ( [Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$username,
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$New_IP_Phone_Number )
Begin { import-module activedirectory }
Process {
$user = Get-ADUser -identity $username | Foreach-Object { $lookup = "LDAP://" + $_.DistinguishedName;[ADSI]$lookup}
$user.put("IPPhone","$New_IP_Phone_Number")
}
End { $user.setinfo() }
} Set-IPPhone</pre><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk1Rxhg5U67-p0m0PtHAg0oxWfmmXBRWwvUJnLpFXFxY-see3vadXDSlcsRvijEiV7vvAQZu9D_TFTqu6JVO9zE9fTJct_WL2UYPR-Oz8wi40yNrnKfEaPylflCuR4wuNOCDg5eEBBIxI/s1600/lifeisgood.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk1Rxhg5U67-p0m0PtHAg0oxWfmmXBRWwvUJnLpFXFxY-see3vadXDSlcsRvijEiV7vvAQZu9D_TFTqu6JVO9zE9fTJct_WL2UYPR-Oz8wi40yNrnKfEaPylflCuR4wuNOCDg5eEBBIxI/s1600/lifeisgood.JPG" /></a></div><br />
BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.com0United States37.09024 -95.712891000000013-36.4181565 99.052733999999987 90 69.521483999999987tag:blogger.com,1999:blog-6417475995992020348.post-30037204142994188612014-04-24T10:10:00.000-05:002014-06-24T23:55:24.476-05:00Cleanup a D:\ Drive<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4K0qMCix4MsUvR2C-Sh1i0RN9_c2yiHFtyvrAQeJ7a7XFVt3h-YSG1LTFpVEPDC2cd2Gq3MJ3XhmmuM0m7VsiYvfEpPuly3j_DoQsTa-LsfnbOa09m-EtsgKtrsKCw9c8EbtdeKBziEY/s1600/data6.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4K0qMCix4MsUvR2C-Sh1i0RN9_c2yiHFtyvrAQeJ7a7XFVt3h-YSG1LTFpVEPDC2cd2Gq3MJ3XhmmuM0m7VsiYvfEpPuly3j_DoQsTa-LsfnbOa09m-EtsgKtrsKCw9c8EbtdeKBziEY/s1600/data6.jpg" height="212" width="320" /></a></div>
Have you ever had the pleasure to clean up a full D:\ drive? If yes, you know this can be a pretty daunting task. If No, just know that you need to be very careful with any data saved on any Volume C:\ through Z:\. Any Volume other than C:\ usually contains data that is irreplaceable weather it has backups saved on it or SQL data that is needed to keep a business running.<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbKha5UuzxxY1BPkBoJ8m-99pDB7a0ab7byYmAl5xamX1VOuAZTBo5-yXFV_g3WuMVsvp4u2k7uTi6oTSfQnLgvja3NAoj51Eh1tCdlMvMD_JqEauEH8kAZDlp7eu4zev0aiVFy4EEz6s/s1600/data.JPG" imageanchor="1" style="clear: left; display: inline !important; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbKha5UuzxxY1BPkBoJ8m-99pDB7a0ab7byYmAl5xamX1VOuAZTBo5-yXFV_g3WuMVsvp4u2k7uTi6oTSfQnLgvja3NAoj51Eh1tCdlMvMD_JqEauEH8kAZDlp7eu4zev0aiVFy4EEz6s/s1600/data.JPG" height="52" width="320" /></a> As you can see to the left <a href="http://www.jam-software.com/treesize_free/" target="_blank">TreeSizeFree</a> is showing that there are 20.6 GBs of data being stored in a folder called System Volume Information (SVI). By default this folder will be hidden so you must first show all hidden system files with either a CMD prompt or PS prompt this can be done quite easily.<br />
CMD<br />
<div style="text-align: center;">
<pre class="PoshConsole">dir D:\ /AH</pre>
</div>
PowerShell<br />
<div style="text-align: center;">
<pre class="PoshConsole">Get-Childitem -Force</pre>
</div>
<div class="separator" style="clear: both; text-align: left;">
Next type "vssadmin list shadowstorage" to find the loaction and size information of the SVI folder.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<pre class="PoshConsole" style="text-align: center;">vssadmin list shadowstorage</pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaD5t_W6vaJwCKfx93M0JQBf6yBbtoSEtceBL27Tr7EAfrs7lZMxTXgBwS1Xdc5qJzEVm_MiZY_T2EsJjoyNg0CFzHy0SRtALclnDU5pZbkKXVuo461nQva3rhyphenhyphen_KrfwaGeU1QQSRY3_g/s1600/data5.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaD5t_W6vaJwCKfx93M0JQBf6yBbtoSEtceBL27Tr7EAfrs7lZMxTXgBwS1Xdc5qJzEVm_MiZY_T2EsJjoyNg0CFzHy0SRtALclnDU5pZbkKXVuo461nQva3rhyphenhyphen_KrfwaGeU1QQSRY3_g/s1600/data5.JPG" height="124" width="640" /></a></div>
After you know the location of the SVI folder you can change the MaxSize of the System restore files<br />
<div style="text-align: center;">
<pre class="PoshConsole">vssadmin resize shadowstorage /For=D: /On=D: /MaxSize=5GB</pre>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjuXtH0BpX57tDbii-UusMeqgv3PimJf1KpkuAdhT_jrXzgDfbp0wg8AZZpT_h0qcn3m5NTLKyBQDw4QDMuXE_WnjvnFAunayYhHupHcfnaCncLLrSXN6ZJipibrf0OkP1EZA4IA3X978/s1600/data2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjuXtH0BpX57tDbii-UusMeqgv3PimJf1KpkuAdhT_jrXzgDfbp0wg8AZZpT_h0qcn3m5NTLKyBQDw4QDMuXE_WnjvnFAunayYhHupHcfnaCncLLrSXN6ZJipibrf0OkP1EZA4IA3X978/s1600/data2.JPG" height="204" width="640" /></a></div>
<div style="text-align: center;">
From 3% to 12%.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8WXprDsuNvntXHrZS4LhNpP0NYrM7to0PY7_DrsWOau4coDdy6DwGCudHIXLTdape4djNG4gILIceWk68qHjV1BfMBEDINlyD_2OwBApN853esEiX8aPJS7x1yLa_GlvICJsGeGWx0AM/s1600/data3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8WXprDsuNvntXHrZS4LhNpP0NYrM7to0PY7_DrsWOau4coDdy6DwGCudHIXLTdape4djNG4gILIceWk68qHjV1BfMBEDINlyD_2OwBApN853esEiX8aPJS7x1yLa_GlvICJsGeGWx0AM/s1600/data3.JPG" height="268" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkWWleFKHXrBKpHyHhui5SxKC4EjNA8qzEKfBtjZ7Twfb9g1LSNbhGM5mGwwDs9u9d5aFKepke_ucJTqq8XbdJ7Nuy-t74gCiVnTlmZ9bXMyw46jUASiQrQtrtfrnu-KAmVfA9wwCBXXs/s1600/data7.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkWWleFKHXrBKpHyHhui5SxKC4EjNA8qzEKfBtjZ7Twfb9g1LSNbhGM5mGwwDs9u9d5aFKepke_ucJTqq8XbdJ7Nuy-t74gCiVnTlmZ9bXMyw46jUASiQrQtrtfrnu-KAmVfA9wwCBXXs/s1600/data7.JPG" height="138" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
BatmanFlyshttp://www.blogger.com/profile/16544325027482911084noreply@blogger.comElk River, MN, USA45.322340654642929 -93.5852766036987345.319549654642927 -93.590319103698732 45.325131654642931 -93.580234103698729