Feed aggregator

Server 2003 DC Authentication

The Official Scripting Guys Forum! - 7 hours 23 min ago

Hi Experts,


I have 2 sites in a domain (Site - A and Site - B), 2 DCs are there per site. When users are logging in Site - A :

1) How would i understand which user gets authenticated by which DC ?

2) Is it possible that i can configure for 100 users to be authenticated by DC1 and rest users by DC2 ?

Categories: PowerShell

Run a .VBS file with admin access

The Official Scripting Guys Forum! - 11 hours 4 min ago

Hi

  Iam having one .vbs file for installing print drivers in all user machines. But its required for admin access. Can you please tell me how to add admin username and password within the script file itself for running with admin access..

Set objNetwork = CreateObject("Wscript.Network")

' Retrieve Distinguished Name (DN) of current user and computer.
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
strComputerDN = objSysInfo.ComputerName

' Assign printer according to user group membership.
' Only assign one printer.
' You could use strComputerDN to test computer object group membership.
Set objGroup1 = GetObject("LDAP://cn=Color Printing,ou=security,ou=groups,ou=HQ,dc=er,dc=int")
If (objGroup1.IsMember("LDAP://" & strUserDN) = True) Then
objNetwork.AddWindowsPrinterConnection "\\10.10.1.66\FollowMe_Color"
objNetwork.SetDefaultPrinter "\\10.10.1.66\FollowMe_Color"
Else
Set objGroup2 = GetObject("LDAP://cn=Black White Printing,ou=security,ou=groups,ou=HQ,dc=er,dc=int")
If (objGroup2.IsMember("LDAP://" & strUserDN) = True) Then
objNetwork.AddWindowsPrinterConnection "\\10.10.1.66\FollowMe_BW"
objNetwork.SetDefaultPrinter "\\10.10.1.66\FollowMe_BW"
Else
End If
En

Categories: PowerShell

List of files\folders where Administrator doesn't have Full Access

The Official Scripting Guys Forum! - 13 hours 4 min ago

Hi Guys,

I need to get list of files and folders on C:\ where Administrator user doesn't have 'Full Access'. Is it possible using PowerShell. I have looked into this:

http://rightbrainleft.net/2010/06/using-powershell-to-inspect-folder-permissions/

which uses Get-Acl command, but I m not able to do it the way I need.

I would really appreciate any help in this regard.


Regards, David Johnson


Categories: PowerShell

Weekend Scripter: Scripting Wife Creates Her Ideal TechEd 2012 Schedule

Hey, Scripting Guy! Blog - 19 hours 16 min ago

Summary: The Scripting Wife plays WhatIf and creates her ideal Microsoft TechEd 2012 schedule.

Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife likes to use WhatIf in her daily musings. She has also been hearing from a lot of people who are going to Microsoft TechEd for the first time. Last year was her first TechEd experience, and she hopes to improve her takeaways this year. When asked what her schedule would look like if she was not working at the Scripting Guys booth, she sat down with the catalog and came up with the following schedule. I will warn you that Teresa is very flexible, so although this would be her proposed schedule on paper, it by no means indicates what will or would actually occur.

For example, she may have chosen a session to attend based on the content, but then she may meet a really interesting person after we arrive who is presenting at the same time as a session she had already written down as attending. The next thing I know, I may be getting an email from her on my Windows 7 smartphone that says, “My plans have changed and I am going to attend a different session than is on my schedule. I met this really cool person and I want to go to his session.” In truth, the chances are good that if you want to talk to the Scripting Wife, come by the Scripting Guys booth during nearly any hour that the Connect Zone is open, and she will probably be there. She loves talking to people who want to learn Windows PowerShell, but do not know where or how to begin.

Now without further ado, here is the Scripting Wife’s schedule for Microsoft TechEd 2012.

Hello everyone! Scripting Wife is here. I need to say a couple of things so you can follow what I have written and chosen. By the way do you know how hard it is to choose between Don Jones and Mark Minasi? Both are dear friends and both are excellent speakers.

First, I am going to list the three items that I will work on while I am not attending a session. There is one demo in The Learning Center (TLC) and there are two hands-on labs.

Demo in S. Hall A:

Windows Server 2012 Server Manager and PowerShell | WSV07-TLC

Whatever the size of your organization, you want to maximize IT operational cost efficiency. Windows Server 2012 offers excellent total cost of ownership as an integrated platform with comprehensive, multiserver manageability. It delivers capabilities to manage many servers and the devices connecting them—whether they are physical or virtual, and whether they are on-premises or off. Specifically, Windows Server 2012 provides new multi-machine management capabilities, automation, improved compliance with industry management technology standards, and experiences which are unified across physical and virtual platforms. Visit the Windows Server 2012 Management booth to hear from experts about all the great new features.

Lab in S. Hall B:

What's New in Windows PowerShell 3.0 | WSV11-HOL

This lab gets you up and running with the all-new Server Manager in Windows Server 2012. Topics covered include: deploying roles and features to a remote server, configuring a role on a remote server, monitoring remote servers, and troubleshooting a remote server. You will leave this lab with a solid grasp of how to use the new Server Manager to quickly and easily perform common server management tasks, local and remote.

Lab in S. Hall B:

Introduction to Windows PowerShell Fundamentals | 3.0 WSV12-HOL

