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

How to get the output of a java program run through Powershell on remote machines

$
0
0

Hi,

I have a java program which has to be executed in 10 remote machines at a time. I used invoke-parallel for that, but I'm not able to get it's output back. Is there anyway to get it back from all the machines?

My powershell script is:

$remoteMachineList = "Machine1","Machine2","Machine3"
Invoke-Parallel -InputObject $remoteMachineList{
    Set-Item -Path Env:CLASSPATH -Value C:\MassiveQuiz"CLASSPATH = $Env:CLASSPATH"
    .\java.exe -classpath $Env:CLASSPATH MyClass
    }
where MyClass is the java class.

Thanks in advance :)

Aravind


BREAK in nested Loops behaves weird

$
0
0

I found a weird behavior of BREAK in nested loops.

Here my test-code:

#1
:OuterLoop ForEach ($x In 1..3) {
   'x' + $x
   :InnerLoop ForEach ($y In 1..8) {
      ' y' + $y
      If ($y -ge 5) {
         Break InnerLoop
      }
   }
}


#2
:OuterLoop ForEach ($x In 1..3) {
   'x' + $x
   :InnerLoop ForEach ($y In 1..8) {
      ' y' + $y
      If ($y -ge 5) {
         Break NoLoop
      }
   }
}

#1 breaks the inner loop as expected.

#2 breaks the outer loop though I specified the not-existing label "NoLoop" for BREAK. I would expect an error or warning. At the worst I would expect that the non-existing label is ignored and the OUTER loop breaks.

Does anyone see some logic behind this behavior?

Import empty values from csv

$
0
0

Hi!

My problem is, that if the second variable ($initials,$givenname etc..) is null (these are coming from a csv and there is no value for that column) the If statement return TRUE.

So:

$Attribs.initials empty

$initials null

For me it is equal(should be), but IF condition says it not equal.

The script:

$Attribs = Get-ADUser -Identity $Name -Properties "initials","sn","givenname","displayname","company","department","title","employeenumber","description"

if (($Attribs.initials -ne $initials) -or
($Attribs.sn -ne $sn) -or
($Attribs.givenname -ne $GivenName) -or
($Attribs.displayname -ne $DisplayName) -or
($Attribs.company -ne $Company) -or
($Attribs.department -ne $Department) -or
($Attribs.title -ne $Title) -or
($Attribs.employeenumber -ne $EmployeeNumber) -or
($Attribs.description -ne $Description))
{

}
Please help




Why does my WPF UI Freezes when trying to update ListBox?

$
0
0

I am having problems when trying to use Register-EngineEvent to update a listBox in a different runspace. (Line 32)http://pastebin.com/JuY5KfP4[1]

When the Search button is pressed it triggers an event to write 'Event Happened' to console and it should return 'Test' to the UI ListBox. However, the part of the event that should be updating the ListBox is causing the UI to freeze.

I got a single thread version of this to work, however, my UI would freeze while doing a complex search (in my case a Get-ChildItem on a big directory). This is how I came across using different Runspace's. http://learn-powershell.net/2012/10/14/powershell-and-wpf-writing-data-to-a-ui-from-a-different-runspace/[2]

I have found someone with a very similar problem: http://stackoverflow.com/questions/23699507/why-does-this-code-freeze-my-wpf-ui[3] but I could not find a solution or an explanation.

PS version: 4.0

This is new territory to me so please forgive me if I use the wrong terminology. 

Thank you for your time.


Question about filtering

$
0
0

hi all,
first of all happy new year!!!
I'm having list of sequences in c.txt 

Sequence are shown below (which i need from SystemActivityLogDetailed.txt)

Sequence: S8_Win8_50Inj3Dov0.9 - Started injection 1
Sequence: S8_Win8_50Inj3Dov0.9 - Completed injection 1
Sequence: S8_Win8_50Inj3Dov0.9 - Started injection 21
Sequence: S8_Win8_50Inj3Dov0.9 - Completed injection 21
Sequence: S8_Win8_50Inj3Dov0.9 - Started injection 22
Sequence: S8_Win8_50Inj3Dov0.9 - Completed injection 22
Sequence: S8_Win8_50Inj3Dov0.9 - Started injection 23
Sequence: S8_Win8_50Inj3Dov0.9 - Completed injection 23
Sequence: S8_Win8_50Inj3Dov0.9 - Started injection 24
Sequence: S8_Win8_50Inj3Dov0.9 - Completed injection 24
Sequence: S8_Win8_50Inj3Dov0.9 - Started injection 25
Sequence: S8_Win8_50Inj3Dov0.9 - Completed injection 25
Sequence: S8_Win8_50Inj3Dov0.9 - Started injection 26
Sequence: S8_Win8_50Inj3Dov0.9 - Completed injection 26
Sequence: S8_Win8_50Inj3Dov0.9 - Completed injection 50
Sequence: S8_Win8_50Inj3Dov0.9 - Started injection 50

