OneScript Team Blog

A world of automation script samples based on IT Pros' real-world tasks
  • Here Comes the Update of Script Browser & Script Analyzer 1.1

    Update: Version 1.2 of the Script Browser is out.  Check out the announcement here: http://blogs.technet.com/b/onescript/archive/2014/05/11/what-s-new-in-script-browser-amp-script-analyzer-1-2.aspx

     

    The Script Browser for Windows PowerShell ISEhas received thousands of downloads since it was released a week ago. Based on your feedbacks, today we release the 1.1 update to respond to the highly needed features. The team is committed to making the Script Browser and Script Analyzer useful. Your feedback is very important to us.

    Download Script Browser & Script Analyzer 1.1 
    (If you have already installed the 1.0 version, you will get an update notification when you launch Windows PowerShell ISE.)

     

    1. Options to Turn on / Turn off Script Analyzer Rules

    You can either select to turn on or turn off the rules in the Settings window of Script Analyzer.

    image

    You can also suggest a new Script Analyzer rule or vote for others’ suggestions. Our team monitors the forum closely. Based on your suggestions and votes, we will provide the corresponding Script Analyzer rules in future updates. We are also looking into the capability for you to write your own Script Analyzer rules and plug into the Script Analyzer.

     

    2. Refined Script Analyzer Rules with Detailed Description

    Thanks to your feedback, we refined the Script Analyzer rules that were released in the version 1.0. We also fixed all rule issues that you reported. Each rule comes with a detailed description, good/bad examples, and supporting documents. Here are the 5 refined rules released in this update. We look forward to learning your feedback.

    Invoke-Expression use should be carefully considered

    Invoke-Expression is a powerful command; it’s useful under specific circumstances but can open the door for malicious code being injected. This command should be used judiciously.

    http://blogs.msdn.com/b/powershell/archive/2006/11/23/protecting-against-malicious-code-injection.aspx

    Cmdlet alias use should be avoided

    Powershell is a wonderfully efficient scripting language, allowing an administrator to accomplish a lot of work with little input or effort. However, we recommend you to use full Cmdlet names instead of alias' when writing scripts that will potentially need to be maintained over time, either by the original author or another Powershell scripter. Using Alias' may cause problems related to the following aspects:

    Readability, understandability and availability. Take the following Powershell command for an example:

    Ls | ? {$_.psiscontainer} | % {"{0}`t{1}" -f $_.name, $_.lastaccesstime}

    The above syntax is not very clear to the novice Powershell scripter, making it hard to read and understand.

    The same command with the full Cmdlet names is easier to read and understand.

    Get-ChildItem | Where-Object {$_.psiscontainer} | ForEach-Object {"{0}`t{1}" -f $_.name, $_.lastaccesstime

    Lastly, we can guarantee that an alias will exist in all environments.

    For more information, please see the linked Scripting Guy blog on this topic.

    http://blogs.technet.com/b/heyscriptingguy/archive/2012/04/21/when-you-should-use-powershell-aliases.aspx

    Empty catch blocks should be avoided

    Empty catch blocks are considered poor design decisions because if an error occurs in the try block, the error will be simply swallowed and not acted upon. Although this does not inherently lead to undesirable results, the chances are still out there. Therefore, empty catch blocks should be avoided if possible.

    Take the following code for an example:

    try
    {
            $SomeStuff = Get-SomeNonExistentStuff
    }
    catch
    {
    }

    If we execute this code in Powershell, no visible error messages will be presented alerting us to the fact that the call to Get-SomeNonExistentStuff fails.

    A possible solution:

    try
    {
             $SomeStuff = Get-SomeNonExistentStuff
    }
    catch
    {
            "Something happened calling Get-SomeNonExistentStuff"
    }

    For further insights:

    http://blogs.technet.com/b/heyscriptingguy/archive/2010/03/11/hey-scripting-guy-march-11-2010.aspx

    Positional arguments should be avoided

    Readability and clarity should be the goal of any script we expect to maintain over time. When calling a command that takes parameters, where possible consider using Named parameters as opposed to Positional parameters.

    Take the following command, calling an Azure Powershell cmdlet with 3 Positional parameters, for an example:

    Set-AzureAclConfig "10.0.0.0/8" 100 "MySiteConfig" -AddRule -ACL $AclObject -Action Permit

    If the reader of this command is not familiar with the set-AzureAclConfig cmdlet, they may not know what the first 3 parameters are.

    The same command called using Named parameters is easier to understand:

    Set-AzureAclConfig -RemoteSubnet "10.0.0.0/8" -Order 100 -Description "MySiteConfig" -AddRule -ACL $AclObject -Action Permit

    Additional reading:

    http://blogs.technet.com/b/heyscriptingguy/archive/2012/04/22/the-problem-with-powershell-positional-parameters.aspx

    Advanced Function names should follow standard verb-noun naming convention

    As introduced in Powershell 2.0, the ability to create functions that mimic Cmdlet behaviors is now available to scripters. Now that we as scripters have the ability to write functions that behave like Cmdlets, we should follow the consistent nature of Powershell and name our advance functions using the verb-noun nomenclature.

    Execute the Cmdlet below to get the full list of Powershell approved verbs.

    Get-Verb

    http://technet.microsoft.com/en-us/magazine/hh360993.aspx

     

    3. Issue Fixes

    • Fixed a locale issue “Input string was not in a correct format..” when Script Browser launches on locales that treat double/float as ‘##,####’. We are very grateful to MVP Niklas Akerlund for providing a workaround before we release the fix.
    • Fixed the issues (including the error 1001, and this bug report) when some users install the Script Browser.
    • Fixed the issues in Script Analyzer rules

     

    We sincerely suggest you give Script Browser a try (click here to download). If you love what you see in Script Browser, please recommend it to your friends and colleagues. If you encounter any problems or have any suggestions for us, please contact us at onescript@microsoft.com. Your precious opinions and comments are more than welcome.

  • Releasing Script Browser & Script Analyzer for Windows PowerShell ISE

    Here we'd like to share a piece of good news with everybody:  today we have a new app released – Script Browser for Windows PowerShell ISE.

    Script Browser for Windows PowerShell ISE was designed and developed in response to many IT Pros’ and MVPs’ feedback during the MVP Global Summit.  It puts nearly 10K script examples at IT Pros fingertips when they write scripts to automate their IT tasks. Users can search, learn, download and manage scripts from within their scripting environment - PowerShell ISE - with just a few button clicks.  It saves the time of switching back and forth between webpages and scripting environment, and also the trouble of countless download, copy, and paste operations.  Bundled with Script Browser is another neat feature called ‘Script Analyzer’ that automatically analyzes user’s script against 7 PowerShell best practices, and suggests improvements. Click here to get it now and share the announcements from the Windows PowerShell product team with your IT friends to make their work easier.

    Getting started with Script Browser 1.0


    It is very essential that an app satisfies users’ requirements. Therefore, feedback is of prime importance. For Script Browser, MVPs are one of the key sources where we get constructive feedback. When the Script Browser was demoed at the 2013 MVP Global Summit in November, 2014 Japan MVP Open Day, and a Product Group Interaction event, the MVP community proposed insightful improvements. For instance, MVPs suggested showing a script preview before users can decide to download the complete script package. MVPs also wanted to be able to search for script samples offline. These were great suggestions, and the team immediately added the features to the release. We have collected a pool of great ideas (e.g. MVPs also suggested that the Best Practice rules checking feature in Script Analyzer should be extensible). We are committed to continuously improving the app based on your feedback.

    We have an ambitious roadmap for Script Browser. For example, we plan to add more script repositories to the search scope. We are investigating integration with Bing Code Search. We are also trying to improve the extensibility of Script Analyzer rules. Some features, like script sample sharing and searching within an enterprise, are still in their infancy.

    We sincerely suggest you give Script Browser a try (click here to download). If you love what you see in Script Browser, please recommend it to your friends and colleagues. If you encounter any problems or have any suggestions for us, please contact us at onescript@microsoft.com.  Your precious opinions and comments are more than welcome.

     

     

    Acknowledgement

    Individually, we are one drop. Together, we are an ocean.  The v1 release of Script Browser is a big collaborative effort from many teams at Microsoft.   Mei Liang, Dan Ruder, Jialiang Ge, Bill Grauer, Allen Ding, Allen Li, Huajun Gu (MVP), Qi Fu from Microsoft CSS worked with the PowerShell Product Group represented by John Slack (PM), Frederic Francois, Samuel Li, Susan Mings, Vlad Carpenco, and Kriti Jindal, and the TechNet Script Center team represented by Bryant Hawthorne.  Pei Wang and Satoru Kitabata localized the app to 14 languages.  Microsoft GARAGE (Ben Gilbert is the PM) provides a perfect platform to demonstrate the app and internally crowd-source ideas and effort to make it better. Nearly 20 Microsoft Garage volunteers, and even their wifes, contributed test and localization to the release: Michael Janelle-Montcalm, Tiago Damasceno, Leland Holmquest's wife Geylan Holmquest, Petr Rybak, Igor Rybak, Piotr Walaszek, Cale Teeter's wife, Jose Cardenas Salazar, Aldo Mendoza Saucedo, Damian Leibaschoff (PSS), Markus Jansen, Tim Sullivan, Jorge Aleman Rodriguez, Ronald Aigner, Roberto Aldaba Mendez, Raffaele Limosani, Christian Kuhtz, Eric Chang (MSR), Erik Millan Jimenez, Tino Morenz.

  • Register the "OneCode & OneScript" session at MVP Global Summit November 2013

    The yearly Microsoft MVP Global Summit will lift its curtain on Nov 17th in Bellevue, WA.  This year, we have prepared three new apps and many new samples in response to MVPs’ feedbacks last year.  If you are attending this year’s Microsoft MVP Global Summit, you will have the privilege to kiss or bite their development team Smile 

    • Sample Browser Windows Phone app – with 6000+ MSDN code samples which will be at your fingertips anytime and anywhere.
    • Script Explorer for PowerShell ISE – with 8000+ script sample which will be at your fingertips when you are writing scripts in PowerShell ISE.
    • PowerShell checkin policy for TFS – automatically checks your PowerShell script code against best practices of PowerShell.

     

    Interested?  Please open your Schedule Builder for the MVP Summit 2013, and register for the event called “OneCode & OneScript” on Nov 17th.  We look forward to seeing you and learning your feedback.

     

    image

  • Microsoft All-In-One Script Framework Sample Release on March 25th

    Are you ready for another wave of script samples?  Here are 13 new script samples for Windows, SharePoint and IE.  As always, the script samples are based on frequently asked IT tasks that we collected in TechNet forums. 

     

    Windows and Windows 8 Script Samples

    image

    Script to refresh Windows 8

    Download: RefreshWindows8.zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/Script-to-refresh-Windows-eca1e59a

    Description: This PowerShell Script shows how to create custom refresh image of Windows 8.

    User Scenarios: Windows Refresh gives you a quick and easy way to start with a clean slate while also maintaining your apps, data, Windows settings, and user profile.

     

    How to Delete the "Windows.old" Folder in Windows 8 (PowerShell)

    Download: DeleteWindowsOld.zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/How-to-Delete-the-912d772b

    Description: This PowerShell script shows how to delete the "Windows.old" Folder in Windows 8.

    User Scenarios: When you performed a refresh of Windows 8, upgrade to Windows 8 or a custom install of Windows 8 without formatting the drive for a clean stall and selected to install Windows 8 on the same partition of the previous Windows installation, then you may have a "C:\Windows.old" folder left over in your new installation. It contains a copy of the previous Windows 8 installation, and can be quite large in size. If users are sure that they don't need this folder any more, they can try to use a script to delete the folder.

     

    Script to display the deleted objects in Active Directory (PowerShell)

    Download: DisplayDeletedADObjects.zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/Script-to-display-the-c995a5f6

    Description: This PowerShell script sample can display the deleted objects from the Active Directory.

    User Scenarios: Accidental deletion of Active Directory objects is a common occurrence for users of ADDS and ADLDS. This script can display the deleted objects from the Active Directory Recycle Bin.

     

    Script to add an item to Startup in Windows 8 (VBScript)

    Download: AddItemToStartup (VBScript).zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/Script-to-add-an-item-to-2b99b14f 

    image

    Description: This VBScript sample shows how to add an item to the Startup in Windows 8.

    User Scenarios: Sometimes, users want programs to start when your system starts. Usually, you can add items to the startup folder. In Windows 8, adding items to Startup requires additional work. This script can resolve this problem.

     

    Check if disk partitions are 4KB aligned using PowerShell

    Download: Check4kAligned.zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/Check-if-disk-partitions-bb5b3eca

    Description: This script can be used to check if users' disk partitions are right 4kb alignment. Over the next few years, the data storage industry will be transitioning the physical format of hard disk drives from 512-byte sectors to 4,096-byte sectors (also known as 4K or 4KB sectors). This transition is driven by several factors. These include increases in storage density and reliability.  Many customers need to know if their disk partitions have non-4kb alignment issue which will cause incompatibility issues with existing software (including operating systems and applications).

    User Scenarios: We can use Test-OSC4kAligned function to check if user’s disk partitions are right 4kb alignment.

     

    Script to fix issues of Event ID 4107 and Event ID 11 (PowerShell)

    Download: BulkFixIssuesOfEventID4107AndEventID11.zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/Script-to-fix-issues-of-a5f6f91a

    Description: This sample can help the enterprise administrator to bulk fix the issue “Event ID 4107 or Event ID 11 is logged in the Application log in Windows and in Windows Server “ on all the client computers which have these issues in the enterprise’s  domain.

    User Scenarios: Event ID 4107 and Event ID 11 error occurs because the Microsoft Certificate Trust List Publisher certificate expired. A copy of the CTL with an expired signing certificate exists in the CryptnetUrlCache folder. To bulk resolve these issues, you can use this script to list all the expired certificates in the specific computer and remove all the files in the CryptnetUrlCache folder.

     

    Script to list the cluster servers (PowerShell)

    Download: ExportServersInCluster.zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/Script-to-list-the-cluster-cbab4d4b

    Description: This script will demo how to list the servers in one or more Windows clusters.

    User Scenarios: Sometimes, IT pro need to list all servers in the specified cluster(s).This script is to accomplish it.

     

    Script to disable "turn off this device to save power" for NIC Power Management

    Download: DisableNetworkAdapterPnPCapabilities(VBS).zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/Insert-pictures-in-a-eb23b3a9

    Description: This VBS Script illustrates how to disable "turn off this device to save power" feature in Power Management.

    User Scenarios: Many users want to disable the option in network device called: Allow the computer turn off this device to save power. Now, this script can help users to disable "turn off this device to save power" feature in Power Management of all physical network adapters.

     

    SharePoint Script Samples

    image

     

    SPProfileDump

    Download: SPProfileDump.zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/SPProfileDump-77f87a72

    Description: This script enumerates through the user profile manager for a given site collection and would extract information about all profiles from the profile store.

    User Scenarios: In SharePoint, we come across issues with profiles not being consistently updated with property values after an import operation. There could be numerous reasons for this; albeit a change in the import connection or the inability to reach and fetch information from a designated Directory server. Besides, the Central Admin UI doesn’t present a holistic view of all user profiles; neither is there an easier way to navigate through hundreds of profiles within the UI.

    SPProfileDump would extract all profile information to a comma delimited (SPProfileDump.CSV) file. Additionally, it would also create a SPProfileProperties.TXT file that would contain the very basics of each profile property. You can open the SPProfileDump.CSV file in a tool like Excel and use filtering to view data the way you want. For example, find how many profiles have come through a specific OU or per say, how many users do not have a valid PictureURL.

     

    How to remove users from a site that have a specific permission level

    Download: RemoveSPsiteUsers.zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/How-to-remove-users-from-a-d792858b

    Description: This PowerShell script shows how to remove users from a site that have a specified permission level.

    User Scenarios: You cannot remove users from a site by using the UI and it is difficult to find all users that have a specific permission level.

     

    Complete the Reporting Services with SharePoint Integration configuration

    Download: IntegrateSSRSToSharePoint.zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/Complete-the-Reporting-0971816b

    Description: This Windows PowerShell script achieves the same function as we to complete configure the Reporting Services integrate to SharePoint in SharePoint Central Administration. This script applies to SQL Server Reporting Services 2008 R2 or SQL Server Reporting Services 2008 integrate to SharePoint 2010.

    User Scenarios: When we need to configure SQL Server Reporting Services in SharePoint integrated mode, after installed and configured both SQL Server Reporting Services side and SharePoint side, in traditional way, we need to bind the report server URL and set authentication type in the SharePoint Central Administration.  Actually, we can also easily set these steps by using script. It is suitable for bellowing two conditions:

    • Never integrated any SQL Server Reporting Services to this SharePoint.
    • Had ever integrated SQL Server Reporting Services to this SharePoint, need to integrate one new SQL Server Reporting Services to this SharePoint.  

     

    Internet Explorer Script Samples

    image

    Setting Tab Process Growth for Internet Explorer (PowerShell)

    Download: SettingIETabProcessGrowth(PowerShell).zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/Setting-Tab-Process-Growth-5e52fe62

    Description: This sample can help you to operate the “TabProcGrowth” registry entry to set Tab Process Growth(Sets the rate at which IE creates New Tab processes) for Internet Explorer 8 or later.  It shows how to get and set Tab Process Growth setting for the Internet Explorer installed on your computer by using PowerShell script.

    User Scenarios: If you have been using IE7, you are probably used to all your tabs opening under the same iexplore.exe process. The only exception is if you are on a Windows Vista machine and you are moving from Protected to Unprotected mode. Internet Explorer 8 or later had a big makeover in this area. You will now notice that new tabs typically open in a new process.  By default,  IE8 will start with two instances of iexplore.exe (one for the Frame, one for the tab) and grows the number of tab processes as needed based on the amount of available RAM, the number of tabs, the integrity levels for tabs, and the number of distinct IE sessions .

     

    Script to remove Internet Explorer in Windows 7 (PowerShell)

    Download: RemoveInternetExplorer (PowerShell).zip
    Details: http://gallery.technet.microsoft.com/scriptcenter/Script-to-remove-Internet-e8327b13 

    Description: This PowerShell script demo shows how to remove Internet Explorer in Windows 7.

    User Scenarios: In some situations, customers need to uninstall Internet Explorer 9 to fix crash issue, but they cannot manually uninstall Internet Explorer successfully sometimes.

  • Request free Script Samples from Microsoft and the Community

    Microsoft All-In-One Script Framework is providing a script sample request function.  This is a proactive way for our IT community to obtain script samples for certain IT tasks directly from Microsoft.

    IT Pros are encouraged to submit script sample requests dealing with any Microsoft products and any scripting languages to the TechNet Script Request Forum (http://gallery.technet.microsoft.com/scriptcenter/site/requests).  At the same time, IT Pros can vote for newly submitted or existing script sample topics. Here’s the exciting part!  In this active IT community, your script request may be quickly resolved by the strong MVPs and other community members.  Microsoft engineers will also pick the requests with high number of votes and provide the script samples, free of charge.
     

     

    We have a few suggestions for you in order that your request can be served at the earliest.

    1. Before you open a new request, we suggest that you quickly search among existing script requests and vote them up.  

    image

     

    In addition, the TechNet Script Center has provided over 7000 script samples.  A quick search in this big script repository may give you surprises.

     

    2. Please be specific about what the script sample is going to demonstrate.  Here is an example of a good script request: 

    "I want a script sample that demonstrates how to change the background color of the Windows 8 start screen”.

    General script requests such as “I want more script samples for Windows 8” will require more back-and-forth clarifications before our engineer can understand the actual script requirement and start to produce scripts.

    3. If possible, please provide some proof that this script is needed by many IT Pros.  The team prioritizes to produce scripts that can benefit more people.  You may share the business impact of the script, or share the forum threads that are discussing the topic.  For example,

    "I want a script sample that demonstrates how to change the background color of the Windows 8 start screen.  Many people are asking how to do this in the TechNet forum: http://social.technet.microsoft.com/Forums/en-US/w8itprogeneral/thread/a5699003-9233-4ddc-96fc-e3c1e4a2a81b”.

     

    How are you prioritizing the script requests?

    The higher the script request is voted, the higher priority will the team offer to handle, write and publish the script sample.

    Besides the Script Request Service, Microsoft All-In-One Script Framework is also featured by creating scripts for frequently asked IT tasks in TechNet forums and Microsoft support calls.  The team prioritizes to handle your script requests over the script topics collected from forums, in order to give you a better and faster service experience.

    Meanwhile, with the launch of many new Microsoft products such as Windows 8, Windows Server 2012, Office 2013, etc, we prioritize to handle requests for these new products.

     

    What happens after I submit a script request?

    Microsoft All-In-One Script Framework Team is monitoring the script request forum everyday.  Meanwhile, we have a very active and strong IT community in TechNet.  MVPs and community members may share their scripts to help you.

    If the script request gets more than 2 votes, and no script sample is posted to resolve the script request, Microsoft All-In-One Script Framework engineers will start to handle the request.  They will first clarify the request with you when necessary, and research to see if any existing scripts can answer your requirement.  If none of the existing scripts helps, the team will submit the script topic to the field experts at Microsoft and triage the script topic:

    • Is the script going to demonstrate recommended practices from Microsoft?  (We will surely not demonstrate any hacking solutions Smile)
    • Can the request be resolved with one of two lines of code?  If the request can be resolved with a few lines of code, we will post the lines of code directly in your script request, instead of creating a complete, downloadable script sample package.
    • Does the script topic involve any 3rd party solutions?  If the solution requires the use of 3rd party components, please understand that it will be hard for us to make the demonstration.
    • Is the script topic too sophisticated and more like a product feature request?  If the script topic requires more than 1000 lines of scripts, we will consider it as a product feature request, and route it to the relevant product team for future consideration.

    The field experts are Microsoft Escalation Engineers and the Product Group members.  If the script request is declined by the field experts, we will share the reason of the decision, and expect your understanding.

    Next, Microsoft All-In-One Script Framework engineers will start to produce the script sample.  We will not keep you waiting for the complete script.  You will receive “code snippets” from our engineers for your instant needs.  The script sample will be tested by our testers, and reviewed by the field experts before publishing.

    Throughout the process, the Microsoft All-In-One Script Framework engineers will keep you updated about the request status every few days.  If you have any feedback, please email onescript@microsoft.com.

     

     

    Acknowledgement

    By taking this opportunity, the All-In-One Script Framework team wants to thank Don Totten and his TechNet Script Repository team for creating the Script Request Forum, and making it possible for us to launch the Script Request Service program. 

     

   Script of the Day