This lab gets you up and running with Windows PowerShell, Microsoft's latest shell environment and scripting language. Topics covered include: file system navigation, help and discovery features, PowerShell scripts, working with WMI, working with the system registry, and working with Active Directory. You will leave this lab with a solid grasp of how to use PowerShell to quickly and easily perform common IT management tasks, and have a solid foundation to learn advanced PowerShell topics.

And now for my session schedule...

Monday, June 11

9:00 AM - 10:30 AM

Keynote Session

11:30 AM - 1:15 PM

Lunch

1:15 PM - 2:30 PM

The 12 Reasons to Love Microsoft SQL Server 2012 | DBI202

Speakers: Dandy Weyn, Thomas LaRock

In this demo-only session, discover 12 good reasons to love SQL Server 2012. Learn about AlwaysOn, ColumnStore Indexing, Data Quality Services, Transact-SQL Enhancements, Power View, SQL Server Data Tools, and so much more in a very demo-driven session. By the end of the session you will understand the key features and improvements in SQL Server 2012, and how they work together.

3:00 PM - 4:15 PM

PowerShell Remoting in Depth | WCL403

Speaker: Don Jones

Remoting is a foundation feature in Windows PowerShell, and is poised to become one of the most      important protocols on your network, especially for remote client management and support. Do you know how it works? Can your troubleshoot it? Can you configure it in a variety of scenarios to meet your organization's needs for security and operations? Don Jones, PowerShell author and MVP, walks you through the nitty-gritty details of Remoting, showing examples for a variety of scenarios and covering its troubleshooting features in great detail. 

4:45 PM - 6:00 PM

Windows PowerShell Crash Course | WSV321

Speakers: Don Jones, Jeffrey Snover

Windows PowerShell 3.0 is here, and it is delivering on Microsoft's promise to make nearly everything in Windows manageable from the command-line. Are you finally going to learn the shell, or learn to say, "Would you like fries with that?" instead? Join PowerShell author, columnist, trainer, and MVP Don Jones (one of the world's most well-known PowerShell experts) in a crash course that shows you how to use the shell's key features. No scripting experience needed—you'll use the shell as it is meant to be used to accomplish real administrative tasks with just a few commands. Also, learn how the shell can teach you how to use itself, setting you up for success with the new wave of Microsoft and third-party enterprise products.

6:00 PM - 9:00 PM

TechExpo Welcome Reception

Tuesday June 12

10:15 AM - 11:30 AM

Inside Windows Server 2012 Multi-Server Management Capabilities | WSV306

Speakers: Erin Chapple, Jeffrey Snover

Windows Server 2012 will offer excellent total cost of ownership as an integrated platform with comprehensive, multicomputer manageability. Two areas in which Windows Server 2012 improves multicomputer management are Server Manager and Windows PowerShell 3.0. Server Manager in Windows Server 2012 helps you efficiently deploy and manage roles and features on the local server, on remote servers, and on both online and offline virtual hard disks. It also provides a multiserver experience where you can centralize your Windows Server management in a single view, and streamlined your server configuration and deployment from the same window. Windows PowerShell 3.0 provides an extensive platform to help you manage server roles and automate management tasks. With access to over 2300 cmdlets (a tenfold increase from the previous version), Windows PowerShell 3.0 offers comprehensive management across your datacenter. This session overviews these subjects in detail and prepares you for enhancing your management capability.

11:30 AM - 1:30 PM

Lunch

1:30 PM - 2:45 PM

Legal Structures of User Groups | BOF05-ITP

Room S329

Should your group incorporate or apply for non-profit status? What are the benefits and pitfalls of creating legal structures for IT Professional groups? Do you charge membership fees to the members to pay the legal obligations?

3:15 PM - 4:30 PM

Standards Support and Interoperability in Windows Server 2012: Storage, Networking, and Management |  WSV308

Speakers: Gene Chellis, Jeffrey Snover, See-Mong Tan, Wojtek Kozaczynski

Windows has always implemented formal and industry standards but the Windows Server 2012 mission to be a Cloud OS required us to take this to a new level with investments in storage, networking and management standards. For example, in Windows Server 2012 the WSMAN standard is now the primary management protocol, with DCOM provided for backwards compatibility. Clearly this is not your father’s Windows Server. This 200-level session covers formal “de jure” standards including management (such as SMI-S, WSMAN and CIM), networking (such as IPv6, IPSec, DCB, DCTCP, NVGRE, ECMA Power standards and RDMA), and storage (such as NFS and iSCSI). We describe the technology, how Windows supports it, what benefits it brings, and what you need to change/do in order to get those benefits. We also discuss “de facto” standards such as VSS and SMB and describe how Microsoft enables and promotes interoperability using conferences, protocol documentation, plugfests and more to make Windows Server 2012 the most interoperable operating system on the planet. IT pros should come learn how Windows Server 2012 simplifies the tasks of architecting and running systems and how you should update your equipment purchasing guidelines. Developers and Partners should come to learn about new opportunities and preferred mechanisms to interoperate with Windows Server 2012.

5:00 PM - 6:15 PM

Extending Applications to Everywhere! Your Guide to Securing RDS RemoteApps for the Internet | WSV311

Speaker: Greg Shields

