Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all 15028 articles
Browse latest View live

AEM CentraStage Event Result Script

$
0
0

Hi, 

We are using AEM CentraStage Monitoring as an monitoring tool. With this monitoring program we are trying to create e-mail notifications of the event log. 

To create the e-mail notifications we need to create an “custom component”. For the “custom component” we have written the following PowerShell script:

$Event = Get-WinEvent -FilterHashtable @{logname='Microsoft-Windows-Backup'; id=4,5,8,9,19,49;StartTime=(Get-Date).AddMinutes(-2015)} -MaxEvents 1 -ErrorAction SilentlyContinue | format-list

If ($Event -eq $null)
	{ Exit 0 } #No events logged
Else
{
Write-Host "<-Start Result->"
Write-Host "Result="($Event | Format-Table | Out-String)
Write-Host "<-End Result->"
Exit 1
}

But when we receive an e-mail notificiaton, the e-mail is empty
Like this: 

I have tried different variation in the script like removing the  “format-list” Command, but then we receive an e-mail notification with errors.

Like this


Can somebody help me out, Because i don't have enoug knowledge to resolve this problem on my own. 

Kind regard,
Francois Meulenberg



PowerShell - After recommedation of array - hash table use

$
0
0

Hi

I am struggling a bit trying to work out the best way to dynamically store some info then access it.

