Quantcast
Channel: PowerShell General
Viewing all 10624 articles
Browse latest View live

Execute a batch file from a list of computers

$
0
0

Hello,

I am new to PowerShell and I will provide some background for my issue.  I have over 150 computers on the network that need Office pro plus 2010 uninstalled.  It was not assigned using GPOs it was just installed on each computer from a network share.  I tried to remove it using wmic, both remotely and locally and I got the 1603 return value.  Anyway I have a work around that I have tested that does work I copied an XML file and placed that in the Office14 directory and created a batch file to execute the uninstall:

C:\Program Files>"Common Files\microsoft shared\OFFICE14
\setup.exe" /uninstall PROPLUS /config config.xml

The XML file allows a silent uninstall with no splash screens ect.... 

So far I have copied config.xml and setup file to each computer in a text file using PowerShell:

C:\> get-content "c:\computers.txt" | Copy-item "C:\temp\config.xml" -Destination{"\\$_\C$\users\default\desktop"}

This worked very smoothly though my test only included 3 computers in my lab. 

Now what I want to do is take the same computer.txt file and use powershell to execute the uninstall.bat file.  I've tried invoke-command and item but I don't think I am on the right path.  It would be nice to come up with something as easy the file copy line.  I have been working on this for 4 days between handling trouble tickets and such.  I like the to learn PowerShell and to be honest this is my first 4 days in trying this.  I'm not asking for someone to write a script but point me in the right direction on how to accomplish this. 

Thanks


Problem with .NET Framework 4.5 remote install via PowerShell

$
0
0

I am trying to install .NET Framework 4.5 to the remote Win2008R2 Server via PowerShell session in such way (user is in the server Administrators group):

$session = New-PSSession -ComputerName $server -Credential Get-Credential

Invoke-Command -Session $session -ScriptBlock {Start-Process -FilePath "C:\temp\dotnetfx45_full_x86_x64.exe" -ArgumentList "/q /norestart" -Wait -PassThru}

 

And then I get this error:

> Executable: C:\temp\dotnetfx45_full_x86_x64.exe v4.5.50709.17929

> --- logging level: standard ---

> Successfully bound to the ClusApi.dll

> Error 0x80070424: Failed to open the current cluster

> Cluster drive map: ''

> Considering drive: 'C:\'...

> Drive 'C:\' has been selected as the largest fixed drive

> Directory 'C:\aa113be049433424d2d3ca\' has been selected for file extraction

> Extracting files to: C:\aa113be049433424d2d3ca\

> Error 0x80004005: Failed to extract all files out of box container #0.

> Error 0x80004005: Failed to extract

> Exiting with result code: 0x80004005

> === Logging stopped: 2013/09/04 16:29:51 ===

 

If I run command locally at the server

Start-Process -FilePath "C:\temp\dotnetfx45_full_x86_x64.exe" -ArgumentList "/q /norestart" -Wait

- all works fine.

consolidating RDP service verify and system gateway and DNS verify

$
0
0

Hi every one,

 

  I got two posting two script one is used to check the RDP service status on the remote server and other one used to check the current gateway and DNS IP address associated with it.

 

  Both the scripts are working perfectly when its independent. When i consolidate both in one and execute the script on the server which has multiple NIC card its not working.  

  I am very much new to power shell seeking for help.. 

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

Gateway and DNS verify scipt.

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

[cmdletbinding()]

param (

 [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]

    [string[]]$ComputerName = $env:computername

)            

 

begin {}

process {

 foreach ($Computer in $ComputerName) {

 

  if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {

 

   $Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}

 

   foreach ($Network in $Networks) {

 

    $DefaultGateway = $Network.DefaultIPGateway

    $DNSServers  = $Network.DNSServerSearchOrder

 

    $OutputObj  = New-Object -Type PSObject

    $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()

    $OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value $DefaultGateway

    $OutputObj | Add-Member -MemberType NoteProperty -Name DNSServers -Value $DNSServers

    $OutputObj

   }

  }

 }

}            

 

end {}

-------------------------------------------------------output----------------