I've executed this string but the result is not the one expected. M getting the output with below Script

$pwd = "D:\Machines"
$servers = @(gc $pwd\MCN.txt)
$c = @(gc $pwd\c.txt)

foreach ($server in $servers)

{
 Set-ExecutionPolicy Unrestricted -Force
}

foreach ($server in $servers)
{

    foreach ($p in $c)
    {
        Select-String -Path \\$server\d$\"$server"\SystemActivityLogDetailed.txt -Pattern "$p" | select * | Out-File d:\OverheadSheet.txt -Append -Force
        Get-
    }
}

But the thing is that m also getting values for injection 10,11,12, 13,........till 19.

Which i don't need. How can i modify my Script to get only the desired values (i.e injections 1,21,22,23,24,25,50).



String concatenation in variable

$
0
0

Hello, I have a weird issue with variable concatenation… I wrote a script to create an Exchange distribution list. In my script, I have 2 param : the name of the list to create and the member to add.

In my distribution list, I always want a specific address + the one that was passed in parameters. What I want to do is add adressToAdd@MYDOMAIN.qc.ca to the $member variable (see code below…)

Param(
    [string]$cmdDistributionListName,
    [string]$cmdMember
)


function CreerListeDistributionApple {
    param ([string]$distributionListName, [string]$member)

    $member = $member,"addressIAlwaysWantToAdd@MYDOMAIN.qc.ca"
    #write-host $member
    #write-host user@MYDOMAIN.qc.ca,adressToAdd@MYDOMAIN.qc.ca

New-DistributionGroup -Name $distributionListName -Type "Distribution" -Members $member

So I call the function and add a member (let’s say user@MYDOMAIN.qc.ca)...$member = user@MYDOMAIN.qc.ca...after that, I want $member to equal user@MYDOMAIN.qc.ca,addressIAlwaysWantToAdd@MYDOMAIN.qc.ca

I have tried different kind of concatenations, it does not seem to work.

If in the New-DistributionGroup cmdlet, I replace –Members with user@MYDOMAIN.qc.ca,adressToAdd@MYDOMAIN.qc.ca, it works !

When I uncomment the Write-Host, both are the same! If I use –Member $member, then I get an error that the object "user@MYDOMAIN.qc.ca adressToAdd@MYDOMAIN.qc.ca" is inexistant... it looks like my concatenation makes the $member variable in one block ("xxx xxxx" instead of xxx,xxx)

Any idea on how I should work with this ???

Thanks in advance


What's with the double-quotes...

$
0
0

Hi everyone,

I'm trying this short code:

Import-Module ActiveDirectory

$ADGroups = Import-Csv -Path 'ADgroups.txt'

ForEach ($Group in $ADGroups)
{
	$UserCount = Get-ADGroupMember -Identity $Group
}

The output fails because of the values in $Group variable need to be enclosed in double quotes. How exactly is this done when using a script?

At the command line I have no issues since I'm manually adding double quotes.

Thanks!

Jobtrigger at startup

$
0
0

Hello,

Since I migrated from Win 8.1 to 10, job scheduling seems to have changed.

I want to launch a script to read out the data from a 'smart' electricity meter whenever I turn on my pc.

I registered the job as follows:

  • $trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:30
  • Register-ScheduledJob -Trigger $trigger -FilePath C:\leo\Read_SlimmeMeter.ps1 -Name GetSlimmeMeterData

As opposed to Windows 8.1,  Windows 10 no longer executes my script whenever I start my pc from power down.

I need to do a restart to get my script activated.

How can I ensure that the job gets activated after starting the pc from power off?

Thank you!

Leo


Why is my Format-Table output changed when the -property is added?

$
0
0

If I run:

PS C:\> Get-PSDrive -PSProvider filesystem | ft -auto

I Get this Output where Used and Free are in GB's.

Name Used (GB) Free (GB) Provider   Root CurrentLocation
---- --------- --------- --------   ---- ---------------
C       164.13     73.81 FileSystem C:\
D       319.64    379.00 FileSystem D:\
E                        FileSystem E:\

But If I run:

PS C:\> Get-PSDrive -PSProvider filesystem | ft -property root,used,free

I get this output in bytes.

Root         Used         Free
----         ----         ----
C:\  176229478400  79250817024
D:\  343206727680 406947545088
E:\             0

Why is this happening, how do I fix it?

Interating through XML in SQL 2008 & 2012 packages to produce all elements and attributes and values

$
0
0
I have made some progress on this but at this point I could use some expert guidance. Thank you!

Backup notifications thru powershell/email

$
0
0

Hi All

A cpl. of things...

trying to send an email notification, for backup thru the task scheduler and powershell. The task runs endlessly in the task scheduler.

the script works, when I run it thru a powershell script debugger, but doesn't work when running thru powershell directly.

any ideas as to why?

Also the script includes the username/password to the smtp server, for authentication purposes, it's in plain text, what can i do to avoid the lack of security in the script. This was mentioned to me in a another post, when I was troubleshooting the email script.

New to Powershell, learning on the fly!

Thx!

How to find all users that have ADS_UF_PASSWD_NOTREQD

$
0
0

Hello,

I would like to know how I could find all users within different ou's that do not have passwords (ADS_UF_PASSWD_NOTREQD)? I did some googling and found how to search it within AD, but not with a PowerShell script. So if someone could be kind enough to write one for me, that would be appreciated :)

Thanks!

Cannot find path error, path contains dollar sign

$
0
0

I have written a Powershell script to import data from a flat into a SQL Server table.  I have declared the following variable, which in initialized with the path to the location of the source flat file:

$SourceFilePath = '\\servername\d$\restofpath\filename'
I pass this variable to StreamReader like so:

$reader = New-Object System.IO.StreamReader($SourceFilePath)

When I execute the script I get the following error message:

Cannot find path '\\servername\d$\restofpath\filename' because it does not exist.

I suspect the problem is due to the dollar sign in the path, but everything I've read says that if the string is enclosed by single quotes as I've done, then the dollar sign should be treated literally.  I've tried escaping it with a backtick, but that hasn't worked either.  What am I missing here?

Can't Complete Powershell 3.0 Jumpstart - Server Error

$
0
0

I get a server error about 55 minutes through the "Advanced Tools and Scripting with PowerShell 3.0 Jump Start."  The course is useful and amusing but I can't complete it.

The error occurs in Chrome, Edge and IE 11.

The Error is:

Server Error in '/' Application.

Runtime Error

Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated. 

Security Settings GroupPolicy

$
0
0

Hi, I`m building a Ps script to read security policy settings from several remote servers. At the moment I`m using secedit (servers OS ranges from 2003 to 2012R2) then I export the settings to a ini file then read the ini file and add the contents to an array of type PSObject and delete the ini file on disk, after this I store the array contents inside a xml file.

My question is, do we have a better way to do this?

Thank you.

 

Import-module activedirectly sudenly stops working

$
0
0

Hi all

I have been using some powershell scripts to query active directory users and its very usefull

Recently the script stops working even though I have not changed it !

I dont understand why.   The prereqs etc. have not been altered

The errors im getting include:

"import-module: a local error has occured ....   { import-module $_  }...

Error initializing default drive:  'a call to SSPI failed see inner exception...

I am using windows 8 64 bit  had all the pre reqs sorted e.g.  RSAT tools, powershell option enabled.   Dot net 4.5 etc.

I have tested the same script on another machine and it works fine which makes it look like there is something awry on the windows 8 machine.   I have googled about but haven't found a working solution.

The only thing  I changed recently was enabled the DHCP option in the RSAT under control panel turn windows features on or off.   Ive checked to see if id unchecked anything that would upset powershell but don't see anything so I'm at a loss.

Thanks for reading

Confuseis


confuseis

COM Object list of values

$
0
0

Good day.

I need to create COM Objects via powershell. These objects have to have parameters that differs from default. How to get list of values? Get-Member applied to the Object provides me with

Name                MemberType            Definition                        
----                ----------            ----------                        
IsPropertyReadOnly  Method                bool IsPropertyReadOnly (string)  
IsPropertyWriteOnly Method                bool IsPropertyWriteOnly (string) 
Value               ParameterizedProperty Variant Value (string) {get} {set}
Key                 Property              Variant Key () {get}              
Name                Property              Variant Name () {get}             
Valid               Property              bool Valid () {get}

I know there are values "Name", "ApplicationAccessChecksEnabled", "Identity", "Password", but how do I get full list? And which exact values every one can take?

How to store multiple information into a variable and send it via email ?

$
0
0

Hello, my ultimate goal is to send an email with the name of the products that are expiring in less than 30days, along with the end date, and how many days left. I am stuck in creating that buffer and insert it into the body of the email. The following is what i have so far:

$enablemail = @()
$enablemail = "yes"
$ProductsExpiring = @()
$smtpServer = "appmail"
$NWlicense = Import-Csv "C:\scripts\SendEmailLicense\NWLicense.csv"
$StartDate=(get-date)
$MaxDays = 30
Foreach ($NWlicense_Product in $NWlicense){
    write-host ""
    $EndDate = $NWlicense_Product."CoverageEnd"
    #write-host "End Date:" $EndDate
    #write-host "Product:"$NWlicense_Product."Product" "|" "Coverage End:"$NWlicense_Product."CoverageEnd"
    $DaysLeft = NEW-TIMESPAN -Start $StartDate -End $EndDate | select days
    #write-host "How Many Days Left for the Coverage :" $DaysLeft."Days"
    If (($DaysLeft."Days") -lt $MaxDays)
    {
        write-host ""
        write-host "Product:"$NWlicense_Product."Product" "|" "Coverage End:"$NWlicense_Product."CoverageEnd"
        #write-host "How Many Days Left for the Coverage :" $DaysLeft."Days"
        write-host "How Many Days Left for the Coverage : $($DaysLeft.Days)"
        #$ProductsExpiring =
    }
 }

Not sure how to store Product, CoverageEnd and DaysLeft into $ProductsExpiring

So, if $ProductsExpiring has the right info it will be part of the email...

Here is the email part..

# if ($enablemail -match "yes")
    # {
        # $msg = new-object Net.Mail.MailMessage
        # $smtp = new-object Net.Mail.SmtpClient($smtpServer)
        # $msg.From = $mailfrom
        # $msg.To.Add($mailto)
        # $msg.ReplyTo = $replyto
        # $msg.Subject = "WATCH OUT: Coverage Ending"
        # $msg.Body = "Hello,`n `
        # The Support Coverage or License Renewal of the following products are expiring in less than 30 days`n `
        # Product:$NWlicense_Product."""Product""""
        # $smtp.Send($msg)
    # }

Thanks for your help,


GE RF


Using Import-StartLayout to a local system

$
0
0

Here is states, that this cmdlet can be used only to an image: http://technet.microsoft.com/en-us/library/dn283403.aspx

But his guy claims that this cmdlet can be used locally: http://stealthpuppy.com/customizing-the-windows-8-1-start-screen-dont-follow-microsofts-guidance/

I need to set a valid powershell script (ps1) or command line, which could work during task sequence.

1. If I run the command from location with the startscreen bin file as:

PS L:\Tools\W8Customize> Import-StartLayout -LayoutPath .\CustomStartScreenLayou
t.bin -MountPath %SystemDrive%\

I´ll get: Cannot find path 'L:\Tools\W8Customize\%SystemDrive%\

2. If I run it with C:\Windows instead of SystemDrive, I get:

PS L:\Tools\W8Customize> Import-StartLayout -LayoutPath CustomStartScreenLayout.
bin -MountPath "C:\Windows\"

I´ll get: The path C:\Windows\ did not resolve to a file.

I also tried to copy the bin file manually to C:\Windows\ and execute it locally, but that doesn´t work either.

Find String in Excel and get neigbouring cell to Variable

$
0
0

Hi

I mapped a list of our ad users to their computers & exported to a csv file.    The computernames in column A, Usernames in Column B

I need powershell to search for the given user name in the csv file Column B and then get the corresponding computername from Column A.

I'm thinking of finding the string of text in e.g.  Cell   b100  then getting the cell number to powershell changing that to cell no. a100 and getting the contents of A100 to a variable.

Below is what I have found and tested so far.   It will find the string (username) and replace it (just to prove it works)

But im interested in the computer name 1 cell to the left

Hope that makes sense.

$File = "C:\test\Result.csv"

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

$SearchString = "user1"

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

$Search.value() = "user1-edited"


confuseis

Viewing all 21975 articles
Browse latest View live


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