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

Need help in create TFS branch using Powershell

$
0
0

I need help in creating TFS branch using PowerShell. With this I am planning to automate the process of branching and merging of source code using PowerShell. Really appreciate if some one provide the code snippet.

Thanks,

Purna Chandra.


Splitting a String with a Multicharacter Delimiter

$
0
0

Hello,

I'm trying to split a string of text using a multicharacter delimiter, but the split method appears to only support a one character delimiter.  Is there a simple way to split using multiple characters?

Example:

My file contains this:  ISA*DATA*DATA*DATA*DATA*DATA~ISA*DATA*DATA*DATA*DATA~ISA*DATA*DATA~

I would need to split it on "ISA*".  Below is an example of the output when I try to just use the split method.  Any idea why I'm getting that output and what a better way to do it is?

$test = "ISA*DATA*DATA*DATA*DATA*DATA~ISA*DATA*DATA*DATA*DATA~ISA*DATA*DATA~"
$test2 = $test.split("ISA*")
$test2


D
T

D
T

D
T

D
T

D
T
~



D
T

D
T

D
T

D
T
~



D
T

D
T
~

Set-Acl permission failed

$
0
0

I am trying to set the permissions on a folder using the below code, However i get this error :-

Cannot find an overload for "FileSystemAccessRule" and the argument count: "6".



Functin kozos_Permission($Server)
{

 $FolderLocation = "C:\inetpub\ftproot\kozos"
 $GroupToBeAdded = "$Server\administrators"
 $acl = Get-Acl -Path $FolderLocation
 $User = [System.Security.Principal.NTAccount]$GroupToBeAdded
 $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($User, "FullControl","ContainerInherit", "ObjectInherit", "None", "Allow")
 $acl.AddAccessRule($AccessRule)
 set-acl -Path $FolderLocation -AclObject $acl
}
kozos_Permission localhost

Execute .ps1 script silently

$
0
0

Hi, 

I'm new to Powershell so please bear with me.  My .ps1 files are associated with Powershell.exe so when I run them from the command line they open up "Powershell ISE" and wait for me to press play. Is there a way of just having them execute without this popping up? 

I had a look at the Powershell editor and it looked fine for testing out single line commands, however I did not seem to be able to comment/uncomment lines easily so I decided to use Visual Studio 2015 Enterprise as I'm familiar with the IDE, am I likely to run into any issues/limitations further down the road using this?

Thanks

  

[PSCustomObject] does not return all colums (Powershell)

$
0
0

Hi

Experts, I am new in powershell and I did copy/paste and adjusted code following code from internet to accomplish my need, please excuse me for asking silly questions if it so.

I am just using following powershell code to get SQL version data from one portal but it should return 4 columns instead of 2 columns:

$url = 'http://sqlserverversions.blogspot.in'
$HTML= Invoke-WebRequest -Uri $URL
$HTMLTableNumber="3"
#$RawTables=$HTML.ParsedHtml.getElementsByTagName("TABLE")
$RawTables=@($HTML.ParsedHtml.getElementsByTagName("TABLE"))
$RawTable = $RawTables[$HTMLTableNumber] #temp
ForEach ($RawTable in $RawTables)
{  

 $titles = @()
 $rows = @($RawTable.Rows)


 foreach($row in $rows)

  {
    $cells = @($row.Cells)
    if($cells[0].tagName -eq "TH")
    {
        $titles = @($cells | % { ("" + $_.InnerText).Trim() })
        continue
    }

    if(-not $titles) {$titles = @(1..($cells.Count + 2) | % { "Col$_" })}

    $resultObject = [Ordered] @{}
    for($counter = 0; $counter -lt $cells.Count; $counter++)
    {
        $title = $titles[$counter]
        if(-not $title) { continue }
       
#$cells[$counter].InnerText
        $resultObject[$title] = ("" + $cells[$counter].InnerText).Trim()

    }

    [PSCustomObject] $resultObject    
  }
}

If I don't put the looping on table i.e. ForEach ($RawTable in $RawTables) and adjust the code to work to get only single HTML table then same code return correct data.

Can someone help on this?

I also wanted to know more on following statement as why we are using ("" in statement, seems it is one liner statement which always creates trouble:

$resultObject[$title] = ("" + $cells[$counter].InnerText).Trim()

Bobby

Using command output as message in msg

$
0
0

Hi.

I'm trying to use the output of a Powershell commands as the content of a message in msg.

if I do:

$TEST = 123
msg /server:mypc * "$TEST"

I get the message box saying "123"

However, when I do:

$TEST = (cmdlet|cmdlet|cmdlet)|out-string
msg /server:mypc * "$test"

It dose not work.

Is there a way sent the output of (cmdlet|cmdlet|cmdlet)|out-string with msg?

Thank you! :)




how to display deletion user list for a particular period along with directory path (last known parent) & deletion date via powershell

$
0
0

how to display deletion user list for a particular period  along with directory path (last known parent) & deletion date via powershell

