Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

Powershell script to change the name of the child node in XML

$
0
0

Hi,

I am trying to replace the XML child node name. Below is the XML that I have. In the below XML there is a Parent and Child tag named as <TrkTraceTxt>. I want to change the name of Parent or Child Tagname to <TraceTxt>. I have written below powershell script and it is not working.

(Get-Content C:\Users\svenk7\Documents\XML\NewFiles\QMI.201305231321.xml) |
Foreach-Object {$_ -replace "</EvntId>`n      <TrkTraceTxt>", "</EvntId>`n      <TraceTxt>"} |
Set-Content C:\Users\svenk7\Documents\XML\NewFiles\QMI.201305231321.xml

 

Any help is really appreciated.

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<EDIDM>
  <TrkTrace>
    <BOLNbr>289017592</BOLNbr>
    <CarrCd>TPQL</CarrCd>
    <TrckgNbr>868644206</TrckgNbr>
    <SAPPONbr>28465, 28466, 28467</SAPPONbr>
    <DestCtryCd>USA</DestCtryCd>
    <OBPrcsId>OUTBOUND</OBPrcsId>
    <TrkTraceTxt>
      <EvntId>ST</EvntId>
      <TrkTraceTxt>BANNER WAREHOUSE (CTW)</TrkTraceTxt>
    </TrackTraceTxt>
  </TrkTrace>
</EDIDM>


remote to start service help!

$
0
0

We need to get two services (name a and b) status from different domain and if service name a and
b stop, we need to start them.  I found out that it is difficult to start two services from different
servers at different domain.
Can anyone help?

thank you!

All Users- with Created dates

$
0
0

What can I use to run in power shell so that it outputs a list of all users in the forest with the dates those users were created.