get-Content .\serverl.ist.txt | ForEach-Object {.\getgw.ps1 -computername $_}

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

ComputerName                            Gateway                                 DNSServers

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

QAVMFTC                              {10.247.98.1}                           {10.247.97.10, 10.247.97.11}

DNAS01                             {10.247.98.1}                           {10.247.97.10, 10.247.97.11}

DNAS01

DNAS01

DNAS01                             {198.18.2.1}                            {198.18.2.25, 198.18.2.26}

DNAS01

DNAS01

-------------------------- Output End----------------------------------------------

...............................RDP Verify Script start..........................................

param(

     [parameter(Mandatory=$true,ValueFromPipeline=$true)][string[]]$computername

     )

 

$results = @()

 

foreach($name in $computername){

 

        $result = "" | select Name,RDP

        $result.name = $name

 

        try{

           $socket = New-Object Net.Sockets.TcpClient($name, 3389)

           if($socket -eq $null){

                 $result.RDP = $false

           }else{

                 $result.RDP = $true

                 $socket.close()

           }

        }

        catch{

                 $result.RDP = $false

        }

        $results += $result

}

 

return $results

------------------------------- Output-----------------------------

get-Content .\serverl.ist.txt | ForEach-Object {.\RDP_Port_verify -computername $_}

 

Name                                                                                                                                  RDP

----                                                                                                                                  ---

QAVMFTC                                                                                                                           True

dnas01                                                                                                                          True

 

I am trying to consolidate the script into one for single output 

-------Script stats-----------------

[cmdletbinding()]

param (

 [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]

    [string[]]$ComputerName = $env:computername

 

 

)            

 

 foreach ($Computer in $ComputerName) {

 

if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {

$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}

}

foreach ($Network in $Networks) {

   $DefaultGateway = $Network.DefaultIPGateway

       $DNSServers  = $Network.DNSServerSearchOrder

 }

}

 

##################################

 

$results = @()

 

foreach($Computer in $computername){

 ##

        $result = "" 

        try{

           $socket = New-Object Net.Sockets.TcpClient($name, 3389)

      

           if($socket -eq $null){

                 $result = $false

           }else{

                 $result = $true

                 $socket.close()

           }

        }

        catch{

                 $result.RDP = $false

        }

        $results += $result

}

 

 

    $OutputObj  = New-Object -Type PSObject

    $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()

    $OutputObj | Add-Member -MemberType NoteProperty -Name RDP -Value $results

    $OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value $DefaultGateway

    $OutputObj | Add-Member -MemberType NoteProperty -Name DNSServers -Value $DNSServers

    $OutputObj

 

----------------------------Output bellow--------------------------------------

get-Content .\serverl.ist.txt | ForEach-Object {.\test.ps1 -computername $_}

 

ComputerName                       RDP                                Gateway                           DNSServers

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

QAVMFTC                         {True}                             {10.247.98.1}                     {10.247.97.10, 10.247.97.11}

DNAS01                        {True}

 

The server which has multiple gateway and associated DNS IP is not visible at script output.  

 

 

 

 

Change DHCP IP to static IP

$
0
0