Kindly provide the same 

problems with null-valued expression error

$
0
0

I run my code that gathers certain parameters against multiple machines to create a report. I gather the parameters in a hashtable. Problem is when running the script against one of the machines which in theory should be identical like the others I get

You cannot call a method on a null-valued expression.

+$properties = @{

+~~~~~~~

       +CategoryInfo : InvalidOperation: (:) [], RuntimeException

       +FullyQualifiedErrorID : InvokeMethodNull

I checked all the variables that go to the hashtable and all return values unless I have some caching I'm not aware of. How can I pinpoint the one causing the error? 


yaro


DSC Partial configurations failing when trying to update servers at the same time.

$
0
0

Hi All,

I have tried to configure the partial configurations for the set of servers.

The nodes are configured as following:

ConfigurationRepositoryWeb XXX-DSC-REPOS {
ServerURL = "https://$servername/PSDSCPullServer.svc"
CertificateID = $CertificateID
AllowUnsecureConnection = $False
RegistrationKey = $RegistrationKey
ConfigurationNames = @("xMyconfigMasterHost", "xMyconfig", "xMyconfig_SIT", $ComputerName)

"xMyconfigMasterHost", "xMyconfig", "xMyconfig_SIT" – are the partial configuration names that are merged for the node and contain environment wide settings.
 $ComputerName – Computer specific configuration. Variable is populated from the script input.



PartialConfiguration xMyconfigMasterHost
        {
            Description                     = 'Configuration for the xMyconfigMasterHost'
            ConfigurationSource             = '[ConfigurationRepositoryWeb]XXX-DSC-REPOS'
            RefreshMode                     = 'Pull'
        }
PartialConfiguration xMyconfig
        {
            Description                     = 'Configuration for the xMyconfig'
            ConfigurationSource             = '[ConfigurationRepositoryWeb]XXX-DSC-REPOS'
            DependsOn                       = '[PartialConfiguration]xMyconfigMasterHost'
            RefreshMode                     = 'Pull'
        }
           PartialConfiguration xMyconfig_SIT
        {
            Description                     = 'Configuration for the xMyconfig_SIT'
            ConfigurationSource             = '[ConfigurationRepositoryWeb]XXX-DSC-REPOS'
            DependsOn                       = '[PartialConfiguration]xMyconfig'
            RefreshMode                     = 'Pull'
        }
  PartialConfiguration $ComputerName
        {
            Description                     = "Configuration for the  $ComputerName"
            ConfigurationSource             = '[ConfigurationRepositoryWeb]XXX-DSC-REPOS'
            DependsOn                       = '[PartialConfiguration]xMyconfig_SIT'
            RefreshMode                     = 'Pull'
        }

So all the servers have 2 partials configurations that they share and one specific, that is representing the configuration specific for the server.

I have 2 problems with this config:

1. If the configurations have been pulled to the node and I would like to change  one of the configuration names,  the merge will fail as it will try to include the old partial configuration that will now being replaced, as it still exist on the node. The error will say that I do have a duplicate resource.

2. If  I will try to run "Start-DscConfiguration -UseExisting -ComputerName "Server-01","Server-02" -Verbose -Force -Wait" on multiple nodes - it will fail for all except one. 

The error for the failed nodes would be:

The attempt to get the action from server
http://dsc-001///PSDSCPullServer.svc/Nodes(AgentId='C07CBBB90')/GetDscAction failed
because pullserver is not available or there is no  registered node with AgentId C07CBBB90
on the server.+ CategoryInfo          : ResourceUnavailable: (root/Microsoft/...gurationManager:String) [], CimException+ FullyQualifiedErrorId : WebDownloadManagerGetActionNodeConfigurationNotFound,Microsoft.PowerShell.DesiredStateCo
   nfiguration.Commands.GetDscActionCommand+ PSComputerName        : Server-01

If try to run any amount of nodes in different PowerShell sessions with only one node per command - it will work fine for all nodes.

Any advice?


Local security settings

$
0
0

I'm having trouble with getting local security policy settings through powershell . I need to take all security settings that can be seen in secpol.msc through poswershell in human readable format if it's possible .

Is there anyone who is willing to write a script or find any other way to help me , I would appreciate that .

Best regards

How to exclude duplicate records while fetching the data from one file and put into another file.

$
0
0

Hi All,

I have file name "old.txt". The file contains the following data.(with Duplicate records)

I need to exclude the duplicate records where combination of 3rd and 4th columns are same and put it into another file "new.xtx"..

Note: There is no column names inside the file.

can any help me on this? This is very important.

Data in "old.txt" file with duplicate records.

EAICC             005584A021984Q3LD       12005      _1984-Vflag ON in the base so  cant value this policy
EAICC             005840A011985Q2CD      02777      _1985-no key 005840A in imvalgrp.tbl
EAICC             005584A021984Q3LD       02777      _1985-no key 005840A in imvalgrp.tbl
EAICC             005584A021984Q3LD       02774      _1985-no key 005840A in imvalgrp.tbl
EAICC             005584A021984Q3LD       02777      _1985-no key 005840A in imvalgrp.tbl
EAICC             005584A021984Q3LD       02777      _1985-no key 005840A in imvalgrp.tbl
EAICC             005584A021984Q3LD       02777      _1985-no key 005840A in imvalgrp.tbl
EAICC             005584A021984Q3LD       02778      _1985-no key 005840A in imvalgrp.tbl
EAICC             005584A021984Q3LD       02777      _1985-no key 005840A in imvalgrp.tbl
EAICC             005584A021984Q3LD       02777      _1985-no key 005840A in imvalgrp.tbl

Thanks & Regards,

Dinesh.


Try not catching Drive_not_found

$
0
0

I was surprised that the below checking of a non-existing drive does not transfer control to the Catch area. Why is that?

$DebugPreference = "Continue"                         

try {
    Write-Debug "Before Error"
    Get-ChildItem -Path "Q:\"    # Q is a non-existing drive.
    Write-Debug "After Error"
    Write-Debug ("Error in Try block: " + $Error[0])
}
catch {
    Write-Debug "Catch"
    Write-Debug ("Error in Catch block: " + $_.Exception.Message)
}


-Tom. Microsoft Access MVP

class ignores if/while bug?

$
0
0

Hi

Something strange I encountered 

if you put a class in a while/if that will not run it will get created?!

if ($false)
{
    'How is this class get created if this line does not?'
    class Base64
    {
        [string]$ItemName

        Base64([string]$String)
        {
            $this.ItemName = $String
        }

        [string]ToString()
        {
            return $this.ItemName
        }
    }
}
[base64]$a = 'aaaa'
$a

How?

Why?


Help with Simple Find Dates with Regular Expression...need two digit year

$
0
0

Need some help with just a simple date finder that can do two digit years.
I just want it exported to another file with the list of lines containing dates.

The expression runs without error it just doesn't find any data and I have gone all the way to file level, but there are probably 50 date references in the format 08/22/16.

The latest expression I tried that found no dates is this one:

^((0?[13578]|10|12)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[01]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1}))|(0?[2469]|11)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[0]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1})))$/g