Your job as IT administrator is all about applications and data. You need to protect your users' data, and you need to ensure access to it via applications. But today's workforce requires us to make our applications available from everywhere. Creating your own Internet-based cloud infrastructure for corporate applications is quickly becoming a need for every environment, both large and small. You can create this today for very little cost using Microsoft Remote Desktop Services. RDS Guru and Microsoft MVP Greg Shields has been working with Terminal Services since its introduction in Windows NT 4.0 Terminal Services Edition, and in this deep dive session he presents the step-by-step approach to building a cloud-based remote applications infrastructure with enough industrial-grade security that even the most secure of networks will allow it. RDS has for too long been relegated to the sidelines. Attend this session and make secure, scalable, and inexpensive cloud applications a reality for your company.

6:15 PM - 9:00 PM

Community Night. There will be a Scripting Guys area!

9:00 PM - 1:00 AM

Jam Sessions

Wednesday June 13

8:30 AM - 9:45 AM

Group Policy Reporting and Analysis with Windows PowerShell | WSV415

Speakers: Jeffery Hicks, Jeremy Moskowitz

In this session led by PowerShell MVP Jeffery Hicks and Group Policy MVP Jeremy Moskowitz, we discuss techniques for analyzing Group Policy objects to identify potential problems. We look at ways to identify Group Policy settings using PowerShell scripts and third-party tools.

11:30 AM - 1:30 PM

Lunch

1:30 PM - 2:45 PM

Turn PowerShell Commands into Reusable CLI and GUI Tools | WCL404

Speakers: Don Jones

Say you have written an incredible PowerShell command or script. How do you leverage that as a tool across your entire organization? Learn to turn those commands and scripts into tools that can be safely used by your less-technical colleagues, or even end users! PowerShell MVP and author Don Jones demonstrates a variety of approaches, including cmdlet-like command-line tools all the way up to fully-distributable GUI tools that you can build yourself!

3:15 PM - 4:30 PM

Windows PowerShell Best Practices | BOF11-ITP

Led by Windows PowerShell MVP, Don Jones, and Microsoft Scripting, Guy Ed Wilson

All of Microsoft's current operating systems and most of their server-based products have deep PowerShell integration, and that trend will continue. Same goes for the hardware and software vendors out there, large and small. You need to be on this train! You need to script! How do you know if you are doing it right? What does that even mean? Can you save time by using tried and tested techniques?

5:00 PM - 6:15 PM

Advanced Automation Using Windows PowerShell 3.0 | WSV414

Speakers: Hemant Mahawar, Travis Jones

This session showcases the improvements to Windows PowerShell introduced in Windows Server 2012. Demos for this talk include how IT administrators can create cmdlet functionality without the need for programming skills, PowerShell Remoting, Jobs, Modules, Debugging, and Constrained Endpoints, among others.

Thursday, June 14

8:30 AM - 9:45 AM

How to Tell Your Manager You Need Quotas on Your Mailboxes | EXL203

Speaker: Bhargav Shukla

As systems offer bigger and bigger mailboxes and Microsoft has published whitepapers on large mailbox vision, it is important to understand the infrastructure to support such designs, what your company desires, and what the cost and operational impacts are. This session provides intelligent discussion about factors involved and cost benefits, to help you drive your infrastructure towards better manageability and stability.

10:15 AM - 11:30 AM

Application Monitoring with Microsoft System Center Operations Manager 2012 | MGT302

Speakers: Aakash Mandhar, Daniele Muscetta

In this session we provide a summary of the application monitoring capabilities enabled through System Center 2012 Operations Manager against Microsoft .NET and Java applications, covering the platforms and supported configurations. See how System Center 2012 Operations Manager can provide critical availability, performance, and reliability information without requiring any custom instrumentation to the code or custom management packs.

11:30 AM - 1:00 PM

Lunch

7:30 PM - 12:00 AM

Closing Party

That is my WhatIf schedule, and I think it has a nice balance to it. Hopefully, you will find it useful. Keep in mind, Microsoft TechEd 2012 is a huge event, and the Orlando Expo Center (according to the Scripting Guy) is like three miles long. So you should definitely bring comfortable walking shoes and also wear clothes that are comfortable. I look forward to seeing you if you get to come to TechEd 2012 in Orlando. There are still some slots available, so there is still time to register.

~Scripting Wife

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Categories: PowerShell

Batch File to invoke few SQL Server Scripts and take the command prompt to a specific file (involving Find Functions)

The Official Scripting Guys Forum! - May 18, 2012 - 9:52pm

Hi Scripting Gurus!!

I have a requirement to create a batch file(.bat) which has to do the following

