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

MSCluster.Cluster Classes not registered in windows 2012

$
0
0

I don't see mscluster.cluster class in windows2012 after cluster build but same I get in windows2008 ,my code started failing due to that,example below , can somebody point out why classes are missing and how to get them back?

PS D:\do_not_delete\Scripts> New-Object -Com "mscluster.cluster"

New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed

due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

At line:1 char:1

+ New-Object -Com "mscluster.cluster"

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException

    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand


I need to get the cluster information using"MSCluster.Cluster" object

$
0
0

Hi,

Please anyone solve my problem ? I need to get the cluster information using"MSCluster.Cluster" object.

Set objCluster = CreateObject("MSCluster.Cluster")

objCluster .open <clustername>

If i run the vbscript " Microsoft VBScript runtime error: ActiveX component can't create object: 'MSCluster.Cluster' " error is thrown.

Kindly explain what is the issue and what can i do ? 

-Sundar.


PowerShell Test-connection and Active Directory Input

$
0
0

I am just learning powershell, and I"m working to write a script that pulls computer names from AD and puts them into a Test-connection cmdlet to determine if its valid.

clear-host
import-module activedirectory
$workstations = Get-ADComputer -Filter '*' -SearchBase "OU=CMSD,OU=Windows XP,OU=Workstations,DC=TECH,DC=LOCAL" | FT Name
Foreach($w in $workstations)
    {
        Test-Connection -ComputerName $w -Count 1
    }

when i run the script, i receive the following error for all entries:

Test-Connection : Testing connection to computer 'Microsoft.PowerShell.Commands.Internal.Format.GroupEndData' failed: The requested name is valid, but no data of the requested type was found
At line:6 char:24+         Test-Connection <<<<  -computername $w -Count 1+ CategoryInfo          : ResourceUnavailable: (Microsoft.Power...at.GroupEndData:String) [Test-Connection], PingException+ FullyQualifiedErrorId : TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand

I'm thinking that when the array is going into the Test-connection cmdlet, its adding string characters such as "name=computer" and not just the computer name.  I don't know how to edit strings in powershell.  

any help is appreciated, thank you.


Problem Setting Variable

$
0
0

I have started learning PowerShell but I am still fairly inexperienced.  The other night I was curious about how to display a simple dialog box using PowerShell, and I came across the two articles below--one shows how to do a text box and the other shows how to do a list box.

http://technet.microsoft.com/en-us/library/ff730941.aspx

http://technet.microsoft.com/en-us/library/ff730949.aspx

Based on these articles I decided to do a little learning project.  Essentially, I combined the code from the two articles so that I have one dialog box that contains a list box and a text box.  The list box contains descriptions of scripts, and the text box allows a name to be entered.  The idea is that a user could select the script to run, put in the employee name, and get the desired results.  Currently, there are only two scripts on the list, and both are single liners, so the code below might seem like a lot for a few single line commands, but as I say, this is a learning project.  I can envision eventually adding some data validation, error trapping, etc.  But, first I need to get this basic version working.

Below is my code.  As you can see, I'm using Remove-Variable to make sure the values are reset each time, and I'm setting breakpoints for the variables.  The breakpoint commands are included for testing purposes and will eventually be removed.  I either disable the breakpoints commands after they are set once, or clear the breakpoints between each test run.  I've also temporarily disabled the section that determines what to do when the ENTER or ESC keys are used, and at the end I write the variables to the screen just for visual confirmation that the values were set correctly (This will be removed when the script is working). When I run the script nothing happens--it behaves as if the variables are not getting set. The odd thing is, when a variable break point is encountered and I hover over the variable, it shows the correct value.

What am I missing?  When I run the script why does nothing happen?  It seems to me that the values should at least be written to the screen.

Thanks for any help that you can offer!

--Tom

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

Remove-Variable ScriptToRun
Remove-Variable EmployeeName

Set-PSBreakpoint -script ServiceDeskScripts.ps1 -Variable ScriptToRun
Set-PSBreakpoint -script ServiceDeskScripts.ps1 -Variable EmployeeName

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Script Options"
$objForm.Size = New-Object System.Drawing.Size(300,270)
$objForm.StartPosition = "CenterScreen"

# $objForm.KeyPreview = $True
# $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
#    {$ScriptToRun=$objListBox.SelectedItem;$EmployeeName=$objTextBox.Text;$objForm.Close()}
# $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
#    {$objForm.Close()}})

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,190)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$ScriptToRun=$objListBox.SelectedItem;$EmployeeName=$objTextBox.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,190)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please select a script to run:"
$objForm.Controls.Add($objLabel)

$objListBox = New-Object System.Windows.Forms.ListBox
$objListBox.Location = New-Object System.Drawing.Size(10,40)
$objListBox.Size = New-Object System.Drawing.Size(260,20)
$objListBox.Height = 80

