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

Free PowerShell community CI server

$
0
0

Last week, PowerShell.org created a hosted TeamCity instance which is free to use for any open-source project.  What sets this apart from other similar CI solutions out there is that we're customizing build agents and project templates specifically for PowerShell script / module testing.  If you're hosting an open-source PS project on GitHub, and you're already using Pester for testing, then the effort involved to get your project set up is virtually nothing.  The template used to create new projects will automatically run your Pester tests against every commit (including pull requests), on PowerShell v2 through v5, and publish a pass or fail status back to GitHub.

http://powershell.org/wp/community-build-server/ for more information.


Powershell script that after the user digit a site address, look up for that site ip and modify hosts file.

$
0
0

Hi! I'm new to the powershell scripting, i'd like to know it there's a way to make a script that does this: 

1) Asks the user for a web address, for example the user types "www.google.com"

2) Look up automatically for that address IP

3) Take that IP information and adds the Web Address and the IP to the hosts file.

For the administration rights to modify the hosts file i'll use a .bat script to execute the ps.1 file.

Thank you in advance! I'm really curious!!!


Creating Sub directories

$
0
0

Hi there,

Am quite new with powershell Scripting..infact am just laerning how to work with Scripting. am trying to create a script that creates Sub Folders and the names of all the Sub Folders created should not have spaces. For example a Folder called MY SPACE I want the script to creat it like MY_SPACE.

How can i make this happen?

Regards to all!!!

Script to find the total disk space and total free space

$
0
0

Probably a simple question, I am using the below statement to get the drive information, but it is listing multiple drives, all I need is the total allocation and the total free space

get-wmiobjectWin32_LogicalDisk-computername$strComputer-Filter“DriveType = 3"

Thanks in advance

import bulk users help

$
0
0

Hi Everyone,

I just created a script to import users on mass using the script that most people use

Import-Csv .\importbulkusers_contractors.csv | foreach-object {
$userprinicpalname = $_.SamAccountName + "@{internal;bcpharmacists}.org"
New-ADUser -SamAccountName $_.SamAccountName -Name $_.name -DisplayName $_.DisplayName -GivenName $_.GivenName -SurName $_.sn -Description $_.Description -Path $_.path -AccountPassword (ConvertTo-SecureString "College15" -AsPlainText -force) -Enabled $True -PassThru }

The user account gets created without any errors but the when I go into the account properites in AD users and computers, the UPN name and user logon name aren't there.  I can set it once I go in but I would like the script to do it.  I have tried various things like:

1.  {internal;bcpharmacists}.org (originally it was this {internal.bcpharmacists}.org) and various formations of this.

2. I have tried removing the foreach-object switch and adding the UPN switch to the New-ADUser line but no success.  I'm running out of things to try so was wondering if anyone had any ideas?


Thanks in adavnce

Email One File at a time until all files have been Emailed

$
0
0

I may have more than 1 "NBJC File" that I would like to send separate emails for each file. For Example:

1.NBJC.pdf should be its own email

2.NBJC.pdf should be its own email

3.NBJC.pdf should be its own email

The script below works well if I only have one file in the directory; however, if more than one file exists  then all of the files move and I do not get any emails. Any ideas on how to fix this? Again - I would like to email one file at a time

$File = GCI \\10.10.10.10\jcfiles\JCProductionDatabases\POM\NBJC*
Send-MailMessage-From"CES@JCGI.com"-To"jc@jcgi.com"-Subject $File.name-Attachments $File -SmtpServer10.10.192.10 

move-item \\10.10.10.10\jcfiles\JCC-ProductionDatabases\POM\JC011* \\10.10.10.11\jcfiles\JC-ProductionDatabases\POM\Archive -force
                                         

Powershell custom object in a script file not working

$
0
0

I am using v4 of Powershell and below code(two custom object) in a powershell script file(.ps1) does not print two outputs from custom object, while, if you execute each command in a powershell console all output is received. Pls help!:

Why is the below script not working when run via powershell script file but works when each line is executed in powershell console?

NB - I need to use two custom objects