1- Ask the user to input the hostname and SID (here the system is an SQL server with SID( a 3 letter identifier in a data base) and then replace them with  place holders in the whole script file, even in execution it should substitute and eecute automatically

Eg:- start C:\<<source hostname>>\J2SDK_1.4.2\javac

2- execute few SQL server scripts, the main batch file waiting for each sql script to execute(echo the current running script) and the moving to next

    Here I tested with single batch file containing only the line,  SQLCMD -S <hostname> U<user> P<password> @@hostname and it displays perfectly the host name after authenticating in the SQL server(I did to test basic), but when I include above in showDBhostname.sql and call in main batch file  as

SQLCMD -S <hostname> U<user> P<password> -q showDBhostname.sql or

START SQLCMD -S <hostname> U<user> P<password> -q showDBhostname.sql , I get SQLCMD command not found

CAn any one help me how to acheive this and my main requirement is like this

Search for Javac exe location and take the command prompt automatically to there and execute Javac <Javafilename> 

SQLCMD -S <hostname> U<user> P<password> -q dboffline.sql

wit until finish(echo the status of currently running sql script in main batch file)

SQLCMD -S <hostname> U<user> P<password> -q dbchangeMaster.sql

wait until finish(echo the status of currently running sql script in main batch file)

SQLCMD -S <hostname> U<user> P<password> -q EXECBacKUP.sql

wait until finish(echo the status of currently running sql script in main batch file)

SQLCMD -S <hostname> U<user> P<password> -q restorebackup.sql

I am ok If anyone suggests a better approach , even using VBScript etc..

Many Thanks  in Advance

Munsar

Categories: PowerShell

I need help modifying a script

The Official Scripting Guys Forum! - May 18, 2012 - 9:21pm

I did my research and I couldn't figure this out.

I have a drop-down menu that has a list of categories. When you select an option, I want text to display.  I think I gotta use the onChange event and javascript but I get lost when I try to figure out the option value.

The follow is the code that makes the drop-down menu:

<select name="cat">
                                <option value="">{$lang52}</option>
                                {insert name=get_categories assign=cat}
                                {section name=i loop=$cat}
                                <option value="{$cat[i].CATID}">{$cat[i].name|stripslashes}</option>
                                {/section}

I've read basic tutorials about this but they all used basic drop-down menus and this one seems more advance. I know the CATID is coming from the sql database. Don't worry about $lang52, that just puts the word Categories beside the menu.

I hope this was enough information to get started.

Thank you.

Categories: PowerShell

Running Powershell Script as a SQL Scheduled Job - Need to Send Error back to SQL

The Official Scripting Guys Forum! - May 18, 2012 - 7:27pm

I have written the following script to watch a folder for files.  If more than X files are in the folder it means my process is not running and I need to take action. 

I am running this powershell script as a SQL Scheduled Task.

My question is, how do I send an error back to SQL and fail the Job?

I can send the message back to appear in the Job History, but I can't seem to raise the error.

 

#----- define Source Folder where files are located
$SourceFolder = ("\\"+ (get-content env:computername) + "\SHARE$\IMPORT\")


$Count = [System.IO.Directory]::GetFiles($SourceFolder).Length;
if ($Count -gt 2)
    {
    $message = " files in "+$SourceFolder +" , bad news."
    Write-Output $Count $message

    }  
else
    {
     $message = " files in the directory, all ok."
     Write-Output $Count $message

     }

Categories: PowerShell

Not able to retrieve Hyper-V Cluster GUID

The Official Scripting Guys Forum! - May 18, 2012 - 5:11pm

Hi,

My goal is to catch a UniqueIdent for every part of my Hyper-V Cluster ( Cluster, Node, VM) ; so , I will be able to retrieve them in my records,
even if their names change for example.

No problem to get the VM GUID with :
Get-WMIObject -Class Msvm_ComputerSystem -Namespace "root\virtualization"

Let's talk about  the node :
I'm trying to retrieve the GUID of a cluster node (info similar to VM GUID); so, I run the following command :
Get-WmiObject -Namespace "root\MSCluster" -class "MSCluster_Node"  which gives me this result:

__GENUS                     : 2

__CLASS                     : MSCluster_Node

__SUPERCLASS                : CIM_UnitaryComputerSystem

__DYNASTY                   : CIM_ManagedSystemElement

__RELPATH                   : MSCluster_Node.Name="H1"

__PROPERTY_COUNT            : 30

__DERIVATION                : {CIM_UnitaryComputerSystem, CIM_ComputerSystem, CIM_System, CIM_LogicalElement...}

__SERVER                    : H1

__NAMESPACE                 : root\MSCluster

__PATH                      : \\H1\root\MSCluster:MSCluster_Node.Name="H1"

BuildNumber                 : 7601

Caption                     :

Characteristics             : 0

CreationClassName           :

CSDVersion                  : Service Pack 1

Dedicated                   :

Description                 :

Flags                       : 0

IdentifyingDescriptions     :

InitialLoadInfo             :

InstallDate                 :

LastLoadInfo                :

MajorVersion                : 6

MinorVersion                : 1

Name                        : H1

NameFormat                  :

NodeHighestVersion          : 400817

NodeInstanceID              : 00000000-0000-0000-0000-000000000001

NodeLowestVersion           : 400817

OtherIdentifyingInfo        :

PowerManagementCapabilities :

PowerManagementSupported    :

PowerState                  :

PrimaryOwnerContact         :

PrimaryOwnerName            :

PrivateProperties           : System.Management.ManagementBaseObject

ResetCapability             :

Roles                       :

State                       : 0

Status                      :

__GENUS                     : 2

__CLASS                     : MSCluster_Node

__SUPERCLASS                : CIM_UnitaryComputerSystem

__DYNASTY                   : CIM_ManagedSystemElement

__RELPATH                   : MSCluster_Node.Name="H2"

__PROPERTY_COUNT            : 30

__DERIVATION                : {CIM_UnitaryComputerSystem, CIM_ComputerSystem, CIM_System, CIM_LogicalElement...}

__SERVER                    : H1

__NAMESPACE                 : root\MSCluster

__PATH                      : \\H1\root\MSCluster:MSCluster_Node.Name="H2"

BuildNumber                 : 7601

Caption                     :

Characteristics             : 0

CreationClassName           :

CSDVersion                  : Service Pack 1

Dedicated                   :

Description                 :

Flags                       : 0

IdentifyingDescriptions     :

InitialLoadInfo             :

InstallDate                 :

LastLoadInfo                :

MajorVersion                : 6

MinorVersion                : 1

Name                        : H2

NameFormat                  :

NodeHighestVersion          : 400817

NodeInstanceID              : 00000000-0000-0000-0000-000000000002

NodeLowestVersion           : 400817

OtherIdentifyingInfo        :

PowerManagementCapabilities :

PowerManagementSupported    :

PowerState                  :

PrimaryOwnerContact         :

PrimaryOwnerName            :

PrivateProperties           : System.Management.ManagementBaseObject

ResetCapability             :

Roles                       :

State                       : 0

Status                      :

I'm  disappointed cos I hope to get for Name and NameFormat something else buult with an heuristic as described in MSCLUSTER_Node class description :

Name

Data type: string

Access type: Read-only

Defines the label by which the node is known.

Inherited from CIM_UnitaryComputerSystem.

NameFormat
Data type: string
Access type: Read-only

Identifies how the node Name property is generated, using a heuristic. This property identifies how the system name was generated by using the subclass heuristic. The heuristic is outlined in the CIM V2 Common Model specification and assumes that the documented rules are traversed to determine and assign a name. The NameFormat values list defines the precedence order for assigning the system name with several rules mapping to the same value.

Inherited from CIM_UnitaryComputerSystem.

......

Did I misunderstand something ?

Is this node GUID located elsewhere in the WMI space ?

BTW, where may I find same GUID for the cluster itself ?

Thanks for help.

Regards,

J.P. Ribeauville

Categories: PowerShell

Top mailboxes report with get-user information

The Official Scripting Guys Forum! - May 18, 2012 - 4:01pm

I have an html report that is part of another weekly report I use on my Exchange environment.  The report in question shows me the top largest mailboxes, I would like to add some information from the get-user cmdlet to this report.  I realize there are other ways to do this, I have created a one-liner report that gives me the info I want but I can't figure out how to pull this information into this paticular report/script.  Using this report will help me wiht others that are similar and give me the data that I'm looking for.

Here is my report, I would like to add get-user information to this report.

# Script that reports on top 150 mailbox sizes - dot sourced in weekly-exchange.ps1 # # Main #HTML Output "<html>" "<body>" "<b><font size=5>E-mail Statistics Report</font></b>" #Todays date goes here" "<hr>" "<table>" "<tr>" "<td><font size=3><b><i>Top 150 Mailboxes</i></b></font></td><td></td>" "</tr>" "<tr>" "<td><hr>Mailbox<hr></td><td>|</td><td align=center><hr>Size<hr></td><td>|</td><td align=center><hr>Deleted Items<hr></td><td>|</td><td align=center><hr>Quota<hr></td><td>|</td><td align=center><hr>Office<hr></td>" "</tr>" foreach ($mailbox in get-mailboxserver | get-mailboxstatistics | sort totalitemsize -descending | select -first 150){ $mailboxsize = $mailbox.TotalItemSize.Value.ToMB() $mbname = $mailbox.displayname $mbquota = $mailbox.storagelimitstatus $mbdeleted = $mailbox.TotalDeletedItemSize.Value.ToMB() "<tr>" "<td>$mbname</td><td>|</td><td>$mailboxsize MB</td><td>|</td><td align=center>$mbdeleted MB</td><td>|</td><td>$mbquota</td><td>|</td><td>$location</td>" "</tr>" } #Post "</body>"
Categories: PowerShell

Powershell

The Official Scripting Guys Forum! - May 18, 2012 - 3:42pm

Need to read a file that looks like this. 

GROUP_9 {
  E2EDC01 { LineFeedDelimRecord  "E2EDC01                       "
  E2EDC01_MANDT { AlphaNumericFld @3 .. 3  none
  }*1 .. 1 ;; |-- end E2EDC01_MANDT --|
  E2EDC01_DOCNUM { AlphaNumericFld @16 .. 16  none
  }*1 .. 1 ;; |-- end E2EDC01_DOCNUM --|
  E2EDC01_PSGNUM { AlphaNumericFld @6 .. 6  none
  }*1 .. 1 ;; |-- end E2EDC01_PSGNUM --|
  E2EDC01_HLEVEL { AlphaNumericFld @2 .. 2  none
  }*1 .. 1 ;; |-- end E2EDC01_HLEVEL --|
  E2EDC01_SGTYP { AlphaNumericFld @3 .. 3  none
  }*1 .. 1 ;; |-- end E2EDC01_SGTYP --|
  E2EDC01_ZLTYP { AlphaNumericFld @3 .. 3  none
  }*1 .. 1 ;; |-- end E2EDC01_ZLTYP --|

I need to write every line to a new file and when I come across a line that has "_" in it, I need to write 2 lines like this after it, using the field name with the "_" in it.

[ ]

E2EDC01_MANDT = " " 

Any suggestions?

Categories: PowerShell

Changing static IP address and DNS to DHCP

The Official Scripting Guys Forum! - May 18, 2012 - 2:23pm

I was told to start a new thread based on the age of the the initial thread I found.  The thread I found discussing this issue doesn't include the DNS portion in the script.  I have found others scripts that work but not very efficiently with Windows 7/Vista.  I have tried to add the DNS portion into this script myself with no luck.  This is the thread I am referring to:  http://social.technet.microsoft.com/Forums/en/ITCG/thread/bd7119d0-af0c-435d-83eb-7367b0c665c3

If someone could assist I would be greatful!

Categories: PowerShell

Changing a trigger property of a scheduled task

The Official Scripting Guys Forum! - May 18, 2012 - 12:25pm
 

Windows Server 2008 R2 SP1. In a scheduled task on the "Edit Trigger" panel that pops up when you edit a Trigger on the "Triggers" tab there is a check box. That check box is labeled "Synchronize across time zones". Does anyone know a way to change that setting other than manually? (script, registry, etc). I need to set this on several thousand servers that span across the EST, CST, MST, and PST time zones. What I am trying to achieve is this:  I what to run a scheduled task at 11:00 PM EST (I believe that is 4 AM Universal time) on all servers no matter which time zone that server is in.

Thanks in advance for any help.

Categories: PowerShell

inventory script needing help with moniotr and NIC output

The Official Scripting Guys Forum! - May 18, 2012 - 12:08pm

good day,

i have this script here that i need some assistance on.

it runs well on desktops with one drive and one monitor. but when i run it on a Laptop it chokes at the monitor section because a laptop does not have a monitor to pull that information from.

it also will only see the active network card on a laptop and it needs to pickup the wired and wireless NIC.

any help would be greatly appreciated,

thanks

'=-=============================
'On Error Resume Next

' To convert to a logon script that runs without user interaction, add a rem in front of the strComputer = InputBox
' line below and remove the rem from the strComputer = "." line below that. This will then only check the PC on which
' the script runs
Set WshNetwork = WScript.CreateObject("WScript.Network")

strComputer = "."
'Type the unc location of the spreadsheet. Needs to exist first.
strWorkBook = "\\server\share\Inventory.xls"

' Create Excel Spreadsheet
Set app = CreateObject("Excel.Application")
app.Workbooks.Open strWorkBook
Set wb = app.ActiveWorkbook
app.Visible = False
wb.Activate
Set ws = wb.Worksheets(1)
ws.Cells(1,1).Value = "Computername"
ws.Columns(1).ColumnWidth = 20
ws.Cells(1,2).Value = "Username"
ws.Columns(2).ColumnWidth = 30
ws.Cells(1,2).Value = "Brand"
ws.Columns(3).ColumnWidth = 20
ws.Cells(1,3).Value = "Model"
ws.Columns(3).ColumnWidth = 20
ws.Cells(1,4).Value = "Serial Number"
ws.Columns(4).ColumnWidth = 30
ws.Cells(1,5).Value = "CPU"
ws.Columns(5).ColumnWidth = 30
ws.Cells(1,6).Value = "CPU Speed"
ws.Columns(6).ColumnWidth = 10
ws.Cells(1,7).Value = "Operating System"
ws.Columns(7).ColumnWidth = 40
ws.Cells(1,8).Value = "Service Pack"
ws.Columns(8).ColumnWidth = 20
ws.Cells(1,9).Value = "Total Memory"
ws.Columns(9).ColumnWidth = 20
ws.Cells(1,10).Value = "Disk Data"
ws.Columns(10).ColumnWidth = 45
ws.Cells(1,11).Value = "Network card"
ws.Columns(11).ColumnWidth = 20
ws.Cells(1,12).Value = "MAC Address"
ws.Columns(12).ColumnWidth = 20
ws.Cells(1,13).Value = "Network card"
ws.Columns(13).ColumnWidth = 20
ws.Cells(1,14).Value = "MAC Address"
ws.Columns(14).ColumnWidth = 20
ws.Cells(1,15).Value = "Video Card"
ws.Columns(15).ColumnWidth = 20
ws.Cells(1,16).Value = "Monitor"
ws.Columns(16).ColumnWidth = 20
ws.Cells(1,17).Value = "Monitor Serial"
ws.Columns(17).ColumnWidth = 20
ws.Cells(1,18).Value = "Monitor"
ws.Columns(18).ColumnWidth = 20
ws.Cells(1,19).Value = "Monitor Serial"
ws.Columns(19).ColumnWidth = 20
ws.Cells(1,20).Value = "Audit Date"
ws.Columns(20).ColumnWidth = 20
ws.Rows(1).Font.Bold = True

' Get the serial number first to see if it already exists in the spreadsheet
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
For Each objItem In colItems
strSerialNumber = "" & objItem.SerialNumber
Next
Set objWMIService = Nothing
Set colItems = Nothing

intRowToUse = -1
For intRowCount = 2 To ws.UsedRange.Rows.Count
      If Trim(strSerialNumber) = Trim(ws.Cells(intRowCount,5).Value) Then
            intRowToUse = intRowCount
      End If

Next

If intRowToUse = -1 Then
      intRowToUse = ws.UsedRange.Rows.Count + 1
End If

'Get Disk usage details
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colDisks = objWMIService.ExecQuery("Select * from Win32_DiskDrive")
    For each objDisk in colDisks
    sDiskID = objDisk.DeviceID
    sTotal = Int(objdisk.Size /(1073741824))
    sUsed = sTotal-sFree
    sDisk = sDisk & " "& sDiskID & " " & sTotal &  " GB " & vbCrLf
    'Output the disk usage details
    ws.Cells(intRowToUse,10).Value = sDisk

Next

Set objWMIService = Nothing
Set colItems = Nothing

' Get Computer System Details
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem In colItems
    ws.Cells(intRowToUse,1).Value = "" & objItem.Caption
        ws.Cells(intRowToUse,2).Value = "" & objItem.Manufacturer
       ws.Cells(intRowToUse,3).Value = "" & objItem.Model

Next

Set objWMIService = Nothing
Set colItems = Nothing

'Output the Serial Number
    ws.Cells(intRowToUse,4).Value = strSerialNumber

' Get CPU Details
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48)
For Each objItem In colItems
    ws.Cells(intRowToUse,5).Value = "" & objItem.Name
        ws.Cells(intRowToUse,6).Value = "" & objItem.CurrentClockSpeed

Next

Set objWMIService = Nothing
Set colItems = Nothing

' GET OPERATING SYSTEM
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem In colItems
        ws.Cells(intRowToUse,7).Value = "" & objItem.Caption
       ws.Cells(intRowToUse,8).Value = "" & objItem.CSDVersion
        ws.Cells(intRowToUse,9).Value = "" & FormatNumber(objItem.TotalVisibleMemorySize/1024,0)  

Next

'NETWORK ADAPTER

    Set colNicConfigs = objWMIService.ExecQuery _
 ("Select * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colAdapters = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
For Each objAdapter in colAdapters
     ws.Cells(intRowToUse,11).Value = "" & objAdapter.Description
     ws.Cells(intRowToUse,12).Value = "" & objAdapter.MACAddress
      ws.Cells(intRowToUse,13).Value = "" & objAdapter.Description
     ws.Cells(intRowToUse,14).Value = "" & objAdapter.MACAddress

next

'VIDEO ADPATER
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_VideoController")
For Each objItem In colItems
    ws.Cells(intRowToUse,15).Value = objItem.Description

next

Function BytesToString(ByVal Bytes)
  Dim Result, N
  Result = ""
  For N = 0 To UBound(Bytes)
    If CInt(Bytes(N)) <> 0 Then
      Result = Result & Chr(Bytes(N))
    Else
      Exit For
    End If

  Next

  BytesToString = Result
End Function

Dim WMI, Monitors, Output, Monitor
    Set WMI = GetObject("winmgmts:{impersonationlevel=impersonate}!root/wmi")
    Set Monitors = WMI.InstancesOf("WmiMonitorID")
Output = ""
For Each Monitor In Monitors
  If Output <> "" Then
    Output = vbNewLine & Output
  End If
  Output = Output _
    & "Active: " & CStr(Monitor.Active) & vbNewLine _
    & "InstanceName: " & CStr(Monitor.InstanceName) & vbNewLine _
    & "ManufacturerName: " & BytesToString(Monitor.ManufacturerName) & vbNewLine _
    & "UserFriendlyName: " & BytesToString(Monitor.UserFriendlyName) & vbNewLine _
    & "SerialNumberID: " & BytesToString(Monitor.SerialNumberID) & vbNewLine _
    & "WeekOfManufacture: " & CStr(Monitor.WeekOfManufacture) & vbNewLine _
    & "YearOfManufacture: " & CStr(Monitor.YearOfManufacture)
    
    ws.Cells(intRowToUse,16).Value = "" & BytesToString(Monitor.UserFriendlyName)
    ws.Cells(intRowToUse,17).Value = "" & BytesToString(Monitor.SerialNumberID)
    ws.Cells(intRowToUse,18).Value = "" & BytesToString(Monitor.UserFriendlyName)
    ws.Cells(intRowToUse,19).Value = "" & BytesToString(Monitor.SerialNumberID)

next

Set objWMIService = Nothing
Set colItems = Nothing

' Get & Writeout current Date
ws.Cells(intRowToUse,20).value = "" & Month(Now) & "-" & Day(Now) & "-" & Year(Now)

'Autofit all columns
app.ActiveSheet.Columns.EntireColumn.AutoFit
' Save Audit File
app.DisplayAlerts = False
'wb.Saved = True
wb.Close True
app.DisplayAlerts = False
app.quit

Categories: PowerShell

Enumerating IIS 6 weblog directory info with ADSI

The Official Scripting Guys Forum! - May 18, 2012 - 11:47am

I needed to write a script that will walk through each site on a server, find the directory for each site where the web logs are written and then delete logs older than 30 days.  I have the script working for IIS 7 using the IIS Snap-in; however, I also need to do this same task on IIS 6 (and IIS 5!) servers as well.  I decided to use ADSI to get the information needed, and am very close to having it completed, but there is one issue I can't resolve - a space between the results queries.  The space appears to be before my variable string.  I have tried using $string.Substring(1), but that just removes the first letter in the returned text - not the leading space.  Below is the code and the result...any help is appreciated!

$sites = [adsi]"IIS://localhost/W3SVC"
$children = $sites.children
ForEach ($child in $children)
 {
  If ($child.KeyType -eq "IIsWebServer")
  {
     $site =$child.name
     $wsvc ="W3SVC"
     $LogLocation = $child.LogFileDirectory
     $logfolder = $LogLocation + $wsvc + $site + "\"
     write-host $LogFolder
  }
 }

d:\data\logs\iis\ W3SVC 1043446615 \
d:\data\logs\iis\ W3SVC 1057654198 \
d:\data\logs\iis\ W3SVC 1130850271 \
d:\data\logs\iis\ W3SVC 1240773179 \


Categories: PowerShell

Remote users who have forgotten there local domain profile password

The Official Scripting Guys Forum! - May 18, 2012 - 11:46am
How can you either remove or reset a local domain account password (laptop) without being connected to the domain, also user does not know the password? We do not have an Exchange/OWA environment. We can have the user, with direction, login to a local profile account with admin rights. This has also occurred when user does not have any access to the Internet (very remote locations). We do have a password scripting tool, which only works for changing local profiles while connected to the domain.
Categories: PowerShell

deleting student profile in windows 7

The Official Scripting Guys Forum! - May 18, 2012 - 11:43am

good day,

i work in education K-12 we upgraded to windows 7 at the start of the year. it is time clean up the computer and remove the student profiles from the computers. i have over 300 students per campus for over 1200 total students. i am looking for a script that will let me delete the students but leave the must have accounts and teachers accounts.

i have looked into delprof2 and few other scripts but they want to setup the profiles that are not to be deleted so they can delete the unwanted or delete by number of days old. if the teachers a students or it is july before i could run the script or program it would hit both groups.

what i would like to see is a script that calls to ad for the group and then ask for the logon name of each user in that group.

is there such a script or program to do this??

any help would be much appreciated.

thanks

Categories: PowerShell

Removing Devices from an AD Group

The Official Scripting Guys Forum! - May 18, 2012 - 10:44am

Hello,

I'm trying to remove a group of devices in an AD group.  I don't want to remove all devices but specific devices say device ending in 8 e.g. DEV*8.

My cmd is like:

dsget group "CN=ad_group_devices,ou=xx,ou=xx,....." -members | dsquery computer -name DEV*8 | dsrm -c

I keep getting an error.

Any help is appreciated.

cheers,

Al

Categories: PowerShell

Join WQL Query c++

The Official Scripting Guys Forum! - May 18, 2012 - 8:28am

Hello everyone,

How Can I get PnPDeviceID of live/currently connected ?

I queried deviceIOControl, where I found on removable device.. I need to pass that result to get its PnPDeviceID...

Categories: PowerShell

Updating a database from powershell command output

The Official Scripting Guys Forum! - May 18, 2012 - 8:19am

Updating a database from Powershell command output

I found this Hey Scripting Guy post and it is very close to working.

http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx

I added these 4 scripts invoke-sqlcmd2, write-datatable, out-datatable and add-sqltable to my own script and issued the following:

$dt = Get-AdGroupMember -Identity 'CN=SP_Test Org Desc,OU=TECO Organizational Groups,DC=tec,DC=net' -Server 'tec.net' -Recursive |Out-DataTable

Write-DataTable -ServerInstance "instancename" -Database AD_Scripts -TableName test -Data $dt

One of the fields that comes back is the SID field and I cant seem to get the right data type in the database.

The error I get is:

Write-DataTable : System.Management.Automation.MethodInvocationException: Exception calling "WriteToServer" with "1" argument(s): "The given value of type SecurityIdentifier from the data source cannot be converted to type varbinary of the specified target column." ---> System.InvalidOperationException: The given value of type SecurityIdentifier from the data source cannot be converted to type varbinary of the specified target column. ---> System.InvalidCastException: Failed to convert parameter value from a SecurityIdentifier to a Byte[]. ---> System.InvalidCastException: Object must implement IConvertible.

I have tried changing the datatype for the SID field to many types. Some posts indicated it had to be exactly varbinary(16) (85) or (100) but I cant get it to work. So....

I tried something that seems even more important to be able to do - I added the Format option to the command to remove the SID column

$dt = Get-AdGroupMember -Identity 'CN=SP_Test Org Desc,OU=TECO Organizational Groups,DC=tec,DC=net' -Server 'tec.net' -Recursive |Format-Table -Property distinguishedName,name,objectClass, objectGUID,SamAccountName|Out-DataTable

Write-DataTable -ServerInstance "instancename" -Database AD_Scripts -TableName test -Data $dt

The command runs but nothing gets added to the table. No Errors, etc. Im stumped.

Thanks. Slag

Categories: PowerShell

Use a script to list all received email within a time period for an account (by sender)

The Official Scripting Guys Forum! - May 18, 2012 - 6:35am

I have gotten a "challenge", I need to make a script that alerts us when any automated email status messages are NOT received.
This could be any type of mail from "backup succesful", "backup failed", "RAID health check ok"... etc...

Sometimes things happen and these mails are not sent (or received) at all. And with a few hundred of these mails to monitor every day the ones NOT received are sure to fall trough the cracks, as they have now on some occations. Not too good if a client should get a server meltdown and we do not have any backup for the last four weeks becaue the service crashed and we did not notice that we did not receive any email.

I am not a script-guy, I am learning every day, but for this I have no clue where to begin.
I prefer to use VBS for my scripts


Can anyone point me in any direction on this.

In my head the script looks like this:

Find the senders of all mail to this particular mailbox within the last X amount of hours/days.
Compare to a list of the senders that SHOULD be there.
Throw a warning (send a mail) when the sender is not in the list.
Perhaps also even ask to input senders not in the list, but received from, to the list.

What I have trouble with is the first part:
How to get the information from Exchange so I can make the list of received mail.
Like Outlook does, shows today, yesterday and three days ago (last week, last month etc...)

I find a few scripts for finding mailboxsize, but that is not what I am after.
I have control of the exchange server and know the account and password

Categories: PowerShell

Upcoming Events

  • No upcoming events available