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

Problems with getting output to csv instead of text file

$
0
0

Hi,


I recently started exploring powershell, thought i've been a fan of vba for a long time. So i found a script here for finding cluster resource status for one or multiple windows boxes which i found interesting and started to tweak it so i can perform more function as per the needs. The problem i found was firstly i cant run the powershell from a noncluster or a desktop which i kind of figured on how to work around it and secondly instead of output to txt file i moved to getting output in csv so i can add some vba macro to do multiple functions. Now while the output was in txt then everything was good but since i changed it to csv i just get the results of the last box in the list. So basically the output just saves data of  the last server from my list. I read somewhere that with upgrading to powershell 3.0 i can use append parameter which can resolve this issue. But is there any other way to get the desired results without updating the powershell version.

Below is the updated code i'm using

$SCRIPT_PARENT   = Split-Path -Parent $MyInvocation.MyCommand.Definition

$File = ($SCRIPT_PARENT + "\Cluster_Resource_Output.txt")
$FileCSV = ($SCRIPT_PARENT + "\OutputinCsv.csv")
$ClusterList = ($SCRIPT_PARENT + "\ClusterList.txt")
Clear-Content $File, $FileCSV


    
    $Clusters = Get-Content $ClusterList # Cluster Names

    
    Write-Host "Please wait... Collecting Cluster Resources details... " -foregroundcolor "magenta" -backgroundcolor "yellow"
    Write-Host "$Clusters" -ForegroundColor Green
    foreach($Cluster in $Clusters) 
    {
    $clugm = gwmi -ComputerName $cluster -Authentication PacketPrivacy -Namespace "root\mscluster" -Class MSCluster_Resource | add-member -pass NoteProperty Cluster $cluster | 
    add-member -pass ScriptProperty Node `
    { gwmi -namespace "root\mscluster" -computerName $this.Cluster -Authentication PacketPrivacy -query "ASSOCIATORS OF {MSCluster_Resource.Name='$($this.Name)'} WHERE AssocClass = MSCluster_NodeToActiveResource" | Select -ExpandProperty Name } |
    add-member -pass ScriptProperty Group `
    { gwmi -ComputerName $this.Cluster -Authentication PacketPrivacy -Namespace "root\mscluster" -query "ASSOCIATORS OF {MSCluster_Resource.Name='$($this.Name)'} WHERE AssocClass = MSCluster_ResourceGroupToResource" | Select -ExpandProperty Name } 
$clugm | Select-Object cluster, Node, Name, @{n='State';e={if ($_.State -eq 2) {'Online'} else {'Offline'} }}  | Export-Csv $FileCSV -notypeinformation #Output command >> Into CSV

#$clugm | select cluster, Name, Node, @{n='State';e={if ($_.State -eq 2) {'Online'} else {'Offline'} }} | Ft -a | Out-File $File -Append #Output command >> Into textfile
    }

$wshell.Popup("Completed..... Please run the verification", 0, "Cluster Resource", 48+4)

Thanks.


Help with windows powershell - reading text file & manipulating the data

$
0
0

Hello,

I'm new to windows power shell & need your help/expertise in formatting the below *.txt file.

Could you please provide me with a sample powershell script which can accomplish the below request. Thank you so much for your help in advance.

