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

Rebooting multiple servers as same time via PowerShell?

$
0
0

We want to reboot 30+ servers at the same time.  This heart of the matter comes down to this script.

get-content c:\Servers.txt | %{Restart-computer –computername $_ –force}

 

But is using PowerShell really a good solution to the problem?  I don't know what version of Powershell (if any) is  running on each remote server, what firewall issues we may encounter, either.  I need a "rock solid" approach that does the job and hopefully spares me from needing to setup a "reboot" script on each individual server.

TIA,

Barkingdog

 



How to change format of phone numbers in PowerShell?

$
0
0

We need to append the area code and hyphen in front of the office phone number field in their domain user account for all our users that have office phones now that we are changing from 7 digit numbers to 10 digit numbers.

I found a script that finds and edits phone numbers, but the author chose a different way to format the numbers.

This is the part of the script I need to change:

# Format number as xxx xx xx xxx.
        $Phone = '{0} {1} {2} {3}' -f$Phone.Substring(0,3),$Phone.Substring(3,2),$Phone.Substring(5,2),$Phone.Substring(7,3)

I'm trying to figure out how to edit that so that it formats it as xxx-xxx-xxxx (3 digit area code, hyphen, 3 digit prefix, hyphen, four digit number) instead of xxx xx xx xxx.

Can someone show how to rewrite this section?


automated differential backups with powershell

$
0
0
I am trying to figure out how to create automated differential backups for a windows 8 system with PowerShell.  I need the full backup to be performed weekly and saved on the F:, but then I need the differential back ups to be done daily and saved on the G:.  I need the new differential backup to overwrite the old differential backup from the previous day.

How to get DocSet property values in a SharePoint library into a CSV file using Powershell

$
0
0

Hi,

How to get DocSet property values in a SharePoint library into a CSV file using Powershell?

Any help would be greatly appreciated.

Thank you.


AA.

Change Calendar default sharing policy

$
0
0

Hi Guys,

The Office365 and Exchange Online support person refer me to this forum. Could any one please help?

Here is the story:

We are using Exchange Online and Office365. My boss ask me to force all users to share their detailed calendar to other, not just "free and busy".

I know we can do it manually one by one, but considering lots of users aren't skilled computer cooperator, so I want it to be done automatically by using script.

I found a quite useful link: http://community.office365.com/en-us/f/158/t/54401.aspx

The powershell script mentioned on the above thread was running successfully, however, when I back to check the calendar of Outlook2013, nothing has been changed after running the script. Some users have their calender displayed as free or busy.

Please notice our domain is XXX.local and our primary email address is @XXX.co. I am not sure which one to be used in the script.

Here is the details of my script:

PS C:\Users\Administrator.XXX> Set-SharingPolicy -Identity "Default Sharing Policy" -Domains 'XXX.co:CalendarSharingFreeBusyReviewer', 'Anonymous:CalendarSharingFreeBusyReviewer', '*:CalendarSharingFreeBusySimple'
Creating a new session for implicit remoting of "Set-SharingPolicy" command...

PS C:\Users\Administrator.XXX> Get-SharingPolicy |fl


RunspaceId : 07e0f104-d386-4676-843d-XXXXXXXXXX
Domains : {XXX.co:CalendarSharingFreeBusyReviewer, Anonymous:CalendarSharingFreeBusyReviewer,
*:CalendarSharingFreeBusySimple}
Enabled : True
Default : True
AdminDisplayName :
ExchangeVersion : 0.10 (14.0.100.0)
Name : Default Sharing Policy
DistinguishedName : CN=Default Sharing Policy,CN=Federation,CN=Configuration,CN=xxxapps.onmicrosoft.com,CN=Configuratio
nUnits,DC=APCPR01A001,DC=prod,DC=outlook,DC=com
Identity : Default Sharing Policy
Guid : 807d8414-3e10-47f3-bddf-xxxxxxxxxxxx
ObjectCategory : APCPR01A001.prod.outlook.com/Configuration/Schema/ms-Exch-Sharing-Policy
ObjectClass : {top, msExchSharingPolicy}
WhenChanged : 25/03/2015 9:36:25 a.m.
WhenCreated : 12/06/2013 11:49:42 a.m.
WhenChangedUTC : 24/03/2015 8:36:25 p.m.
WhenCreatedUTC : 11/06/2013 11:49:42 p.m.
OrganizationId : APCPR01A001.prod.outlook.com/Microsoft Exchange Hosted Organizations/xxxapps.onmicrosoft.com -
APCPR01A001.prod.outlook.com/ConfigurationUnits/xxxapps.onmicrosoft.com/Configuration
Id : Default Sharing Policy
OriginatingServer : xxxxxxxxxxxxxx.APCPR01A001.prod.outlook.com
IsValid : True
ObjectState : Changed

 


