Excel & PowerShell

Shawnathon

New Member
Joined
Feb 16, 2011
Messages
45
Can anyone help me with a script in PowerShell that works with Excel? Having some errors and need help. Thanks

Shawn
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I have the PowerShell Script. If anyone can help me or point me in the right direction I would appreciate it. Thanks!

Here's the PowerShell Script, it works with Excel. I'm getting a error message and need to know if anyone can help me fix it, thanks.

The script is made to log into your twitter account and extract your friends in Excel. Any help is appreciated.

[System.Reflection.Assembly]::LoadWithPartialName(”twitter.com") | Out-Null

$userName = "username"
$password = "password"

Function Get-TwitterFriends {
param ($userName, $password, $ID)
if ($WebClient -eq $null) {$Global:WebClient=new-object System.Net.WebClient }
$WebClient.Credentials = (New-Object System.Net.NetworkCredential -argumentList $username, $password)
$page = 1
$Friends = @()
if ($ID) {$URL="http://twitter.com/#!/$ID.xml?page=/followers"}
else {$URL="http://twitter.com/statuses/friends.xml?page="}
do { $Friends += (([xml]($WebClient.DownloadString($url+$Page))).users.user )
$Page ++
} while ($Friends.count -eq 100)
$Friends
}

function out-excel {

param ([string[]]$property,[switch]$raw)

begin {
# start Excel and open a new workbook
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Item(1)
# initialize our row counter and create an empty hashtable
# which will hold our column headers
$Row = 1
$HeaderHash = @{}
}

process {
if ($_ -eq $null) {return}
if ($Row -eq 1) {
# when we see the first object, we need to build our header table
if (-not $property) {
# if we haven’t been provided a list of properties,
# we’ll build one from the object’s properties
$property=@()
if ($raw) {
$_.properties.PropertyNames | %{$property+=@($_)}
} else {
$_.PsObject.get_properties() | % {$property += @($_.Name.ToString())}
}
}
$Column = 1
foreach ($header in $property) {
# iterate through the property list and load the headers into the first row
# also build a hash table so we can retrieve the correct column number
# when we process each object
$HeaderHash[$header] = $Column
$Sheet.Cells.Item($Row,$Column) = $header.toupper()
$Column ++
}
# set some formatting values for the first row
$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 19
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True
$WorkBook.HorizontalAlignment = -4108
}
$Row ++
foreach ($header in $property) {
# now for each object we can just enumerate the headers, find the matching property
# and load the data into the correct cell in the current row.
# this way we don’t have to worry about missing properties
# or the “ordering” of the properties
if ($thisColumn = $HeaderHash[$header]) {
if ($raw) {
$Sheet.Cells.Item($Row,$thisColumn) = [string]$_.properties.$header
} else {
$Sheet.Cells.Item($Row,$thisColumn) = [string]$_.$header
}
}
}
}

end {
# now just resize the columns and we’re finished
if ($Row -gt 1) { [void]$WorkBook.EntireColumn.AutoFit() }
}
}

Get-TwitterFriends $userName $password | select name,screen_Name,url | out-excel
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top