Some audits are very specific :(

How do you import a scheduled task to a subFolder?

$
0
0

The following script works to import scheduled tasks to the root of the task scheduler, but fails when trying to import to a subfolder.

# Script to import scheduled tasks into new server after being exported from old server
$task_path = ".\*.xml"
$task_user = "lnidaptumptf11\TaskUser"
$task_pass = "mypassword"

$sch = New-Object -ComObject("Schedule.Service")
$sch.connect("localhost")
$folder = $sch.GetFolder("\")
Get-Item $task_path | %{
 $task_name = $_.Name.Replace('.xml', '')
 $task_xml = Get-Content $_.FullName
  $task = $sch.NewTask($null)
  $task.XmlText = $task_xml
  $folder.RegisterTaskDefinition($task_name, $task, 6, $task_user, $task_pass, 1, $null)
}

To see the error, insert these three lines in place of the line: $folder = $sch.GetFolder("\"):

$root = $sch.GetFolder("\")
$root.CreateFolder("sub")
$folder = $sch.GetFolder("\sub")

The sub folder gets created and everything works up to the RegisterTaskDefinition, which gets: Exception calling "RegisterTaskDefinition" with "7" argument(s): "The specified path is invalid. (Exception from HRESULT: 0x800700A1)" even though $folder.Path has a value of "\sub"

Any ideas on how to get around this would be appreciated.

Remove all groups from one user

$
0
0
I need a Powershell script using native or Quest cmdlets to remove ALL groups from a user in AD. Now here's the catch, the user is a member of groups from 3 different trusted domains in a single forest. I can get a script to remove groups from the domain the user resides in but it fails on removing the groups from the other domains. Any suggestions? I see this is can be an issue when a user is a member of cross-domain groups but have not found a solution yet.

What is not explicitly allowed should be implicitly denied

Detect smart files that are "online only"?

$
0
0

Is there a way to enumerate all files in a tree where the availability attribute is "online only"?  I have an issue where a directory that was symbolicly linked in skydrive ended up with a bunch of duplicate files.  I've removed the symlinks, and have a handle on how to clean up the duplicates, but other than looking at the column in explorer, I can't figure out whether a file is a real "offline" file, or just a placeholder for skydrive.  Is there a definitive way to check in a PS script?

remote execution of powershell on azure IAaS VM using C# Code

$
0
0

hi

I have to run some powershell command in remote Azure VM, from my local machine. I can do it in interactive mode, using enter-possession.

But I want to achieve this from a C# code. I tried creating remote runspace as mentioned at -http://msdn.microsoft.com/en-us/library/ee706560(v=vs.85).aspx,using WSManConnectionInfo , but runspace.Open is failing. If I use

AuthenticationMechanism.Basic - it fails with message "The WinRM client cannot process the request. Unencrypted traffic is currently disabled in the client configuration"

For other enum it fails "The following error with errorcode 0x80090311 occurred while using Kerberos authentication: There are currently no logon servers available to service the logon request"

Any pointers, on how to execute Remote Powersehll call from C# code.

My Azure VM have 2 scenario. One VM is in workgroup and second VM is in Active Directory (created in Azure Virtual network).


Thanks


singhhome

Help with Reading XML file

$
0
0

Hey guys,

I am trying to read a XML file from PowerShell and store the data into an array/variable from the tags of the XML.

Here is the XML content.

<?xml version="1.0"?><configuration><URLS><add key="URL0" value="http://server1/index.html" active="True"></add><add key="URL1" value="http://server2/index.html" active="False"></add><add key="URL1" value="http://server2/index.html" active="False"></add><add key="URL3" value="http://server3/index.html" active="False"></add></URLS></configuration>

Here is my PowerShell script and the Output.

$URLS = [xml](Get-Content 'C:\PowerShell Scripts\In-Development\Get-ServiceRegistry\test.xml')
$URLS.configuration.URLS.add[0]
$URLS.configuration.URLS.add[1]
$URLS.configuration.URLS.add[2]
$URLS.configuration.URLS.add[3]


Now, if I modify the XML to this and Run the below PowerShell, I do not get any output. Any Idea why?

<?xml version="1.0"?><configuration><URLS><add key="URL0" value="http://server1/index.html" active="True"></add></URLS></configuration>
$URLS = [xml](Get-Content 'C:\PowerShell Scripts\In-Development\Get-ServiceRegistry\test.xml')
$URLS.configuration.URLS.add[0]



Home directory creation for local user accounts using powershell

$
0
0

Through Computer Management when I create a user, a home directory is created for the same user in the folder C:\Users.I am creating a user through powershell in a remote machine.I am using the following script to create user 

$comp = [ADSI]'WinNT://localhost,computer';
$user = $comp.Create('User', 'account7');
$user.SetPassword('Welcome1');
$user.SetInfo();

The account is getting created. But no home directory is created for this user. How to create a home directory for a user using powershell? Also the user created through GUI is a member of the group 'Users' by default. How to add the user created to the 'Users'  Group.


Close all popups pulled from running a an executable

$
0
0

I have been using PowerShell to automate some functions.  One of them is when I call an exe file to process user accounts.  The exe file produces a popup.  It looks like a form with no options but to use the x in the corner to close.

Is there a command in PowerShell that will close all opened popups?


pfcjt@hotmail.com

Get-WmiObject -class win32_process -ComputerName with multiple where{$_.ProcessName -eq

$
0
0
I am trying to write a script to query multiple servers for multiple processes to get each process thread count.  See below as I have it working for only one process and the output displays below.


Get-WmiObject -class win32_process -ComputerName Server1,Server2,server3,server4 | where{$_.ProcessName -eq "NotePad.exe"} | select-Object ProcessName, Handles, ThreadCount | Sort-Object $_.ProcessName -Descending | ft -auto

ProcessName Handles ThreadCount
----------- ------- -----------
notepad.exe      50           1
notepad.exe      50           1
notepad.exe      50           1
notepad.exe      50           1

Is it possible to do multiple where statements such as {$_.ProcessName -eq "'NotePad.exe','paint.exe','winlogon.exe','excel.exe'"}.  I have tried this it failed.  What is the proper way to querymuliple servers for multiple processes?  I am looking for ideas as I am a little unsure of how to go about the script.

Sample output of what I am wanting.

CSName      ProcessName   Handles ThreadCount
------      -----------   ------- -----------
Server1 notepad.exe     316          25
Server1mspaint.exe    316          25
Server1 winlogon.exe305          21
Server1 excel.exe     305          21

Server2 notepad.exe    5993         404
Server2 mspaint.exe    5736         389
Server2 winlogon.exe    5024         150
Server2 excel.exe    5026         150

Server3 notepad.exe     316          25
Server3mspaint.exe    316          25
Server3 winlogon.exe305          21
Server3 excel.exe     305          21

Server4 notepad.exe    5993         404
Server4 mspaint.exe    5736         389
Server4 winlogon.exe    5024         150
Server4 excel.exe    5026         150

Thank you for your help and time, Robert Jaudon

Modifying Settings on a device with Set-WMIInstance

$
0
0

Hi all,

I am trying to modify a paramter from a FC HBA on a WS2012 host through powershell:

Set-WmiInstance -Path '\\<HOSTNAME>\root\virtualization\v2:Msvm_ExternalFcPort.CreationClassName="Msvm_ExternalFcPort",DeviceID="Microsoft:<GUID>",SystemCreationClassName="Msvm_ComputerSystem",SystemName="<Hostname>"'  -Namespace "root\virtualization\v2" -Class msvm_externalfcport -Argument @{SupportedMaximumTransmissionUnit=131072}

But I got error:

operation is not valid due to the current state of the object.

I am not an PS expert so my question is how I can modify the property "SupportedMaximumTransmissionUnit"?

Thanks for help in advance,

Markus

Ip address comparsion from a text file

$
0
0

I am writing a script to get the Ip addresses for the multiple servers and save it as an array and have a condition to compare it with the IP address saved in the text file and if they match print out the result as pass or fail.

But Its checking one server Ip address with all other IP addresses from the text file not each server IP with only one IP.

For example:-

localhost ip address is 127.0.0.1

Ip.txt = 127.0.0.1, 12.34.56.23, 1.2.4.5

THe output should be

Server   Ip address from the server  Ip address from txt  Result

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

localhost 127.0.0.1                            127.0.0.1                   Pass

dont want the extra IPS in text file to be displayed.

Here is the code.

#$global:Servers = get-content "Server.txt"
$Servers = "localhost"
Function IPAddress($Server)
{
	Try
	{
		$Ip=""	
		$TextIps = "10.0.0.1","10.2.2.4"
        $IpCheck=Test-Connection -Computername $Server -count 1 -ErrorAction Stop | Select IPV4Address
        $Ip=$IpCheck.IPV4Address
		$Ips = "$Ip $Ip "
		Foreach ($Line in $TextIps)
        {   
            $Line = $Line.Trim()
            If($Line.Length -gt 0)
            { 
                If($Ips.Contains($Line))
                {
                   return($Server, $Ip, "$Line", "Pass")
                }
                Else
                {
                   return ($Server, $Ip,"$Line", "Fail")
                }  
           }
		}
	}
	Catch
	{
		return ($Server, "Invalid Output","Invalid Output", "Fail")
	}
}

Foreach ($Srvr in $Servers)
{
   $Ip = IPAddress($Srvr)
   write-output "The server is - $Ip[0]"
   write-output "The actual IP is - $Ip[1]"
   write-output "The IP from text file is - $Ip[2]"
}


I get the output as 

The server is - localhost 127.0.0.1 10.0.0.1 fail[0]
The actual IP is - localhost 127.0.0.1 10.0.0.1 fail[1]
The IP from text file is - localhost 127.0.0.1 10.0.0.1 fail[2]
The result is - localhost 127.0.0.1 10.0.0.1 fail[3]

But i want the output as

Server - localhost

actual IP - 127.0.0.1

IP from text file - 10.0.0.1

Result  - Pass/Fail

[POWERSHELL] Change File Attributes

$
0
0

Hi guys!!

I have a folderwith some files,I do not know how manythey are, what is theirextension or attributes.

I want tomake sure that, if a filehas among the attributes the hidden property(so it can haveeven more properties ), onlyhidden property is removed.

How can i do it ?

if($_.Attributes -eq 'Hidden'){
        $_.Attributes = 'Normal'
    }

this is what i do... but it don't work well

thanks!

A


Using Powershell to send a message to a Syslog server

$
0
0
I need to get-content from a .txt file and search for a specific string and then send the string to a windows syslog server. I have no issue getting the content from the txt file. What I need help with is sending a message to a syslog server. I can't seem to find anyone on the net doing this with powershell. Is this possible in posershell?  

Read in specific line numbers from a text file (very large 1.5GB) using PowerShell

$
0
0

Hi all,

I have a large file (a text file) which is over 1.5GB in size. 

I need to read in specific line numbers from the file, I have a list of exact line numbers I wish to read.

If I use "get-content" to read in all the contents, PowerShell consumes 1.3GB in memory then crashes out.  I don't have enough memory to cope with using get-content to read in all the contents.

Is there any way of doing the following:

       $entry = get %linenumber% from %filename%

Any help is greatly appreciated!

Kathy


Kathleen Hayhurst Senior IT Support Analyst

quick question

$
0
0
any1 knows how to show processes tht uses more than 10 mb, and it shows name of process, PID and quantity of pagined memory by that process

Loïc Potvin IT Student 2013

Does any encrypted password in a text file expire?

$
0
0

I know this sounds crazy, but I have an encrypted password in a file that works for a while then suddenly stops and I have to recreate the file.  And no, the account password itself has not changed.  Is the encrypted PW  based on some timer, for example like when the machine password in the domain changes?

Here is my code to create the file:

$SecurePassword = Read-Host -Prompt "Enter password for PowerShell account" -AsSecureString
$SecureStringAsPlainText = $SecurePassword | ConvertFrom-SecureString
$SecureStringAsPlainText | Out-File ".\PW.txt" -Encoding ASCII

I can then use the that password file (for an account I specify in another script) for weeks without problem.  Then suddenly it fails to work.  I get this error:

ConvertTo-SecureString : Key not valid for use in specified state.

I am using the same account to run the script that I used to create the PW file - so that is not the problem.  The only way to fix this is to recreate the PW file, using the same exact password I used to create it the previous time.  In other words - nothing has changed that I know of.  Same password, same account name, etc.  So I am wondering, is there something on the machine I run the script from that is used to encrypt the PW with, and that "something" changes every couple of months?

My guess is the machine domain account password changes and this breaks the encrypted PW file. Am I right?

Thanks

NK

sent by email HTML poweshell template not showing tool tip

$
0
0

May it is not the righ forum my apology

Thro programatically by powershell I construct HTML string and sent via email. I wanted to show the tool tip. I send this via email and when I open the  email thro outlook the tool tip or any java script functionality not working. If I output the file as HTML then tool tip functionality is working. Any idea?

<p title='$($Entry.IPV4Address)'>$($Entry.ServerName)</p>

Adding multiple users to multiple mailbox

$
0
0

I need assistance in Adding multiple users to multiple mailboxes.

I have the script for Single user and multiple mailboxes

$mbxlist = Get-Content E:\Users\sid\MailBox.txt

ForEach ($mbx in $mbxList ) {

    # Add Send As rights
    Add-ADPermission $mbx -User 'domain\Samaccountname' -Extendedrights 'Send As'

    # Add Full Access rights
    Add-MailboxPermission -Identity $mbx -User 'domain\Samaccountname' -AccessRights FullAccess

Could you please assist?

Viewing all 21975 articles
Browse latest View live


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