<name>,<ticker>,<date>,<open>,<high>,<low>,<close>,<vol>,<oi>
GOOG 10-Jan-2014 1165 Put,GOOG140110P01165000,20140114,32.9,32.9,32.9,32.9,0,0
GOOG 10-Jan-2014 1170 Put,GOOG140110P01170000,20140114,40.87,40.87,40.87,40.87,0,0
GOOG 10-Jan-2014 1180 Put,GOOG140110P01180000,20140114,54.8,54.8,54.8,54.8,0,0
GOOG 10-Jan-2014 1190 Put,GOOG140110P01190000,20140114,50.9,50.9,50.9,50.9,0,0
GOOG 10-Jan-2014 1200 Put,GOOG140110P01200000,20140114,60.9,60.9,60.9,60.9,0,0
GOOG 10-Jan-2014 1300 Put,GOOG140110P01300000,20140114,157.8,157.8,157.8,157.8,0,0
PCLN 10-Jan-2014 1170 Call,PCLN140110C01170000,20140114,0.05,0.05,0.05,0.05,0,873
PCLN 10-Jan-2014 1172.5 Call,PCLN140110C01172500,20140114,0.01,0.01,0.01,0.01,0,136
PCLN 10-Jan-2014 1175 Call,PCLN140110C01175000,20140114,0.15,0.15,0.15,0.15,0,666
PCLN 10-Jan-2014 1177.5 Call,PCLN140110C01177500,20140114,0.05,0.05,0.05,0.05,0,174
PCLN 10-Jan-2014 1180 Call,PCLN140110C01180000,20140114,0.02,0.02,0.02,0.02,0,896
PCLN 10-Jan-2014 1182.5 Call,PCLN140110C01182500,20140114,0.07,0.07,0.07,0.07,0,138
PCLN 10-Jan-2014 1185 Call,PCLN140110C01185000,20140114,0.05,0.05,0.05,0.05,0,842
PCLN 10-Jan-2014 1187.5 Call,PCLN140110C01187500,20140114,0.05,0.05,0.05,0.05,0,36
PCLN 10-Jan-2014 1190 Call,PCLN140110C01190000,20140114,0.01,0.01,0.01,0.01,0,909
PCLN 10-Jan-2014 1192.5 Call,PCLN140110C01192500,20140114,0.2,0.2,0.2,0.2,0,88
PCLN 10-Jan-2014 1195 Call,PCLN140110C01195000,20140114,0.04,0.04,0.04,0.04,0,835
PCLN 10-Jan-2014 1197.5 Call,PCLN140110C01197500,20140114,0.25,0.25,0.25,0.25,0,22
PCLN 10-Jan-2014 1200 Call,PCLN140110C01200000,20140114,0.04,0.04,0.04,0.04,0,1073
PCLN 10-Jan-2014 1205 Call,PCLN140110C01205000,20140114,0.05,0.05,0.05,0.05,0,434
PCLN 10-Jan-2014 1210 Call,PCLN140110C01210000,20140114,0.03,0.03,0.03,0.03,0,346
PCLN 10-Jan-2014 1215 Call,PCLN140110C01215000,20140114,0.05,0.05,0.05,0.05,0,288

Z 22-Feb-2014 80 Call,Z140222C00080000,20140114,11.5,11.5,11.5,11.5,4,335
Z 22-Feb-2014 85 Call,Z140222C00085000,20140114,7.83,7.83,7.83,7.83,21,523
Z 22-Feb-2014 90 Call,Z140222C00090000,20140114,5.74,5.74,5.74,5.74,42,422
Z 22-Feb-2014 95 Call,Z140222C00095000,20140114,3.89,3.89,3.89,3.89,37,389
Z 22-Feb-2014 100 Call,Z140222C00100000,20140114,2.54,2.54,2.54,2.54,44,576
Z 22-Feb-2014 105 Call,Z140222C00105000,20140114,1.62,1.62,1.62,1.62,3,117
Z 22-Feb-2014 110 Call,Z140222C00110000,20140114,0.99,0.99,0.99,0.99,15,215

The ticker symbol in above file is max of 19 bytes. The software I use cannot convert this data, as it has a restriction of 14 bytes for ticker field.

I want to reduce the ticker field to 14 bytes using below logic & rewrite the modified symbol in the same column/file.

GOOG140110P01165000 - Ticker explanation is as shown below

Symbol : GOOG  ( 4 bytes)

Year : 14 ( 2 bytes)

Month : 01 ( 2 bytes)

Date : 10 ( 2 bytes)

Call/Put : C or P ( 1 byte) 

Strike : 01165 ( 5 bytes )