[void] $objListBox.Items.Add("Email Archive")
[void] $objListBox.Items.Add("Last Sync")

$objForm.Controls.Add($objListBox)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,130)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Enter the employee name (Last name, first name):"
$objForm.Controls.Add($objLabel)

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,150)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()

$ScriptToRun
$EmployeeName

if ($ScriptToRun -eq "Email Archive") {get-mailbox $EmployeeName |select arch*}
 elseif ($ScriptToRun -eq "Last Sync") {Get-ActiveSyncDeviceStatistics -mailbox $EmployeeName |select las*}


Mapping a user's home drive via ps1 script/function - shows success but drive is not present in user's environment

$
0
0

Hello, due to more people teleworking this time of year an issue has been noticed and brought up that when connecting to our VPN the network drives are all there except for the home drive. I have created a short function that should and does find and map the home drive for the local user when run on its own. 

Function Map-HomeDrive
{
$adsearch = New-Object DirectoryServices.DirectorySearcher
$adsearch.Filter = '(&(objectCategory=person)(objectClass=user)('+"anr=$env:UserName"+'))'
$adsearch.SearchRoot = 'LDAP://DC=domain,DC=com'
$results = $adsearch.FindOne()
$object = [adsi]$results.path.ToString()
$directory = $object.HomeDirectory.ToString()
if (!(Get-PSDrive -Name U -ErrorAction SilentlyContinue)) {New-PSDrive -Name U -Root $directory -PSProvider FileSystem -Persist -ErrorAction SilentlyContinue}
}

running Get-PSDrive -Name U afterwards results in a "Cannot Find drive" message