Could anyone please advise if I make a mistake?

Thank you very much in advance.

Cheers,

Vincent


Replace only the first space

$
0
0

Hello,

is there a way to replace only the first space with a semicolon for each line in a file?

Greetings


PowerShell Script for updating accounts in CSV

$
0
0

Hi Experts...!!!!

I need to have a power shell script that can update the status(Enable/disable) accounts given in a .csv file with DNs of the user accounts in it....

Any suggestions...

Thank You... 


TechSpec90

for-each loop

$
0
0

trying to do a loop here like this

$vmwareluns = get-content c:\luns.txt

$igroup = get-content c:\igroup

 

foreach ($i in $vmwareluns}

    {add-nalunmap $vmwareluns $igroup}

but keep getting error

any idea?

do I need to add another loop? 

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

igroup contents

igroup1

igroup2

igroup3

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

luns.txt contents

lun1

lun2

lun3

 


Running PowerShell script from console, or .exe file, without error, while using file dialog boxes.

$
0
0

Hi,

I have a script, which has file open dialog box statement in it, with Windows Forms, for its front end. If I run script from PoweShell ISE, it runs fine. The forms look, feel and file open dialog box behaves as usual.

The moment, I run script from console, or convert it to .exe file using PS2Exe, the two unusual things happen:

  1. The forms look and feel, looks outdated and plain.
  2. When I click button, for file open dialog box, the whole UI hangs and it becomes unresponsive.

Why is this so? How can I overcome this?

# code snippet
Add-Type -AssemblyName System.Windows.Forms
[reflection.assembly]::loadwithpartialname("system.windows.forms") | Out-Null

# form
$form = New-Object System.Windows.Forms.Form
$form.Height = 700
# rest of the code
$form.ShowDialog()

# open dialog code
$filedialog = New-Object System.Windows.Forms.OpenFileDialog
    $filedialog.initialDirectory = $initialDirectory
    $filedialog.filter = "All files (*.*)| *.txt*"
    $filedialog.ShowDialog() | Out-Null
    $form.Text = $filedialog.fileName

What is cause and solution for this problem?

Acces Denied when running set-aduser and delegated rights

$
0
0

Hi,

when a user with delegated rights run a script to change an specific field he gets the message access denied.

If he changes the value over the ADUC snapin, he can change the field where he has the rights.  

if ($objext2txtbox.text -ne "") {set-aduser -Identity $user.DistinguishedName[0] -Replace @{employeeNumber=@($objext2txtbox.text)}} else {$user.employeeNumber.clear()}

Above the codesnip where the change will be set. If the complete code is required i can post that one too.

Best regards

Malte

Powershell 4: Start-Transcript does not log Write-Host

$
0
0

Hi, 

After creating an instance of the latest Windows Server 2012 R2 image on Windows Azure, we see a strange issue with Powershell transcripts: Write-Host is not transcribed. However, "foobar" | Out-Host IS transcribed! Very strange. However, both Write-Warning, and any errors (exceptions, or write-error) does give output.

Anyone else seen this issue? Is this expected behavior or a bug?

Thanks a lot in advance! :-)

Sincerely,

Hallgeir

Here's my powershell version info:

PS C:\> $psversiontable

Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.34014
BuildVersion                   6.3.9600.17400
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2

Example:

**********************
Windows PowerShell transcript start
Start time: 20150114143638
Username: xxx\xxx
RunAs User: xxx\xxx
Machine: xxx (Microsoft Windows NT 6.3.9600.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 2160
**********************
Transcript started, output file is C:\foobar.txt

PS C:\> Write-Host "This is a test"

            CurrentMatchIndex              ReplacementIndex             ReplacementLength CompletionMatches
            -----------------              ----------------             ----------------- -----------------
                           -1                             0                            12 {System.Management.Automat...



PS C:\> Stop-Transcript
**********************
Windows PowerShell transcript end
End time: 20150114143658
**********************

Here's how it looks with piping to Out-Host:

**********************
Windows PowerShell transcript start
Start time: 20150114143755
Username: xxx\xxx
RunAs User: xxx\xxx
Machine: xxx (Microsoft Windows NT 6.3.9600.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 2160
**********************
Transcript started, output file is C:\foobar.txt

            CurrentMatchIndex              ReplacementIndex             ReplacementLength CompletionMatches
            -----------------              ----------------             ----------------- -----------------
                           -1                            19                             8 {System.Management.Automat...



PS C:\> "This is a test" | Out-Host
This is a test

            CurrentMatchIndex              ReplacementIndex             ReplacementLength CompletionMatches
            -----------------              ----------------             ----------------- -----------------
                           -1                             0                             9 {System.Management.Automat...



PS C:\> Stop-Transcript
**********************
Windows PowerShell transcript end
End time: 20150114143809
**********************


Populate IP Phone field in AD based on entries in a csv file

$
0
0

Hi,

Is there a way to populate the IP Phone field in AD based on a csv?

I tried the following link but no luck: http://en.community.dell.com/techcenter/powergui/f/4834/t/19569423

Thanks in advance,

Johnross

Powershell script throwing "Index out of range exception" only at first execution and next time onwards runs fine.

$
0
0

I have put together a powershell script which takes input from a csv file. The script queries the samaccountname from the input csv and then checks the domain specified in the csv, for which it should search the user.

The script then logs the value of a particular attribute for users specified in the csv and then updates that attribute value with a new value specified in the input csv.

On every first instance, the script's catch block logs the below error for the first user in the input csv but then works absolutely fine for the remaining users. Also, the next time the script executed again from the already open ISE, works absolutely fine. Can someone please guide.

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.Collections.ArrayList.set_Item(Int32 index, Object value)
   at CallSite.Target(Closure , CallSite , Object , Int32 , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at System.Management.Automation.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)



Delete empty folders

$
0
0

Here is my folder structure

D:\FileClenup\Archive\DC01\20150401\.xmls

D:\FileClenup\Archive\DC01\20150331\.xmls

D:\FileClenup\Archive\DC01\20150402\.xmls

D:\FileClenup\Archive\DC01\20150332\.xmls

I am deleting empty directories if have in the Archive <g class="gr_ gr_42 gr-alert gr_gramm Punctuation only-ins replaceWithoutSep" data-gr-id="42" id="42">folder</g> but all folders are deleting

Below command is using for delete empty directories in the Archive folder

# Delete Empty Directories

$currentPath= D:\FileClenup\Archive

                              $emptyDdirectories = Get-ChildItem -Path $currentPath -Recurse | Where {$($_.Attributes) -match "Directory" -and $_.GetFiles().Count -eq 0} | Foreach {

        Remove-Item $_.FullName -Recurse -Force}

                              ###

Please suggest you are thoughts  

Exporting just username(s) from query session

$
0
0

Hi all,

Just wondering how to export just the username from: query session /server:"server"

When the results come out like this:  

SESSIONNAME      USERNAME             ID  STATE   TYPE        DEVICE

 rdp-tcp#0           test                         2  Active   

I just want the results form the username column

I need just the users to add an extra field into this code:

$CSV = @""Name","Operating System","Description""DC01","Windows Server 2008 R2","Domain Controller""DC02","Windows Server 2012 R2","Domain Controller""@
$Servers = ConvertFrom-Csv $CSV
$Servers | Out-GridView -Title "Select a server" -PassThru | Select Name |
    %{Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "/v:$($_.Name)"}

Once I can get the usernames ill add a "username" field. We can then use this to select a server, get description and see who/if anyone is logged into the server.

Thanks for any help with this.




get members by group from a forest

$
0
0

I have multiple domains in our forest and I'm trying to pull a list (csv) of all the members of groups with a PCSupport in the name.

I've been able to get the groups or members of the group in my specific domain but not the others.

One or the other and haven't been able to put it all together. This has gotten me the farthest along, I've got all the groups listed, but I don't know how to feed this into additional scripting to get the groups and members into a csv.

Thanks in advance for any help

$forestName = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Name

$ADsPath = [ADSI]"GC://$forestName"

$Search = New-Object System.DirectoryServices.DirectorySearcher($ADsPath)

$Search.Filter = "(&(objectCategory=group)(SamAccountName=*PCSupport))"

$Search.FindAll()

Path                                                                         Properties                                                                
----                                                                         ----------                                                                
GC://mycompany.com/CN=PCSupport,OU=Groups,DC=domain1,DC=mycompany,DC=com             {samaccountname, objectsid, instancetype, objectclass...}                 
GC://mycompany.com/CN=Co-_PCSupport,OU=Groups-Reserved,OU=ServerWorkstations,D... {info, samaccountname, objectsid, instancetype...}                        
GC://mycompany.com/CN=PCSupport,OU=Groups,DC=domain2,DC=mycompany,DC=com                  {samaccountname, objectsid, instancetype, objectclass...}                 
GC://mycompany.com/CN=PCSupport,OU=Groups,DC=domain3,DC=mycompany,DC=com       {samaccountname, objectsid, instancetype, objectclass...}                 
GC://mycompany.com/CN=PCSupport,OU=Groups,DC=domain4,DC=mycompany,DC=com                {samaccountname, objectsid, instancetype, objectclass...}                 
GC://mycompany.com/CN=PCSupport,OU=Groups,DC=domain5,DC=mycompany,DC=com                 {samaccountname, objectsid, instancetype, objectclass...}                 
GC://mycompany.com/CN=PCSupport,OU=Groups,DC=domain6,DC=mycompany,DC=com        {samaccountname, objectsid, instancetype, objectclass...}                 
GC://mycompany.com/CN=PCSupport,OU=Groups,DC=domain7,DC=mycompany,DC=com               {samaccountname, objectsid, instancetype, objectclass...}                 
GC://mycompany.com/CN=PCSupport,OU=Groups,DC=domain8,DC=mycompany,DC=com                   {samaccountname, objectsid, instancetype, objectclass...}                 
GC://mycompany.com/CN=PCSupport,OU=Groups,DC=domain9,DC=mycompany,DC=com            {samaccountname, objectsid, instancetype, objectclass...}                 
GC://mycompany.com/CN=PCSupport,OU=Groups,DC=domain10,DC=mycompany,DC=com                  {samaccountname, objectsid, instancetype, objectclass...}                 
GC://mycompany.com/CN=PCSupport,OU=Groups,DC=domain11,DC=mycompany,DC=com        {proxiedobjectname, samaccountname, objectsid, instancetype...}           


Tom

Copy one zip file into another

$
0
0

I know this should be pretty simple but I keep staring at this wondering what is wrong.

I am trying to copy one pre-existing zip file into another zip file:

Copy-Item"C:\Accounts\Amex\DynamicUpdate2""C:\Temp\MyBigZipFile.zip"

What I end up getting is an error :

Copy-Item: Container cannot be copied on to existing leaf item

Not sure what this exactly means? Also, if I want to copy the source zip file into a specific directory in the destination zip file, how would I do that?

Thanks!

Clicking a link on one site works but same code does not work on another

$
0
0

I am writing a powershell script to open an ie instance and navigate a couple of pages.  I have a script that works on many pages but not on others.  This code works on many pages

$ie = new-object -com InternetExplorer.Application
$ie.navigate2($url)
do{sleep 1} until (-not($ie.Busy))
$ie.visible=$true
$link = $ie.Document.getElementById('_b7ese')
$link.click()

However, it does not work on other pages.  One example of a link I am attempting to click is as follows

&nbsp;|&nbsp;<div class=rr id=_mk_sw><a _sf=false bh=HL id=_tfr3sd href="#" style="text-decoration:none;">Logout</a></div>

the page simply stays put and does nothing.

Need a hand getting output of script formatted properly

$
0
0

Hi guys. I'm working on a script that will help me find a bunch of little useless files. I want to make the output look like:

D:\path\file1
D:\path\file2

What I get is something that looks like below which isn't helpful for what I'm trying to do with this information. My question is what do I need to change to get the output to look like what I want?

Directory: D:\gmapp\GoldMine\MailBox\Attach\abougoulas\ABOUGOUL\2010\02


Mode                LastWriteTime     Length Name                                                                     
----                -------------     ------ ----                                                                     
-----         2/15/2010   1:52 PM       5229 ASI Commission Report.txt                                                
-----         2/11/2010   6:52 PM       3919 image001.png                                                             
-----         2/19/2010   4:45 PM      22016 NEW CLIENT QUESTIONNAIRE.doc                                             
-----         2/25/2010   3:57 PM      22016 Print check list.doc                                                     
-----         2/10/2010   9:35 AM      48911 second dwelling 6.pdf                                                    
-----         2/22/2010   3:12 PM      42534 signatureimage.bmp                                                       
-----         3/31/2010   1:37 PM       7168 Thumbs.db     

#This Script looks through the results we pulled and finds anything less than 50kb.
#MEntion the path to search the files
$path = "D:\gmapp\GoldMine\MailBox\Attach"
#Find out the files less than mentioned size
$size = 50kb
##Limit the number of rows
$limit = 100000
#Find out the specific extension file
$Extension = "*.*"

##script to find out the files based on the above input
get-ChildItem -path $path -recurse -ErrorAction "SilentlyContinue" -include $Extension | Where-Object {(-not $_.PSIsContainer) -and ($_.Length -lt $size)} | Out-File "c:\FileSizeFirst\small_$(get-date -f yyyMMdd).txt"



Change Default Calendar Permissions

$
0
0

Hello,

I have asked this on the email and calendar forum but it's been suggested that I post here.

We would like all users to have access to the calendars of all other users but seeing full details rather than the default free/busy.

I've been given the command below which is for one user and wonder if it is possible to tweak to apply to all users?

Add-MailboxFolderPermission -Identity SharedMailboxName:\calendar -User UserName -AccessRights Editor


itswt

Viewing all 21975 articles
Browse latest View live


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