Strike (Decimal) : 000 ( 3 bytes)

Since they total to 19 bytes,my requirement is to bring down the ticker field size to 14 bytes using below formula.

1) Reduce year field to 1 byte i.e. 14 can be kept as 4

2) Strike ( Decimal) can be reduced to 1 byte ( drop the ending 2 bytes)

3) Month column ( 2 bytes) & call/put ( 1 byte) can be reduced to 1 byte ( saving of 2 bytes) by replacing 01 & C combination with A , 01 & P combination with B so on as mentioned below.

Month( 2 bytes)Call/Put ( 1 byte)Replace with
01CA
01PB
02CC
02PD
03CE
03PF
04CG
04PH
05CI
05PJ
06CK
06PL
07CM
07PN
08CO
08PP
09CQ
09PR
10CS
10PT
11CU
11PV
12CW
12PX

So the modified ticker will look like GOOG4B10011650

GOOG - symbol

4 - year which is 2014 in this case 

B- 01 ( jan) & Put (P) is replaced with letter B

10 - Date

01165 - Strike price

0 - Decimal portion of strike price

The output file should look like below.

<name>,<ticker>,<date>,<open>,<high>,<low>,<close>,<vol>,<oi>
GOOG 10-Jan-2014 1165 Put,GOOG410B011650,20140114,32.9,32.9,32.9,32.9,0,0

Thank you for your inputs with this request.

Regards,

Aimforsky

Listing ADusers with only listed properties. But ExtensionAttributes don't list properly

$
0
0

Im trying to make a csv file with all users and theyr most important properties. This works, but ExtensionAttributes won't show.

Import-module Activedirectory
$date = get-date
$nicedate = [string]$date.day + "_" + [string]$date.month + "_" + [string]$date.year
$filename = "Aduser" + $nicedate + ".csv"

Get-Aduser -filter * -properties extensionAttribute1,extensionAttribute2,extensionAttribute3,extensionAttribute4,extensionAttribute5,extensionAttribute6,extensionAttribute7,extensionAttribute8,extensionAttribute9,extensionAttribute10,SAMAccountname,GivenName,SurName,Displayname,Enabled,AccountExpirationDate,PasswordExpired,PasswordNeverExpires,LastLogonDate,Created,Description,mail,HomeDirectory,HomeDrive,ManagedObjects,CanonicalName,DistinguishedName,cn,company,department,Mobile,TelephoneNumber,facsimileTelephoneNumber,physicalDeliveryOfficeName,POBox,title,wWWHomePage,Manager | export-csv $filename -Encoding "Unicode"

Powershell Script to get "hidden" shared folder and NTFS permission from list of servers

$
0
0

Hi friends,

I found a script here to get shared folders and NTFS permissions, but it is not working with "hidden" shared folders on Windows 2008. Is there a way to get those permissions ?

Thank You!

Get-ADGroupMember -recursive Show Groupnames

$
0
0

I'm new to Powershell and im trying to get a list of the Members of some AD-Groups. Each Group is related to two other Groups for Read and Change permissions. Like FS101_EXAMPLE has two members wich are FS101_EXAMPLE_C and FS101_EXAMPLE_R

So far I've got the following Code:

import-module ActiveDirectory

$GRP = "Groupname"

Get-ADGroupMember $GRP -recursive | select objectclass,name | export-csv C:\Scripts\Exports\$(get-date -f yyyy-MM-dd-hh-mm-ss)-$GRP.txt –NoTypeInformation -Encoding UTF8

If i scan on "FS101_EXAMPLE" it works and i get a list of all Members of FS101_EXAMPLE_C and FS101_EXAMPLE_R but i should know how's in wich group.

How can I get a List with the Groupnames on it?

Powershell - Forest.SetSelectiveAuthenticationStatus Method - Not working

$
0
0

I have written a script to create an Active Directory Trust. The trust creation works fine, but when I attempt to set the selective authentication it does not work.