$Srvlogin = New-Object -TypeName PSCustomObject
$Srvlogin | Add-Member -Type NoteProperty -Name 'LoginName' -Value "One"
$Srvlogin # output 1
$login = New-Object -TypeName PSCustomObject
$login | Add-Member -MemberType NoteProperty -Name 'DBLoginName' -Value "Two"
$login # output 2

==>Output when run via a .ps1 script file (not working!):
LoginName
---------
One

==>Output when run each line of command in console:

.

LoginName
---------
One

.

.

DBLoginName
-----------
Two

Send an email from my Smtp Server

$
0
0

Here is my powershell to send an email from my smtp server. 

My real smtp server exists and functions correctly.

This PS script takes a long time to run and below is the error code:

$subject = "This Subject"
$body =  "The Body and the subBody"
$emailTo = "toemail@email.com"
$emailFrom ="fromemail@email.com"
$smtpServer = “smtp.email.com”
$port="25"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$credentials=new-object system.net.networkcredential(”email@email.com”,”password”)
$smtp.credentials=$credentials.getcredential($smtpserver,$port)
$PlainPassword = "mainpassword"
$SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force
$UserName = "MYSITE\Administrator"
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword
Send-MailMessage -To $emailTo -Subject $subject -Body $body -SmtpServer $smtpServer -From $emailFrom -Credential $Credentials -Port $port -UseSsl

PS Error Code:

InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException



Update AD from CSV

$
0
0
Hi

I need to upgrade more than 1500 users the userprincipalname attribute.
I have a CSV with this format:

sAMAccountName, userprincipalname-OLD, userprincipalname-NEW
Thor, thorelpoderoso@domain.local, thor-elpoderoso@domain.local
Peter, petermax@domain.local, peter-max@domain.local
July, julio-swar@domain.local, julio.swar@domain.local

Can you help me please?, I know that it is asking much, but it is something urgent.

Thanks mates!!

Regards

pull report installed patches from one machine and multiple machines

$
0
0

How to pull report installed patches from one machine and multiple machines, again how to pull missing software updates on single and multiple machines

How to learn debugging, identifying syntax error

$
0
0

How to learn debugging, identifying syntax error, warmfull cmdlets in the script etc

Help creating a powershell script to create accounts from excel/CSV sheet

$
0
0

Hi,

I am  needing to create a Power Shell script that will create accounts from a Excel or CSV sheet.     A business department sends us a excel sheet with the following information.  the parenthesis is the property in power shell.   If we need more information than this I can ask it be added but was hoping we could create a power shell script that would import the needed information from the sheet and then create the accounts and place this in a specified OU.

any help would be appreciated. 

Dealer (Description)Contact (CN)Email Address(EmailAddress)Log On (SamAccountName)Password
company01company number01company01@pshelp.com01B2B.test011
company02company number02company01@pshelp.com02B2B.test021
company03company number03company01@pshelp.com03B2B.test031
company04company number04company01@pshelp.com04B2B.test041
company05company number05company01@pshelp.com05B2B.test051
company06company number06company01@pshelp.com06B2B.test061
company07company number07company01@pshelp.com07B2B.test071
company08company number08company01@pshelp.com08B2B.test081
company09company number09company01@pshelp.com09B2B.test091
company10company number10company01@pshelp.com10B2B.test101
company11company number11company01@pshelp.com11B2B.test111
company12company number12company01@pshelp.com12B2B.test121
company13company number13company01@pshelp.com13B2B.test131
company14company number14company01@pshelp.com14B2B.test141
company15company number15company01@pshelp.com15B2B.test151
company16company number16company01@pshelp.com16B2B.test161
company17company number17company01@pshelp.com17B2B.test171
company18company number18company01@pshelp.com18B2B.test181
company19company number19company01@pshelp.com19B2B.test191

unable to restore deleted user into a new OU

$
0
0

I am using the restore-adobject cmdlet to restore a deleted user account into a newly created OU. However, it was giving the following error

Restore-ADObject : The operation could not be performed because the object's parent is either uninstantiated or delete
At line:1 char:159

Yes, this deleted account was in a OU that was also deleted. That is the reason why I want to restore the account into a different OU by using the -targetpath para. But that didn't seem to work.

Thanks

what are point’s needs to know as administrator before writing or executing any power shell scripts?