i used below script to change DHCP Ip to static on multiple servers. Nut no luck :(

http://social.technet.microsoft.com/Forums/windowsserver/en-US/50f07ed6-c076-4920-a7f2-3a0f5292a177/dhcp-to-static-ip-address?forum=winserverpowershell

$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername (gc .\servers.txt) | where{$_.IPEnabled -eq $true -and $_.DHCPEnabled -eq $true} 
Foreach($NIC in $NICs) { 
    $ip = ($NIC.IPAddress[0]) 
    $gateway = $NIC.DefaultIPGateway 
    $subnet = $NIC.IPSubnet[0] 
    $dns = $NIC.DNSServerSearchOrder 
    $NIC.EnableStatic($ip, $subnet) 
    $NIC.SetGateways($gateway) 
    $NIC.SetDNSServerSearchOrder($dns) 
    $NIC.SetDynamicDNSRegistration("FALSE") 

when i execute this on windows 2000 and windows 2003 server is disconnecting not able to connect to the server with then Ip or server name .

Please provide some solution  or alternate script with hel me to update the DHCP ip to static.

 

Thanks, jeevan

WMIExplorer

$
0
0

I downloaded it WMIExplorer Chapter 14 of "Month of Lunches 2nd Ed, now how do I start it? This is Win 8 Pro and I get no icon or anything to launch other than the install, what is the rookie doing wrong, have a good laugh but no too long:)

Can not remote to myself

$
0
0

Probably obvious once I see what is wrong but for now I'm baffled.
I'm running Powershell 3.0 and want to solve this before I upgrade to 4.

I stripped all the overhead I could

  • firewall disabled
  • no AD/domain just 2 Windows PCs that remote
  • Transport = HTTP
  • TrustedHosts = *
  • Listener Address = *
  • default ports are used 5985, 5986
  • running Powershell as Administrator

I have a Windows 7.1 PC and a Windows 8.0 PC and problem seems to be a configuration setting on the Windows 8 PC. The PCs are WAN connected over the internet. I configured the router to portforward the WSremoting ports to the Windows 8.0 PC

To avoid any typos with usernames and passwords I used the construct $cred=Get-Credential

I can remote van the PC-Win8 into PC-Win8 using localhost
I can remote van the PC-Win7 into PC-Win8 over the internet
But I can't remote van the PC-Win8 into PC-Win8 over the internet

Considering that the first 2 work I would assume remoting is setup correctly but to my surprise on the third one I get Access denied. Below the transcript. I only edited the prompt and the actual computer name.

 
from PC-Windows8.0
=================================================================================
PS C:\> $cred=Get-Credential
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:

PS C:\> Enter-PSSession -Credential $cred -ComputerName localhost

[localhost]: PS D:\> exit

PS C:\> Enter-PSSession -Credential $cred -ComputerName subdomain.mydomain.com
Enter-PSSession : Connecting to remote server subdomain.mydomain.com failed with the following error message :
Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:1
+ Enter-PSSession -Credential $cred -ComputerName subdomain.mydomain.com
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (subdomain.mydomain.com:String) [Enter-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : CreateRemoteRunspaceFailed
 

PS C:\>


from PC-Windows7.1
=================================================================================
PS D:\> $cred=Get-Credential
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:

PS D:\> Enter-PSSession -Credential $cred -ComputerName subdomain.mydomain.com

[subdomain.mydomain.com]: PS C:\> exit

PS D:\>

play sound on a remote computer with powershell

$
0
0

hey there!  

i have a hostmonitor server and another monitor station. 

i neet to play an alarm sound on the station whenever there is some error.

is it posibol to do it?

how can i connect from the server to the station and play the alarm?

thank you for any help...

ido

Listing all URL targets on Desktop of multiple PC's

$
0
0

I'm trying to create a PS script, ultimately, that will find all the URL on a list of pc's, then based on if a target is found, change that target to a new target. The problem I'm having is that it is listing only the .url's of the first pc. Any help is appreciated!

function Get-DesktopShortcuts
{
    $Shortcuts = Get-ChildItem ~\desktop\ -Recurse -force -include *.url
    $Shell = New-Object -ComObject WScript.Shell

$strComputer = Get-Content C:\ps\test.txt

foreach ($computer in $strComputer)
{	
	 foreach ($Shortcut in $Shortcuts)
    {
        $Properties = @{
			Computer = $computer
            ShortcutName = $Shortcut.Name
            Target = $Shell.CreateShortcut($Shortcut).targetpath
        }


        New-Object PSObject -Property $Properties
    }

}
    [Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null
	}


$Output = Get-DesktopShortcuts
$Output

## $Output | Export-Csv C:\ps\smfpc.csv

Need help to Invoke complex cmd File on remote Computer

$
0
0

Hello,

The Problem:

In our Domain we use Matrix/Empirum to Deploy Software/Images/Patches etc.

In the last 5 Month´something went wrong with the Inventory Function of the Program.

To Force an Update of this Inventory on all clients I have to do some tasks on them.

e.g.: Set a new Regfile ( is done )

        Start a Service    ( is done too) 

 

The Last Step in my Script is to Start a little but complex *.cmd File.

"C:\WINDOWS\system32\Empirum\EmpInventory.exe" /C:\\IPADDRESS\Configurator$\User\EmpInvScan_Win_PX.xml" /O:\\IPADDRESS\EmpInv$\%UserDomain%.%ComputerName%.xml" /E /DMI /WMI /AUT /V2 /M /T /ZIP /DIFF

If I Start this little cmd File on the client everything works fine.

In case your´ll ask. Yes, I work with Domain Admin Rights, 
Powershell Remoting is on, Firewall is ok, everything else in my PS Scripts works very well.

 

I tried with the Invoke Function:

$xcmd = 'the command from the top...'

Invoke-Command -ComputerName $_  -ScriptBlock{$xcmd} -Credential $credentials

with different Scenarios like "CMD.EXE /C " + $xcmd

with [Scriptblock}::create("command..")

I tried with WmiObject etc..etc..everything I believe I can find in a long google search and try.

 

What I can see is, that something IS happening on my client (Taskmanager),

but the report I d like to see is not beeing generated.

 The Code above is definitly correct, it works perfekt on the client itselt but not remote.

Anyone here who could give me  advice?

 

 

 

 

 

Help needed to execute a remote powershell exchange command

$
0
0

Hi guys,

I'm a french girl, and a newbie into scripting domain, so if I just don't understand some of the things you explain me, please just be cool :)

So, I want to execute a remote powershell script from a windows 2003 server (monitoring server)  which will be able to count mailboxes on my unique exchange server.

I try this which is working well on the exchange server, but it returns an error message on my remote server :

"Le terme « Get-MailboxStatistics » n'est pas reconnu comme nom d'applet de commande, fonction, fichier de script ou pro
gramme exécutable. Vérifiez l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le chemin d'accès est co
rrect et réessayez.
    + CategoryInfo          : ObjectNotFound: (Get-MailboxStatistics:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

 


Here is the script (get on ne the web) :
 


param([string] $Param )  

$Results = @()
$CountMB = 0

if(!$param)
 {
  $Servers = Get-Process -computerName name_of_server| Get-ExchangeServer | Where {$_.ServerRole -eq "Mailbox"} | Sort Name

  Foreach($Server in $Servers)
   {
    $dbs = Get-MailboxDatabase -server $Server | Sort Name
    
    foreach($db in $dbs)
     {
      $mb = Get-MailboxStatistics -Database $db | Where {$_.DisconnectDate -eq $null -and $_.ObjectClass -eq 'Mailbox'} | Measure-Object
      $mbdis = Get-MailboxStatistics -Database $db | Where {$_.DisconnectDate -ne $null -and $_.ObjectClass -eq 'Mailbox'} | Measure-Object
      
      Write-Host "$($Server) `t $($db.name)`t $($a.count)"
      
      $Obj = New-Object PSObject
      $Obj | Add-Member NoteProperty -Name "Server" -Value $Server
      $Obj | Add-Member NoteProperty -Name "Database" -Value $db.Name
      $Obj | Add-Member NoteProperty -Name "Mailboxes" -Value $mb.count
      $Obj | Add-Member NoteProperty -Name "Disconnected Mailboxes" -Value $mbdis.count
      $Results += $Obj
     }
   }
 }
else
 {
 $server = $param
  $dbs = Get-MailboxDatabase -server $Server | Sort Name

  foreach($db in $dbs)
   {
    $mb = Get-MailboxStatistics -Database $db | Where {$_.DisconnectDate -eq $null -and $_.ObjectClass -eq 'Mailbox'} | Measure-Object
    $mbdis = Get-MailboxStatistics -Database $db | Where {$_.DisconnectDate -ne $null -and $_.ObjectClass -eq 'Mailbox'} | Measure-Object

    $Obj = New-Object PSObject
    $Obj | Add-Member NoteProperty -Name "Server" -Value $Server
    $Obj | Add-Member NoteProperty -Name "Database" -Value $db.Name
    $Obj | Add-Member NoteProperty -Name "Mailboxes" -Value $mb.count
    $Obj | Add-Member NoteProperty -Name "Disconnected Mailboxes" -Value $mbdis.count
    $Results += $Obj
    $countmb += $mb.count
    
   }
  Write-Host
  Write-Host "$($Server) has a total of $($CountMB) mailboxes" -ForegroundColor Green
 }

$Results | FT -AutoSize

 

Any help will be appreciated !

Thanks all

Powershell remoting as non-admin on windows server 2003

$
0
0

I am trying to do powershell remoting as a non-admin user on windows server 2003. I have enabled PS remoting and given the user permissions along the lines discussed in 

http://blogs.msdn.com/b/powershell/archive/2009/11/23/you-don-t-have-to-be-an-administrator-to-run-remote-powershell-commands.aspx

with the cmdlet.

Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI

Now, I can user Enter-PSSession or Invoke-command and run powershell cmdlets fine as non-admin user.
But cannot run native commands eg. ipconfig or cmd /c ipconfig.

I get Access Denied error (Fully qualified error id: NativeCommandFailed.

But when my target server is 2008 R2 I can run any command, batch files and even vbscript files.
Is there some extra setting in windows server 2003 that has be enabled for non-admin users remoting privleges to be complete.

Remoting Function Strategy

$
0
0

I have written a few advanced functions that take advantage of remoting cmdlets such as Invoke-Command or Get-WMIObject and I have a general question regarding how to write these functions.

One function I have uses an external command and executes against the local computer by default. I have added credential and computername parameters and if these are specified then the command is executed using Invoke-Command against one or several remote computers. 

Would you include Invoke-Command in your function or would it be better to use Invoke-Command outside the function? I also have some functions that call certain WMI cmdlets and use similar parameters for remoting capabilities. 

Invoke-Command embedded in function:

Get-Something -computername server01 -credential domain\user01

Using Invoke-Command outside the function:

Invoke-Command -scriptblock {Get-Something} -computername server01 -credential domain\user01

I like my way but I can see that some may say it is not best practice. Please explain why you think one way is better than the other. Also please keep in mind that these functions may be shared with others that do not have a deep knowledge of Powershell. 

Thanks!

Getting Access Denied message from Server

$
0
0

I am trying to execute the powershell script to get the contact details from Active directory from a remote machine that is outside the domain.

From the  XP machine [Client-Workgroup machine] with Powershell version 2.0 ,I am trying to connect a machine in the domain which is Windows Server 2008 R2[Server - It is in Domain] with Powershell version 2.0.

In both machine  I have started winrm service and trusted all the IP address for remote execution.

But when I tried to create the session from the client machine I am getting the Access Denied message.

Command Executed in Server Powershell Command window

cd wswan:

cd localhost\client

Enable-PSRemoting

Set-Item TrustedHosts *

Restart=Service WinRM

Command Executed in Client Powershell Command window

cd wswan:

cd localhost\client

Enable-PSRemoting

Set-Item TrustedHosts *

Restart=Service WinRM

New-PSSession -ComputerName 10.1.1.219 -Credential development\sthangaraj

It prompts for Password Once I give the password and Enter I am getting access denied message

+PSRemotingTransportException

+PSSessionOpenFailed

Unable to run powershell script as a package through SCCM 2012

$
0
0

Hi All,

I have a powershell script that i can run manually on a Windows 8.1 machine but when i create a package for that script in SCCM 2012 and than try to execute it it fails. the command I use in SCCM command line is as below :-

powershell.exe -file .\Add-AppDevPackage.ps1

Any suggestions on how to get this execute through SCCM??

 

 

 

BITS transfer files using different domains without share

$
0
0

hi, can someone explain if is it possible to transfer files between my local pc and a server on a different domain without share its path.

i.e.

PS C:\Users\Desktop> Import-Module bitstransfer

PS C:\Users\Desktop> $c=get-credential

PS C:\Users\Desktop> start-bitstransfer -Credential $c -source \\server\c$\test.txt -destination .

 

the output is:

Start-BitsTransfer : Cannot find path '\\server\c$\test.txt' because it does not exist

but this happens only if I don't mount the share \\server\c$

 

is there a solution?


Powershell Remoting from Server 2012 to Server 2003 SP2 Box Does not work.

$
0
0

I've read at least 30 different "help" articles and I've tried every single suggestion and I still can't make this work!  Of all places I figured that here on PowerShell.com someone might have a suggestion for me.  

I have two servers that are primary and slave for some powershell remoting scripts that I run automagically. The older server is 2008 R2 and I can PSRemote into my remote server (274app) without ANY issues.  

The primary server is a Server 2012 box.  That one will NEVER work.  I've done all the trusted host stuff and all the normal troubleshooting and have come up with nothing.  Error is shown below, it's just the standard generic error WinRM error.  Does PSRemoting from 2012 to 2003 boxes just not work? 

 

PS C:\Users\twsgadmin> Enter-PSSession -ComputerName 274app.twsgserver.com -Credential *********

Enter-PSSession : Connecting to remote server 274app.twsgserver.com failed with the following error message : WinRM

cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over

the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By

default, the WinRM firewall exception for public profiles limits access to remote computers within the same local

subnet. For more information, see the about_Remote_Troubleshooting Help topic.

At line:1 char:1

+ Enter-PSSession -ComputerName 274app.twsgserver.com -Credential RemoteAdmin

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

    + CategoryInfo          : InvalidArgument: (274app.twsgserver.com:String) [Enter-PSSession], PSRemotingTransportEx

   ception

    + FullyQualifiedErrorId : CreateRemoteRunspaceFailed

PowerShell Help !!!

$
0
0

I am very new to PowerShell.  I have a large scale of Brocade Fibre Switch in my environment. I am trying to create a PowerShell script that would make my switch management life a little easier. The script have the following variables;

 

BSSip map to a text file with ip address of the switches .

BCSlogon map to a text file with the user id.

BCSpw map to a text file with the password for the logon id.

BCScommand map to a text file with the command I wish to run on the switch.

 

When I run the PowerShell script can variables has collected the content of the text files asrequested.I get the following error “Unable to open command file “switchshow”

I aslo need to press CTR-C on the switch after logging on.

 

Would someone please the correction of my errors in this script; and other possible ways I complet the task I am trying to do.

 

Thanks in Advance.

Robert

Powershell Script.

<#
This script will login to fibre listed in the switchIP text file  and capture the command and export out to a text file
#>
# Get the IP address from switchIP text file
$BCSip = Get-Content c:\Scripts\Brocadeswitch\switchIP.txt

# Get the logon from SwitchLogon text file
$BCSlogon = Get-Content c:\Scripts\Brocadeswitch\SwitchLogon.txt

# Get the password form Switchpsswd text file
$BCSpw = Get-Content  c:\Scripts\Brocadeswitch\Switchpsswd.txt

# Get the switch command from SwitchCommand text file
$BCScommand = Get-Content c:\Scripts\Brocadeswitch\SwitchCommand.txt

# Use plink to ssh into the switch
$plink = "c:\Scripts\Brocadeswitch\plink.exe"

$logFile = "Brocade-Log-" + (Get-date -f dd ).tostring() + (Get-date -f MM ).tostring() + ((Get-Date).year).tostring() + ".err"


(Get-Date) > $logFile

$BCSip | % { $_ >> $logFile; & $plink -l $BCSlogon  -pw $BCSpw -m $BCScommand $_ >> $logFile }

echo $logFile

 

 

 

Is compare script on text files using powershell works also on excel?

$
0
0

We can compare files that are in .txt format is it possible also in .xls or .csv format?

PS Object Behaivour

$
0
0

I am new to powershell

Using  a power shell script to deploy my SSRS reports

I have run into weird problem 

extracts from script 

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

Create Data source function

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

function New-SSRSDataSource ($Proxy,[string]$RdsPath,[string]$Folder,[switch]$Overwrite) {

    Write-Verbose "New-SSRSDataSource -RdsPath $RdsPath -Folder $Folder"

 

    $Folder = Normalize-SSRSFolder -Folder $Folder

 

    [xml]$Rds = Get-Content -Path $RdsPath

    $ConnProps = $Rds.RptDataSource.ConnectionProperties

 

    $Definition = New-Object -TypeName SSRS.ReportingService2010.DataSourceDefinition

    $Definition.ConnectString = $ConnProps.ConnectString

    $Definition.Extension = $ConnProps.Extension 

    if ([Convert]::ToBoolean($ConnProps.IntegratedSecurity)) {

        $Definition.CredentialRetrieval = 'Integrated'

    }

        $hash =@{

        Name = $Rds.RptDataSource.Name

        Path =  $Folder + '/' + $Rds.RptDataSource.Name

    }

    $DataSource = New-Object -TypeName PSCustomObject -Property $hash

 

    if ( $Overwrite -or  $Proxy.GetItemType($DataSource.Path) -eq 'Unknown') {

 

        $Proxy.CreateDataSource($DataSource.Name, $Folder, $Overwrite, $Definition, $null)

    }

 

    return $DataSource

}

 

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

where Its referenced

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

$DataSourcePaths = @{}

$Project.SelectNodes('Project/DataSources/ProjectItem') |

    ForEach-Object {

   $RdsPath = $ProjectRoot | Join-Path -ChildPath $_.FullPath

        "$RdsPath"

$DataSource = New-SSRSDataSource -Proxy $Proxy -RdsPath $RdsPath -Folder $DataSourceFolder 

 

$DataSource|Out-GridView

 

       $DataSourcePaths.Add($DataSource.Name,$DataSource.Path)

    }

I have two Items in 'ProjectItem' node so essentially for loop should  execute for two times

current behaivour

   when I execute script for the first time

following are results from both grid view and error message at powershell prompt

Grid View

0SSRS.ReportingService2010.CatalogItemSSRS.ReportingService2010.CatalogItem

1@{Name=Verification Relational DS; Path=/Data Sources/Verification Relational DS}System.Management.Automation.PSCustomObject

Prompt
ForEach-Object : Property 'Name' cannot be found on this object. Make sure that it exists.
At C:\Users\prabhakar.munugala\Documents\Visual Studio 2010\Projects\DVSDashBoard\DVSDashBoard\Deploy-SSRS
68 char:19
+     ForEach-Object <<<<  {
    + CategoryInfo          : InvalidOperation: (.:OperatorToken) [ForEach-Object], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Commands.ForEachObjectCommand
When I execute it second time
it would have two grid views as '$DataSourcePaths.Add($DataSourcePaths.Add($DataSource.Name,$DataSource.Path)'
has got 'Name' and 'Path' properties
But it fails on the second data source
below are results
GridView1

Verification Relational DS/Data Sources/Verification Relational DS

GridView2
0SSRS.ReportingService2010.CatalogItemSSRS.ReportingService2010.CatalogItem
1@{Name=VerificationCube; Path=/Data Sources/VerificationCube}System.Management.Automation.PSCustomObject
Prompt
ForEach-Object : Property 'Name' cannot be found on this object. Make sure that it exists.
At C:\Users\prabhakar.munugala\Documents\Visual Studio 2010\Projects\DVSDashBoard\DVSDashBoard\Deploy-S
68 char:19
+     ForEach-Object <<<<  {
    + CategoryInfo          : InvalidOperation: (.:OperatorToken) [ForEach-Object], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Commands.ForEachObjectCommand
When I run for the third time 
every thing is good
Below are results
GridView1
VerificationCube/Data Sources/VerificationCube
GridView2
Verification Relational DS/Data Sources/Verification Relational DS
and Script executes well
Issue :- Returned PSObject , on initial run is not returning the expected value
any help would be appreciated

Software triggered IRQ in PS

$
0
0

Hi,

 

Is there  a way in powershell to initiate software triggered IRQ. I am trying to use the Measure-command to find the execution time of a script block. But due to the high CPU queue length, I see delays in milliseconds. Since the expected result is within milliseconds, even a slight delay in seconds makes much difference in the final result.

 

Regards

 

Ranjith A Paul

Viewing all 10624 articles
Browse latest View live