$SourceContext = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext("Forest","mydomain.com")

$SourceDomainOBJ = [System.DirectoryServices.ActiveDirectory.Forest]::GetForest($SourceContext)

$SourceDomainOBJ.SetSelectiveAuthenticationStatus("otherdomain.com", $false)

$SourceDomainOBJ.GetSelectiveAuthenticationStatus("otherdomain.com")

The code executes and returns what is expected, but if you open he actual trusts from Active Directory Domains and Trusts it hasn't made the change.

Any ideas why it wouldn't be applying?

Using setx.exe while using PowerShell Remoting

$
0
0

Hi,

I am using the Invoke-Command with a Session to execute some installers on a remote computer. This works fine but for some reason setx.exe (to set Environment Variables) will not work as expected. When I create a new computer Environment Variable I am using the following command which works great:

$process = Invoke-Command -Session $Session -ScriptBlock {
            $result = Start-Process -FilePath "setx.exe" -ArgumentList 'MY_PATH "C:\Program Files\MyApplication" /M' -Wait -PassThru -Verb RunAs;
        }

However, when I try to edit a current Environment Variable like PATH it does not work. I use the following code:

$process = Invoke-Command -Session $Session -ScriptBlock {
            $result = Start-Process -FilePath "setx.exe" -ArgumentList 'PATH "%PATH%;%MY_PATH%\bin" /M' -Wait -PassThru -Verb RunAs;
        }

When I login on the remote computer and use "echo %PATH%" from the command prompt it prints the following:

%PATH%;%MY_PATH%

While I was expecting:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\MyApplication\bin

Any idea why I cannot append with this way to an already existing Environment Variable? The commands work locally when I execute it from the command prompt.



Set userpath to homefolder using powershell

$
0
0

I've created a partition " H:\ "  with several folders for different usergroups.
One of these groups is ICT.
When i run the following script the path for the users is set to the correct folder

Get-ADUser -filter * -SearchBase "OU=All_ICT,DC=LUMO,DC=local" | 
% { Set-ADUser $_ -HomeDrive "H:" -HomeDirectory ("\\ServerLUMO\ICT_share\" + $_.SamAccountName) }

The problem is that this path isn't applied. When i go to the usersprofile in AD and i backspace one caracter and retype it i can click " Apply" and it works like a charm....

My question is, how can i achieve this in the powershellscript?


The term 'new-object' is not recognized as the name of a cmdlet, function, script file, or operable program.

$
0
0

I have a script that runs well the vast majority of the time.  On occasion I get an exception.  I would appreciate any insight as to why it fails on occasion.  I can't understand why the new-object cmdlet wouldn't be recognized:

Message: The term 'new-object' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Source: System.Management.Automation

StackTrace:    at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandTypes commandTypes, SearchResolutionOptions searchResolutionOptions, CommandOrigin commandOrigin, ExecutionContext context)
   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)
   at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)
   at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

Here is the script I am running:

param([string]$endpoint)
$ErrorActionPreference = "Stop";
try
{
 [System.Reflection.Assembly]::LoadFile("D:\dotNET_Apps\dotNETCOExBatch\DotNETCOExBatch\bin\DotNETCOExBatch.dll")
 $schedule = new-object DotNETCOExBatch.CallService
 $reply = $schedule.CallWebService($endpoint)
 if ($reply)
 {
  $host.setshouldexit(0)
 }
 else
 {
  $host.setshouldexit(8)
 }
}
Catch
{
 $nl = [Environment]::NewLine
 $evt=new-object System.Diagnostics.EventLog("Application")
 $evt.Source="BatchPowerShell"
 $infoevent=[System.Diagnostics.EventLogEntryType]::Error
 $batchException = $_.Exception
 $logMessage = " "  
 while ($batchException)
 {
  $exMessage = $batchException.Message
  $exStackTrace = $batchException.StackTrace
  $exSource = $batchException.Source
  $logMessage += "$nl $nl Message: $exMessage $nl $nl Source: $exSource $nl $nl StackTrace: $exStackTrace" 
  $batchException = $batchException.InnerException 
 }
 $evt.WriteEntry(" Error starting or process cancellation of $endpoint $logMessage",$infoevent)
 $host.setshouldexit(15)
}