In the example it seems very much like it would find 2 digit year but I have 24 files of dates and it returns no values.

Select-String \\Path\*.txt -pattern "/^((0?[13578]|10|12)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[01]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1}))|(0?[2469]|11)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[0]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1})))$/g" -Context 0,1|Select-Object FileName, LineNumber,Line| export-csv \\Process\drive\Results\Dates.csv                                  

Any help appreciated.




powershell 5.0.x and 5.1.x help not working

$
0
0

I have two different windows 10 systems - 1 has powershell 5.0.x installed and is essentially a plain vanilla windows 10 system. Help on that system doesn't work; e.g. if I do a help about_commandparameters, I get nothing and if I add "-online" to that it doesn't bring up the online help.

My second system is a windows 10 system, as well, but it has powershell 5.1.x installed and I have the same problem as the other system - help about_commandparameters gives nothing as a result, no error, just nothing.  If I add "-online" it doesn't bring up the online version.  On this system, I also tried installing the module browser but ran into problems with "nuget.anycpu.exe" not being found.

Seems to me that the 5.x versions of powershell are broken.  I'd like to see fixing these problems - especially help - being a priority.


Reboot Servers in groups and wait until they are up then move to next group

$
0
0

Hello,

I am trying to create a script and where i have a list of servers and group/sequence numbers.

Csv file content:

servername,Group
Server1,1
Server2,1
Server3,2
Server3,4
etc

What i need to do it come up with script to reboot the servers in the same group at the same time then wait until they are up and then move to the next group.

can you please give me a few ideas to archive this?

Thank you.


EverydayLearner

why Bash on Windows cannot run on the PowerShell ISE

exchange 2013 powershell script to generate shared mailbox owners list

$
0
0

hi,

exchange 2013 powershell script to generate shared mailbox owners list.

can any one help?  tried with Owner parameter but it does not generate list with all shared mailbox details of owners


MD

find disk number with no FileSystemLabel?

$
0
0

Is there a way to find a disk number where no drive letter or file system label is assigned to it in Powershell 5.  the get-drive command does not give label nor drive letter.  the get-volume command will give drive letter and label but not the drive number.  Is there a way to join the two functions?

Thanks,

peter


Rename Computer using Powershell fails with cannot establish WMI connection

$
0
0

I am trying to rename computer using powershell script which takes remote session of DC controller and tries to rename computer.

Script is failing with error - "Cannot establish WMI connection to computer (this is name of PC which is going to be renamed)". RPC server is not available.

Please note below ports are opened for Bi-directional communication between client and domain controller -

1. 5985 - WINRM

2. 135

3. 139

Any idea how to troubleshoot this issue? Is there something else that need to be enable in the Firewall to make powershell script work to rename computes?


Anand Prasad

Viewing all 21975 articles
Browse latest View live


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