running the if (!(Get-PSDrive ... SilentlyContinue) line by itself does map the drive and makes it available to the user.

Does PowerShell not run the function in the same environment or is there some parameter I may be missing?

Primarily Windows 7 w/ PowerShell v3

thanks,

-Nick

PowerShell Export-CSV When Source Object Contains Both Strings And Collections

$
0
0

My goal is to process the data inside a bunch of XML log files.  I would like to get them into CSV format so that end users can easily view them in Excel.

First, I store all the data in a variable called $log.  This works without a hitch

[xml]$log = Get-Content file.xml    #Store the XML data in an object in memory

Let's look at what we've got:

PS U:\> $log

xml                                                         log
---                                                         ---
version="1.0" encoding="utf-8"                              log

There was not much there, so let's drill down another level:

PS U:\> $log.log

entry
-----
{entry, entry, entry, entry...}

Still not what we're looking for, so we'll dig deeper.  Eureka!  Well, almost...  

PS U:\> $log.log.entry

log_time     : 20111009-01:15:32
description  : description
service      : HTTP
sessionid    : 1234567890
type         : 1
severity     : 0
user         : username
host         : subdomain.domain.tld
lstnconnaddr : 192.168.0.17:443
cliconnaddr  : 8.8.8.8:17251
cmd          : Download
params       : params
absfile      : absfile
filesize     : 1024
transtime    : 13001
sguid        : ABC-123-blahblahblah

Here we see the first symptoms of the problem.  Look at the three parameters that don't show their values:  description, params, and absfile.  Why is that?  Here's why:

PS U:\> $log.log.entry.description | Get-Member

   TypeName: System.Xml.XmlElement

Instead of a string as expected, we have a collection of XmlElements.  If I try to export the relevant data to CSV, each of those three columns (description, params, and absfile) is full of repeated entries showing "System.Xml.XmlElement" instead of actually showing me the data.

$log.log.entry | Export-CSV log.csv

The ExpandProperty parameter for Select-Object does what I need, but it only allows Select-Object to work with that one property, so I lose all my other data which makes it useless:

$log.log.entry | Select * -ExpandProperty Description | Export-CSV log.csv

OK, alright, everyone on the Internet is saying to create a custom property to deal with this.  The Internet doesn't lie, right?  So instead I try it like this:

$log.log.entry | Select log_time,service,sessionid,type,severity,user,host,lstnconnaddr,cliconnaddr,cmd,errnum,sguid,@{n="description";e={($_ | Select-Object -ExpandProperty description) -join " "}} | Export-CSV log.csv"

Instead of the intended results, the Description column in the CSV is now filled with repetitions of the word "description" instead of "System.Xml.XmlElement".  It still does not contain the actual descriptions.

I know the actual descriptions do exist, and here is how:

$log.log.entry.description

The line of code above will print out all the descriptions to the console.

So, I am completely lost and a tad frustrated with PowerShell right now.  Can anyone tell me what I'm missing?  How the heck do I get all this information into my CSV file?

Hope this question makes sense, let me know what I can do to improve it.




E-mail notification using powershell script in 365

$
0
0

I need a e-mail script that works using 365. Here is what I have so far and I cant get it to work.

Function EMAIL{

	Param(
		$emailSmtpServer = "XXXXXXXXXXX",
		$emailSmtpServerPort = 587,
		$emailSmtpUser = "XXXXX@XXXXX.com",
		$emailSmtpPass = "Password",
		$emailFrom = "XXXXX@XXXXXXX.com",
		$emailTo = "XXXXXXX@XXXXXXX.com",
		$emailAttachment = 'XXXXXXXXXX',
		$emailSubject = "This is a test" ,
		$emailBody = "How does this look?"
	)
	Process{
$emailMessage = New-Object System.Net.Mail.MailMessage( $emailFrom , $emailTo )
$emailMessage.Subject = $emailSubject
$emailMessage.Attachments.add($emailAttachment)
$emailMessage.IsBodyHtml = $true
$emailMessage.Body = $emailBody
$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential( $emailSmtpUser , $emailSmtpPass );
$SMTPClient.Send( $emailMessage )
}
}



When I use the send-mailmessage and do -credential how to get my password in without having to type it in?

$
0
0
I would like to automate this send-mailmessage to send without having to type in credentials?
-credential noreply@XXXX.com

Unable to get lastLogonTimestamp value from New-Object PSObject

$
0
0

I have the following code in a ForEach loop to log output to a CSV file but am having trouble getting it to populate thelastLogonTimestamp values... the output just comes out blank.  All the other columns are populating fine.  The value definitely exists in AD for these disabled users. I have a hunch that it has something to do with the actual value (e.g. - 130100816639918715) vs. the displayed value (e.g. - 4/10/2013 11:34:23 AM Eastern Standard Time). The syntax is categorized as "Large Integer/Interval."  Any ideas?

#Create new object for logging.
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name "Name" -Value $DisabledUser.name
$obj | Add-Member -MemberType NoteProperty -Name "samAccountName" -Value $DisabledUser.samaccountname
$obj | Add-Member -MemberType NoteProperty -Name "DistinguishedName" -Value $DisabledUser.DistinguishedName
$obj | Add-Member -MemberType NoteProperty -Name "lastLogonTimestamp" -Value $DisabledUser.lastLogonTimestamp
$obj | Add-Member -MemberType NoteProperty -Name "Status" -Value 'Disabled'

#Adds object to the log array.
$LogArray += $obj

#Exports log array to CSV file in the temp directory with a date and time stamp in the file name.
$logArray | Export-Csv "C:\Temp\User_Report_$logDate.csv" -NoTypeInformation

Powershell - Trimming the first 10 characters from a text file and replacing it

$
0
0

Hi Everyone,

Does anyone know how to trim the first 10 characters from a text file and then append the replacement in its place?

Example: Lets say that on the first line of text which could be a random name like this  \\server1234\sharedfolder. I want to replace \\server1234 with \\server5678. Remember that trimming is my only alternative because there is no static name, its random.

Any help would be very helpful. Thank you

Exchange 2007 - Get-LogonStatistics need to get primarysmtpaddress

$
0
0

I need to pull in primarysmtpaddress to Get-LogonStatistics.  Here's what I have so far:

Get-Mailbox -ResultSize unlimited | Get-LogonStatistics | Select UserName,ClientVersion,LastAccessTime,ServerName  | Export-Csv "C:\outlook_version.csv" -NoTypeInformation

Any help would be greatly appreciated.

Windows 8.1 AutoRotate Powershell Script

$
0
0

Hello,

I'm trying to write a script that will turn on and off the autorotate feature on the Windows 8.1 Tablet.  I have the commands below that seem to work, but since I'm modifying registry keys, the script must always be run as an administrator.  Is there another way to go about this that doesn't require admin rights?  Thanks in advance for you assistance!

$regKey = "HKLM:\software\microsoft\windows\CurrentVersion\AutoRotation"
set-itemproperty -path $regkey -name enable -value (0or1)



CMD Window is not closing automatically after the command executes in a batch file - take 2 requested by Mike Laughlin

$
0
0

I have a problem with the DOS window not closing when executing parametric.bat in a script.  Creo Parametric 2.0 is the latest version of CAD software from PTC.  I did not have the issue of the DOS window hanging up with previous versions of the software (Pro/Engineer WF5).  The DOS window does close when Creo Parametric 2.0 is closed.  Or I can manually close the DOS window with Creo Parametric still running.  I would just prefer the DOS window to close after parametric.bat is executed.

Here is the batch file I am running:

@echo off
copy \\maap01\stdpc\Mconfig\WC10_Creo\config.sup "C:\ptc\Creo 2.0\Common Files\M070\text\config.sup"
rem place "rem" on line below
copy \\maap01\stdpc\Mconfig\WC10_Creo\config.pro "C:\ptc\Creo 2.0\Common Files\M070\text\config.pro"
rem place "rem" on line below
copy \\maap01\stdpc\Mconfig\WC10_Creo\creo_parametric_admin_customization.ui "C:\ptc\Creo 2.0\Common Files\M070\text\creo_parametric_admin_customization.ui"
copy \\maap01\stdpc\Mconfig\appearance.dmt "C:\ptc\Creo 2.0\Common Files\M070\graphic-library\appearances\appearance.dmt"
copy \\maap01\stdpc\Mconfig\feature.dat "C:\ptc\Creo 2.0\Common Files\M070\mech\text\licensing\mech\feature.dat"
copy \\maap01\stdpc\Mconfig\config C:\ptc\config
"C:\ptc\Creo 2.0\Parametric\bin\parametric.exe"
@echo off
Exit

One other thing, I am using a shortcut to the batch file and setting the Start in folder to c:\ptc\startup with the Run set as Normal window.  Not sure if that has an effect or not.  I can set the Run to Minimized and at least it is not displayed on the screen.

Need VB script for getting the IIS certification information

$
0
0

Hi guys,

I have totally 1000 IIS servers  2003 & 2008windows and some of the  servers configuredIIS 3rd party Security certificates. I need a script to get the certification information like expiry date & certificate vendor name.



Regards,

SreeM


Having trouble executing powershell scripts through MMC taskpad

$
0
0

I have created a taskpad that executes multiple powershell scripts. Each script uses the selected ActiveDirectory group name attribute as a parameter in the command line options. I can account for groups with spaces in the name by surrounding the $COL<0> parameter with single quotes '$COL<0>', but when I do this the task pad action title will include xml code properties like this:

"title=" tabindex="0">List Members of a group

I can surround the selection in double quotes which fixes the title but then it will treat each word in a group name as a separate parameter which will not work. I have tried multiple ways to escape the quotes but nothing seems to work. The only way I can use this taskpad action properly is with the screwed up title. I have pasted the working command with the messed up title below.

-noexit C:\MCCcode\GroupMembershipList.ps1 '$COL<0>'


Export Available Important Windows updates to Excel File

$
0
0

Hi,

I want to export List of Important Windows updates available in Windows Updates to excel or csv file by using CMD. I don't have any WSUS server deployed. I want to do this by using CMD command. Anyone can help?

Regards,

Riaz Javed

[PS] Cycling through console input history after importing history

$
0
0

Hallo fellow scripters,

What I'm trying to do
I'm trying to add a functionality to PowerShell that allows me to import the command history of a PS User and actually adds these commands not merely to the command history (which I can call with Get-History), but actually introduce them in a way, that allows to user to access them simply by pressing key "Cursor:Up"-Key, as if cycling through the commands entered in the current console session.

What I've tried
First of all, I tried doing things with Add-History and Get-History, like:

Get-History | Export-CSV $Path
Import-CSV $Path | Add-History

This works in adding the entries to the history I can call up with Get-History, however it's not possible to comfortably cycle through the commands.

Looking at the System.Console class, alas, didn't yield any spontaneous inspiration either.

So ... anybody an idea how to pull this off?

Cheers,
Fred


There's no place like 127.0.0.1

Powershell - How do you clear a variable from memory to verify a change that was done?

$
0
0

Hi Everyone,

Does anyone know how to clean up after a variable value that is in memory, in order to view the current change?

Example: i changed a value in the properties of a folder, but when i call onto the variable again, its still giving me the previous value and not the new one. I physically checked so i know that the change has been made.

Encountered unmappable character error in powershell

$
0
0

Hi,

I am using a following cmdlets to get all the machines information from AD of our domain. After running this script i get only few machine around (10 % of total machine in AD).

Error - An error pops up "  Encountered unmappable character error " .

Que - What does these mean? And what more switches i need to add to get all machines ?  

Cmdlet used =  Get-ADComputer -Filter * -Property * | Select-Object Name,OperatingSystem | Export-CSV AllWindows.csv -                        NoTypeInformation -Encoding UTF8

Powershell Version used = 2.0

please let me know if more information is requird.

how to send email using formatted excel worksheet as email body ?

$
0
0

Hi there,

does anybody know how to adjust this below code to use formatted excel worksheet as body content email ?

thanks

Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
$smtpServer = "10.10.10.10."
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "sample@dummyemail.com"
$msg.To.Add("sample@dummyemail.com")
$msg.Subject = "Test"
#$msg.Body = "Test"
$msg.IsBodyHTML = $true
$msg.Body = Get-Content ("test.html")
$smtp.Send($msg)
$att.Dispose()


Viewing all 15028 articles
Browse latest View live


Latest Images

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