how to fix this is who in the picture ?

$
0
0

I use this script in server 2008 R2 for Storing Windows Event Viewer Output in a SQL Server table with PowerShell :

foreach ($server in Get-Content c:tempservers.txt) { $variable = ( Get-EventLog -ComputerName $server -LogName Security -After “22-08-2011“ | select @{Expression={$($server) };Label = “ComputerName“} ,index,TimeGenerated,EntryType,Source,InstanceID,Message ) $valuedatatable = Out-DataTable -InputObject $variable Write-DataTable -ServerInstance YourServer -Database YourDatabase -TableName EventError -data $valuedatatable 

the link : https://www.simple-talk.com/blogs/2011/08/31/storing-windows-event-viewer-output-in-a-sql-server-table-with-powershell/


Count mail items and get size of each in exchange 2003 mailbox?

$
0
0

I'm trying to get into a mailbox via powershell and see if:

 

1.  I can list all emails within the past year.

2.  Get the size of each mail item.


Anthony

Takes forever to pass the output

$
0
0

Is there anything wrong with these codes? I am trying to list the event ID 1074. It runs well locally but not on the remote pc. It takes more than 10 mins.

Function whoshutdown($ComputerName = ".")
{
$date=(Get-Date).AddDays(-7)

Get-Eventlog -Logname System -computer $ComputerName -After $date `
| Where-Object {$_.EventId -eq ’1074′} `
| Format-list  TimeWritten,EventID, Message | more
}


Why does Invoke-Command fail with multiple-paramater command?

$
0
0

$robocopy = ("$env:SystemRoot\System32\robocopy.exe ") $source = '"\\MYSERVER\netlogon\MyFolder\MyStuff" ' $destination = '"C:\MyFolder\MyStuff" ' $options = "/MIR R:1 W:1 /XJ " $excFiles = '/XF "test.txt" today.doc" ' $excDirs = '/XD "test" "today" ' $log = '/NFL /NDL /LOG:"C:\mycopy.log"' Write-Host "------------------------------------" $robocopy $source $destination $options $excFiles $excDirs $log Write-Host "------------------------------------" $command = $robocopy+$source+$destination+$options+$excFiles+$excDirs+$log $command Invoke-Command $command

------------------------------------
C:\Windows\System32\robocopy.exe
"\\US0TE0DC0A01\netlogon\MyFolder\MyStuff"
"C:\MyFolder\MyStuff"
/MIR R:1 W:1 /XJ
/XF "test.txt" today.doc"
/XD "test" "today"
/NFL /NDL /LOG:"C:\mycopy.log"
------------------------------------
C:\Windows\System32\robocopy.exe "\\MYSERVER\netlogon\MyFolder\MyStuff" "C:\MyFolder\MyStuff" /MIR R:1 W:1 /XJ /XF "test.txt" today.doc" /XD "test" "today" /NFL /NDL /LOG:"C:\my
copy.log"
Invoke-Command : Parameter set cannot be resolved using the specified named parameters.
At C:\invokeRobocopy.ps1:20 char:1
+ Invoke-Command $command
+ ~~~~~~~~~~~~~~~~~~

The command appears to be quoted properly for execution on the command line.

How do I format these multiple parameters for Invoke-Command?





 

Need to use variable Local Paths

$
0
0

Hello,

I have a the following snippit, how can I add a variable to the bolded UNC path C:\TEMP\GPO\source\5\{231A178D-DC6C-4186-9575-9C64F07DA5B5}\gpreport.xml

Those paths will change a lot in my scenerio. Thank you.

$file_server = Read-Host "Enter the file server IP address"


(Get-Content "C:\TEMP\GPO\source\5\{231A178D-DC6C-4186-9575-9C64F07DA5B5}\gpreport.xml") | ForEach-Object { $_ -replace "99.999.999.999", "$file_server" } | Set-Content "C:\TEMP\GPO\source\5\{231A178D-DC6C-4186-9575-9C64F07DA5B5}\gpreport.xml"

(Get-Content "C:\TEMP\GPO\source\5\{231A178D-DC6C-4186-9575-9C64F07DA5B5}\Backup.xml") | ForEach-Object { $_ -replace "99.999.999.999", "$file_server" } | Set-Content "C:\TEMP\GPO\source\5\{231A178D-DC6C-4186-9575-9C64F07DA5B5}\Backup.xml"

(Get-Content "C:\TEMP\GPO\source\5\{231A178D-DC6C-4186-9575-9C64F07DA5B5}\DomainSysvol\GPO\User\Documents & Settings\fdeploy1.ini") | ForEach-Object { $_ -replace "99.999.999.999", "$file_server" } | Set-Content "C:\TEMP\GPO\source\5\{231A178D-DC6C-4186-9575-9C64F07DA5B5}\DomainSysvol\GPO\User\Documents & Settings\fdeploy1.ini"

(Get-Content "C:\TEMP\GPO\source\5\{231A178D-DC6C-4186-9575-9C64F07DA5B5}\DomainSysvol\GPO\User\Preferences\Drives\drives.xml") | ForEach-Object { $_ -replace "\\99.999.999.999", "\\$file_server" } | Set-Content "C:\TEMP\GPO\source\5\{231A178D-DC6C-4186-9575-9C64F07DA5B5}\DomainSysvol\GPO\User\Preferences\Drives\drives.xml"

(Get-Content "C:\TEMP\GPO\source\5\{231A178D-DC6C-4186-9575-9C64F07DA5B5}\DomainSysvol\GPO\User\Preferences\files\files.xml") | ForEach-Object { $_ -replace "\\99.999.999.999", "\\$file_server" } | Set-Content "C:\TEMP\GPO\source\5\{231A178D-DC6C-4186-9575-9C64F07DA5B5}\DomainSysvol\GPO\User\Preferences\files\files.xml"


How to append data in xml

$
0
0

I have below script which will create xml with data.

======================================================================

# Set the File Name
$filePath = "e:\Report2.xml"
 
# Create The Document
$XmlWriter = New-Object System.XMl.XmlTextWriter($filePath,$Null)
 
# Set The Formatting
$xmlWriter.Formatting = "Indented"
$xmlWriter.Indentation = "4"
 
# Write the XML Decleration
$xmlWriter.WriteStartDocument()
 
# Set the XSL
$XSLPropText = "type='text/xsl' href='style.xsl'"
$xmlWriter.WriteProcessingInstruction("xml-stylesheet", $XSLPropText)
 
# Write Root Element
$xmlWriter.WriteStartElement("Execution")
 
# Write the Document
$xmlWriter.WriteStartElement("ExecutionStarted")
$xmlWriter.WriteAttributeString("Date",$date)
$xmlWriter.WriteStartElement("Environments1")
$xmlWriter.WriteStartElement("Colors")
$xmlWriter.WriteAttributeString("Red","21")
$xmlWriter.WriteAttributeString("Yellow","14")
$xmlWriter.WriteAttributeString("Green","18")
$xmlWriter.WriteEndElement()# Closing Colors
$xmlWriter.WriteEndElement() # Closing environments1


$xmlWriter.WriteStartElement("Environments2")
$xmlWriter.WriteStartElement("Names")
$xmlWriter.WriteAttributeString("John","21")
$xmlWriter.WriteAttributeString("Mike","14")
$xmlWriter.WriteAttributeString("Alex","18")
$xmlWriter.WriteEndElement()# Closing Name
$xmlWriter.WriteEndElement() # Closing environments2


$xmlWriter.WriteEndElement() # Closing executionstarted
# Write Close Tag for Root Element
$xmlWriter.WriteEndElement() # Closing RootElement
 
# End the XML Document
$xmlWriter.WriteEndDocument()
 
# Finish The Document
$xmlWriter.Finalize
$xmlWriter.Flush()
$xmlWriter.Close()

======================================================================

here is the xml data

<?xml version="1.0"?>
<?xml-stylesheet type='text/xsl' href='style.xsl'?>
<Execution>
    <ExecutionStarted Date="">
        <Environments1>
            <Colors Red="21" Yellow="14" Green="18" />
        </Environments1>
        <Environments2>
            <Names John="21" Mike="14" Alex="18" />
        </Environments2>
    </ExecutionStarted>
</Execution>

==================================================================

I want to append new data e.g "Environments3" shown below. what will be the code for this?

<?xml version="1.0"?>
<?xml-stylesheet type='text/xsl' href='style.xsl'?>
<Execution>
    <ExecutionStarted Date="1">
        <Environments1>
            <Colors Red="21" Yellow="14" Green="18" />
        </Environments1>
        <Environments2>
            <Names John="21" Mike="14" Alex="18" />
        </Environments2>
    </ExecutionStarted>
   <ExecutionStarted Date="2">
        <Environments3>
            <Names blue="21" black="14" cyan="18" />
        </Environments3>
   </ExecutionStarted>
</Execution>


Thanks,



Copy-Item using Windows PowerShell Multithreading?

$
0
0

Hello all,

I need to figure out a way to copy a 500MB .zip file to about 400 servers in parallel.
Until now, I have been using the ForEach () method. But, I'd like to use a parallel method so that I can copy 500MB to multiple servers at once, to lower the total copy time.
I have been reading that I can do this using PowerShell Jobs. What is the best way to do this?

Here is my code using ForEach:

$servers = Get-Content C:\servers.txt

ForEach ($server in $servers)
{
Copy-Item -Path C:\500MB.zip -Destination "\\$server\c$\" -Verbose
}
Any help very much appreciated.

Server2012: Set-ClusterScheduledTask + "Run with highest Priviledges" - ???

$
0
0

Hey there,

I'm trying to fix a script we have to trim VSS copies on our Fileserver which is a Serve 2012 Failover Cluster. 

This has worked in the past, however I think it got messed up when I changed the schedule from a Win8.1 workstation. Anyway, I've lost the "Run with highest priviledges" flag on the task and I can't quite seem to find a way to set it back. Judging by the documentation, if I were able to set a scheduled task principal I could use the -RunLevel switch, but apparently that's not supported with the ClusteredScheduledTasks. Also, it appears that if the settings of the task are set to volatile=true, that enables highest privs, but I can't find a way to do that via the Powershell cmdlets. 

Anyone have any ideas? 

Powershell parsing question

$
0
0

Hi all,

I'm trying to parse the below data and write it into a CSV file. I need to gather all the bolded data and the script that I have allows me to get the first 16 items (which is  exactly what i need) however i'm missing one vital piece of information and that is the enclosure name (hilighted in bold and underlined). I'm not sure how i can add it. Any help would be appreciated and thanks in advanced. 

--Gaz  


HP BladeSystem Onboard Administrator
(C) Copyright 2006-2012 Hewlett-Packard Development Company, L.P.

INFWPSC04A [SCRIPT MODE]> show server names


Bay Server Name                   Serial Number   Status   Power   UID Partner
--- ----------------------------- --------------- -------- ------- --- -------
  1 304XUSE02                USEECB      OK       On      Off
  2 305XUSE02                USEECJ      OK       On      Off
  3 306XUSE02                USEECL      OK       On      Off
  4 308XWRL11                USEECD      OK       On      Off
  5 304XUSE03                USEECP      OK       On      Off
  6 305XUSE03                USEECH      OK       On      Off
  7 306XUSE03                USEECN      OK       On      Off
  8 308XWRL12                USEECA      OK       On      Off
  9 304XUSE04                USEECK      OK       On      Off
 10 305XUSE04                USEECM      OK       On      Off
 11 306XUSE04                USEECF      OK       On      Off
 12 100XHLD07                USEECR      OK       On      Off
 13 304XUSE05                USEECE      OK       On      Off
 14 305XUSE05                USEECS      OK       On      Off
 15 306XUSE05                USEEC9      OK       On      Off
 16 100XHLD08                USEECC      OK       On      Off
Totals: 16 server blades installed, 16 powered on.

INFWPSC04A [SCRIPT MODE]>

show server names


HP BladeSystem Onboard Administrator
(C) Copyright 2006-2011 Hewlett-Packard Development Company, L.P.

INFWPSC02A [SCRIPT MODE]> show topology


Rack Topology (top-down)


Rack UUID: ALL5
Rack Name:11


         Enclosure Name           Status  Local   IP Address         UUID
-------------------------------- -------- ----- --------------- --------------
INFWPSC02                     OK       Yes   10.1.1.1         E121ALL5 

INFWPSC02A [SCRIPT MODE]>
show topology

PowerShell Script

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

$vara = get-childitem -name "D:\ServerInfo\"

$varb = foreach ($q in $vara) {gc "D:\ServerInfo\$q"}

#loop through the text and assign the result to commaSeparatedInfo
$commaSeparatedInfo = foreach($line in $varb){
    #if the line starts with a number or any number of spaces followed by a number, process it, otherwise we'll ignore it
    if($line -match "^\s*\d"){
        #remove the leading spaces if there are any
        $line = $line -replace "^\s*"
        #replace any remaining spaces between the text with a comma and emit the line (should have csv at this point)
        $line -replace "\s+",","
    }
}
#create the header to parse the csv as an array
$header = "Bay","ServerName","SerialNumber","Status","Power","UID","Partner"
#convert the csv into objects with convertfrom-csv using the header
$parsedInfo = $commaSeparatedInfo|convertfrom-csv -Header $header
#select out just the fields that you want.
$EncData = $parsedInfo|select Bay,ServerName,SerialNumber

System requirments to using PowerShell's New-SmbShare cmdlet?

$
0
0

Can anyone tell me if there are system requirments to using PowerShell's New-SmbShare cmdlet?  I'm trying to create a script that will create the folder, create the share, create groups based on the share name, and assign the appropriate NTFS persmissions and share permissions.  When I try to run New-SmbShare on my Windows 8, I get the following error:

New-SmbShare : Access is denied. 
At line:1 char:1+ New-SmbShare -Name ISOs -Path C:\Shares\ISOs -FolderEnumerationMode AccessBased  ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : PermissionDenied: (MSFT_SMBShare:ROOT/Microsoft/Windows/SMB/MSFT_SMBShare) [New-SmbShare], CimException+ FullyQualifiedErrorId : Windows System Error 5,New-SmbShare

I'm an administrator on the laptop, and local Administrators have Full Control at the NTFS level.

Thanks!

PowerShell - Searching Excel and replacing text

$
0
0

Hi all,

I am trying to figure out how to loop this script so that it replaces all the text that I am searching for in my Excel file.  I am able to get it to run but it only replaces the text in the first column and then ends. Any help is appreciated and thanks in advance.

-Gaz

$File="D:\test.xlsx"

# Setup Excel, open $File and set the the first worksheet
$Excel=New-Object-ComObjectExcel.Application
$Excel.visible=$true
$Workbook=$Excel.workbooks.open($file)
$Worksheets=$Workbooks.worksheets
$Worksheet=$Workbook.Worksheets.Item(1)

$SearchString="TEMP# This is the value that I will be searching for

$Range=$Worksheet.Range("A1").EntireColumn
$Search=$Range.find($SearchString)

$Search.value()="ABSENT"# This is the value that i want to replace the text with.

Viewing all 21975 articles
Browse latest View live


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