(Note: I read the data in so can't statically initialise the array, some .Add() is needed) 

I have two classed of data with variable columns count

Type A
Name, Token1, token2, ... repeating

Type B
NameX, Info1, Info2, TokenA, TokenB, ...

What I would like to do is :
- Add a row of Type A data to the Type A array with a key of "Name"
- Add a row of Type B data to the Type B array with a key of "NameX"

Then access the respective arrays with the appropriate Name key and get the "object" which has the data

Then from the data get the various tokens and info. This can be by $x[0], $x[1] type of references but would be nice if
I could do $x["Info1"], $x["info2"]   and   foreach $x["token*"]  <= i.e. each token

>> After some tips ?

(seems like I need a hash table to an array but I can't seem to get this right)

I hope I have explained this clearly enough.

Thanks in advance


Creating external contacts - Powershell

$
0
0

Hi, I have a sort of working  script for creating contacts but am not quite sure the correct way to go from here. Please see below that creates my contacts in AD

$ContactList= Import-Csv "c:\Contacts1.csv"
$ContactList | foreach {New-ADObject -Type Contact -Name $_.Name -OtherAttributes @{'Alias'=$_.Alias;'displayName'=$_.Display;'givenName'=$_.FirstName;'mail'=$_.Email;'physicalDeliveryOfficeName'=$_.Location;'Title'=$_.Title;'company'=$_.Company;'department'=$_.Department} -Path "OU=External Contacts,DC=Test,DC=NET"}
Now I need these mail enabled in Exchange and can do this with the enable-mailcontact in the EMS. Ideally I would like to have just one script to do this but it seems like new-mailcontact in EMS doesn't set all the attributes I want eg Office, job title. Can newnew-mailcontact accept -otheratrributes? It seems not from the help file. Is there a way to achieve this with one script to set all the attributes I have done with new-adobject?


We are on Exchange 2010 and I don't seem to be able to use -mailcontact cmdlet in PS, they are only available when I open EMS.

I need to move AD Users from a CSV to OUs from a CSV

$
0
0

Hi Guys,

Basically what we have is a production domain and a dev domain.

I have mirrored to OU structure identically, but many of the User accounts have been created in dirrering areas.

I have done an export of all the users selecting the sAMAccountName, UserPrincipalName, and OU from the distinguoshedname, using @{n='ParentContainer';e={$_.distinguishedname -replace '^.+?,(CN|OU.+)','$1'} and exported to CSV.

I was just wondring if anyone could help me with a script to move the AD Users in the CSV in the dev enviroment to the location in the same CSV, so to mirror both AD environments.

Thanks in advance

Si

Issue Getting Data from File and Using in Script

$
0
0

Here is what I got trying to put together a script to read the patches on a remote PC:

$computer = gc env:computername
$computers=get-content -path c:\computer.txt
$csvfile ="c:\name.csv"foreach($computer in $computers){Get-WmiObject-Class WIN32_QuickFixEngineering |Select-Object"Caption","CSName","Description","InstalledBy","InstalledOn"|ConvertTo-HTML |Out-File $csvfile}

I do get the results, but I get them from the local machine and not the remote one. What am I doing wrong trying to get the computer name from the c:\computer.txt file?

Thanks again for the help.

Remove duplicates of a csv file

$
0
0

Hi,

I am importing a csv and on pcuture 1 is the result.

Now I want to delete all entries which having the same name and Keep only one of them with the latest date. Picture 2

But when I am doing a sort I am only getting the earliest entry Picture 3.

Here the script:

import-csv C:\name8.csv | sort name -Unique

New-DNSRecord using gives error Invalid Namespace

$
0
0

Hi Team, 

i am using the following cmd and getting following error .

----------------------------                 

New-DnsRecord -Name VM1 -RecordType A -Zone <DNSdomainname> -IPAddress <IP>

-----------------------------------             ERROR -------------------------------------------

New-DnsRecord : Invalid namespace
At line:1 char:14
+ New-DnsRecord <<<<  -Name test12345 -RecordType A -ZoneName wintelsys.com -IPAddress 192.168.1.10
    + CategoryInfo          : InvalidOperation: (DnsShell.PowerS...anagementCmdlet:RuntimeType) [New-DnsRecord], Manag
   ementException
    + FullyQualifiedErrorId : WMIManagementException,DnsShell.PowerShell.CmdLet.NewDnsRecord

New-DnsRecord : Object reference not set to an instance of an object.
At line:1 char:14
+ New-DnsRecord <<<<  -Name test12345 -RecordType A -ZoneName wintelsys.com -IPAddress 192.168.1.10
    + CategoryInfo          : NotSpecified: (:) [New-DnsRecord], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,DnsShell.PowerShell.CmdLet.NewDnsRecord

------------------

i have also visited below site but Did not get a idea what to do ?

http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/13/manage-dns-in-a-windows-environment-by-using-powershell.aspx

Can you please guide me what to do in this case ?

How to generate computer certificate on workgroup machines using cmd or powershell

$
0
0

Hi Team,

Need your help ........ 

I want to generate computer certificate on workgroup machines using and cmd or Powershell cmdlets. 

I have one internal Windows ROOT CA. 

Can you suggest any cmdlets which works on Workgroup machines. (NON Domain Joined Machines ) 

Thanks 


Remove-ADGroupMember from groups imported from csv with names like...

$
0
0

Hello,

I am trying to import a list of ADGroups and remove members whose name are like "eXXX" or "cXXX" (for example).

Very simple to remove all members from a list of imported groups but I am struggling on how to incorporate a ? {(Name -Like "eXXX*") -or (Name -Like "cXXX*")} following the -Members parameter. 

Perhaps I am missing something simple but any help would be appreciated.

PowerShell Script - Error Handling SCCM Client Hardware Inventory Trigger

$
0
0

I have added the below to a PowerShell script so that an SCCM client hardware inventory is triggered at the end of the script. 

$SMSCli = [wmiclass] "root\ccm:SMS_Client"
$SMSCli.TriggerSchedule("{00000000-0000-0000-0000-000000000001}")

The SCCM client inventory runs as expected however on some clients (Windows 7 and Windows Vista) I get this error (although the inventory still runs):

format-default : The following exception occurred while retrieving members: "The RPC server is unavailable. (Exception
from HRESULT: 0x800706BA)"
    + CategoryInfo          : NotSpecified: (:) [format-default], ExtendedTypeSystemException
    + FullyQualifiedErrorId : CatchFromBaseGetMembers,Microsoft.PowerShell.Commands.FormatDefaultCommand

Any ideas on how I can either resolve this error or simply tell the script to ignore it?

The main reason I need to stop this error is that when running the entire script via an SCCM program/advert, it exits with aFailed exit code 1 (but only on some clients!).  I still haven't worked out why 133/230 clients (mixture of Vista x86, Win 7 x86/x64) run the script and returnexit code is 0 (Success)?

Thanks in advance

Steve

Require send mail script to get HTML/HTM report file as mail body

$
0
0

Hi Everyone,

Need one script to convert exported html file send as mail body... VB script or PS is preferable.



Regards Sayan

execute VBA in command line

$
0
0

Hello,

I want to change execute this VBA by comman line because i must make a Schedule.

The solution is to start the VBA when i start Outlook and make a Schedule for open and close Outlook but it's not very well.

Is it possible to execute it by command line ?

This littel script modify the "display as" in contact Outlook.

Public Sub ChangeEmailDisplayName()
    Dim objOL As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim objContact As Outlook.ContactItem
    Dim objItems As Outlook.Items
    Dim objContactsFolder As Outlook.MAPIFolder
    Dim obj As Object
    Dim strFirstName As String
    Dim strLastName As String
    Dim strFileAs As String

    On Error Resume Next

    Set objOL = CreateObject("Outlook.Application")
    Set objNS = objOL.GetNamespace("MAPI")
    Set objContactsFolder = objNS.GetDefaultFolder(olFolderContacts)
    Set objItems = objContactsFolder.Items

    For Each obj In objItems
        'Test for contact and not distribution list
        If obj.Class = olContact Then
            Set objContact = obj

          With objContact

          If .Email1Address <> "" Then
            ' Uncomment the  strFileAs line for the desired format
            ' Add the email address to any string using
            ' the following code:
            ' & " (" & .Email1Address & ")"

             'Firstname Lastname (email address) format
             ' strFileAs = .FullName & " (" & .Email1Address & ")"

             'Lastname, Firstname format
              strFileAs = .FullName & " (" & .Email1Address & ")"

             'Company name (email address) format
             ' strFileAs = .CompanyName & " (" & .Email1Address & ")"

             'Comapany Firstname Lastname (email address) format
             'the display name will have a leading space if
             'the contact doesn't have a company name
             'strFileAs = .CompanyName & " " & .FullName & " (" & .Email1Address & ")"



             'File As format
             'Does not support Company (Fullname) format.
             'Only Company name is used in the display name
             'strFileAs = .FileAs

             .Email1DisplayName = strFileAs

             .Save
           End If
          End With
        End If

        Err.Clear
    Next

    Set objOL = Nothing
    Set objNS = Nothing
    Set obj = Nothing
    Set objContact = Nothing
    Set objItems = Nothing
    Set objContactsFolder = Nothing
End Sub

                                                                                                                    

TRIM SPLIT Powershell cmdlet

$
0
0

Hi,

I have a csv file where for each of the rows, i need to extract only the last few words of the text.

input string

,Unrecoverable Fault : 006 - Duplicate Transaction - UFM ID : 13715030397201 UFMErrorCode : 3003 

Expected output string

UFM ID : 13715030397201 UFMErrorCode : 3003 

I need to extract all the info which starts with UFM ID, Any ideas, how this can be done. I need to do for each and every row in the csv file.

Thanks,

Powershell to find AD group Change

$
0
0
Is there a way to figure out who did what changes to a AD group using powershell.  

Priyabrata

Inset Delay (sec) in for loop

$
0
0

Hi,

I have a powershell script where I am using a for loop. I am reading a csv file and for each row, I am running a command (cawto). Is there a way, I can insert a delay (similar to sleep) for a few seconds (5), before it reads the next row on the csv file.

$VPSFile = Import-Csv 'D:\TRHMIBS\VPS\RTN\newfile.csv'
$Results = @()
foreach ($P in $VPSFile)
{

$PL = $P.PLA_; #
$CT = $P.LAN; #
$LN = $P.LA; #Count
$PL = $P.HASRR;
$CT = $P.TOTAL_UFM;
$LN = $P.RRPCT;

cawto VPSRTNUFM ('{0} {1} {2} {3} {4} {5}' -f $P.PLAZA_, $P.LANE_ID, $P.LA, $P.HASRR, $P.TOTAL_UFM, $P.RRPCT)
}


Powershellscript listing all security groups a Office 365 is in.

$
0
0

The CMD's for managing users on Office 365 is very limited.

I want a simple list of groups a specific msoluser is member of.

How can I achive this?

I guess I'll have to use a combination of get-msoluser, get-msolgroup and get-msolgroupmember?

Removing a SID from the local administrator's group

$
0
0

Good morning, I have recently built a tool which removes domain users from the local administrators group using a text file for input of the machine name and user name.  Yesterday, I was asked to remove a dead account that only shows up as a SID in the local administrators group of ~1400 machines.  I tried using my program with a couple of minor modifications (my current tool uses SCCM to run net localgroups .... /delete, but I noticed none of the 15 test machines I used to create my initial collection had the account removed.

Some caveats, I can not use PSExec, it's frowned upon in our network environment. 

My VB and powershell skills are minimal (we use wise scripting for almost everything).

Please help

Thanks, Rick 

Suggestions for Beginners

$
0
0

Hi All,

I'm a beginner to SCCM and Script. I'm eagerly interested to learn SCCM and Script. I've already started to learn SCCM via online courses and from Colleagues. Meanwhile I'd like to know the best way to learn these things. Please suggest to your junior to become an expertise like you all in this Profession.

Using Robocoy with spaces in the path

$
0
0

Is there a way to use Robocopy to move files from one server to another when there are spaces in the path name?

I have tried several things including this

robocopy \\file\forms\te=reasury management\needs to be imported\ c:\scans\treasury

There are " marks befor and after the source folder but the editor taskes them out. 

When i put quotes on the source path Robocopy takes the entire line as the source and tells me there is no destination specified.

Is there a way to use the quotes in Robocopy?

Thanks for your help jrussell97

WMI Namespace and __Genus property confusion

$
0
0

My question is less to do with scripting as a whole, and more to do with WMI in a general sense. I've been writing a program in C# to scavenge information out of WMI as a project (I know many great tools out there exist already, but this is both for learning and custom tailored to an environment I manage), and I've come across a few oddities. Currently tripping me up is the following snippet below:

using System.Management;

ManagementClass managementClass = new ManagementClass(new ManagementPath(@"\\" + pHostName + @"\root\" + pNameSpace));

EnumerationOptions enumOptions = new EnumerationOptions();
enumOptions.EnumerateDeep = false;

foreach(ManagementObject wmiClass in managementClass.GetSubclasses())
{
    Console.WriteLine(wmiClass["__Class"].ToString());
}

Given the definition of System.Management.ManagementClass under both the MSDN documentation and the VS Documentation, which I'll paraphrase pretty heavily to say it represents a CIM class, and the definition for the GetSubclasses() method which returns a collection of all subclasses under a class (under a class being the key phrase there), the only logical conclusion I can make as to why this works is that a Namespace in WMI is actually an instance of a class, which sounds incredibly wrong.

Are Namespaces actually instances of classes in WMI? On another note, what's the deal with the __genus property of classes? Why is the following a perfectly acceptable WQL:

select * from meta_class where __class like "%win32%" and __superclass like "%process%"

but this is not:

select * from meta_class where __class like "%win32%" and __genus is 2
select * from meta_class where __genus = 1

Neither of the above work, but are both valid and populated properties of classes when a query like the first is performed.

TL;DR; (but I hope you do Read) Are WMI Namespaces actually instances of a higher class? Additionally, why can I query something like __superclass, but not __genus?

Sincerely,

Really confused

Viewing all 15028 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>