$
0
0

 Can I know what are point’s needs to know as administrator before writing or executing any power shell scripts?

Insert custom object typename for a pscustomobject

$
0
0

Hello Community

I'm a Little bit stuck with this and now I hope to find an anwser here. So any suggestions or tipps would be great. A short description of what I want to achieve.

First im declaring an Array for my final object with is called UserConfiguration

Userconfiguration = @()

Then I read an Excel file cell by cell using a given range. After that I store each line of data into a hashtable witch then will be "converted" to an pscustom object.

 

    $ExcelApp = Get-StartApps Excel
    if($ExcelApp) { $Excel = New-Object -ComObject "Excel.Application" }
        else { Write-Error "No Excel App is installed on this system." -Category "Missing App" -RecommendedAction "Install a local copy of excel" -ErrorAction Stop }
   
    $File = "AccountInfoblatt.xlsx"
    $Excel.Visible = $false
    $WorkBook = $Excel.Workbooks.Open($File)
    $WorkSheet = $WorkBook.Sheets.Item("Eintritt")

    # creating excel sheet configuration

    $MaxUsedRows  = ($WorkSheet.usedrange.rows).count
    $MaxUsedColumns = (($WorkSheet.UsedRange.columns).count) - 1
    $CurrentRow = 2
    $CurrentColumn = 2

    $UserConfiguration = @()

    do
    {
        Write-Progress -Activity "Parsing User Data" -PercentComplete ($MaxUsedRows / 100 * $CurrentRow)

        # Reading excel file row by row
   
        $Data = $WorkSheet.Cells.Item($CurrentRow,$CurrentColumn + 1).Value()
        $Header = $WorkSheet.Cells.Item($CurrentRow,$CurrentColumn).Value()
        $Attribute = $WorkSheet.Cells.Item($CurrentRow,$CurrentColumn + 2).Value()
               
        $UserProperties = @{
                                    Value = $Data
                                    Header = $Header
                                    Attribute = $Attribute
                           }
              
                            $CurrentRow ++

        # creating customobject
   
        if($data -eq $null) { <# no object #> } else { $UserConfiguration += [PsCustomObject]$UserProperties }

    }
    while ($CurrentRow -le $MaxUsedRows)

Write-Output $UserConfiguration

So this works great for me and I'm getting an object returned with a type of System.Management.Automation.PSCustomObject

Now I want to insert a custom typename for that object so I can do a Little bit more on de Default formatting of the ouput.

If I do $userConfiguration.pstypenames on that object it tells me the following

System.Object[]
System.Array
System.Object

If I now do $userConfiguration.pstypenames.clear() it does clear all the type names. So far so good

Now I do $userConfiguration.typenames.insert(0,'My.Custom.Type'). It does this as I check the pstypenames again but now if i do a get member on the object again it still tells me that the typename is System.Management.Automation.PSCustomObject.

How can i achive this? Is this because i have an underlaying Array in this object?

Thanks for help. Cheers Lumu


How to create multiple shares using a single PowerShell command on Server 2008

$
0
0

        I have 300 users folders that I need to migrate from a 2003 server to a new 2008R2 server.  Server 08 grants read-only by default when creating a share and I need this to be "change" for each user.  Here is what I need:

path is E:\users\ (each subfolder in this directory is a username)

The share names need to match the folder name.  The file permissions are correct; I just need to set the share permissions to "change".  My migration takes place next Saturday night (IT never sleeps), so please HELP!  Thanks


-Mike

about noun and verb in a cmdlet

$
0
0

How to know about noun and verb in a cmdlet. If noun means where the actions and verb is action so can I know some examples

basic knowledge of powershell

$
0
0

How to get basic knowledge of powershell like small description of PowerShell, cmdlets, functions, modules, snapping, sample scripts over all hint about power shell off course it will be strong basement

restore to back

$
0
0

By accidently or unknowing if wrong commands happens or it causes major impact if any option to restore to back? Second question how to use breakpoints or check points in PowerShell script to avoid unwanted events

install MSI file, EXE, software update via PowerShell on multiple machines

$
0
0

How to install MSI file, EXE, software update via PowerShell on multiple machines

Viewing all 21975 articles
Browse latest View live


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