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

I want to use an error to modify a file.

$
0
0
# Import new users
$ADUserfiles = Get-ChildItem $userfolderpath\*.csv
foreach ($Ufile in $ADUserfiles)
{
  # Import new users
.\tabcmd createusers $Ufile $TabParam
}

The snippet of code above uses a command line tool to add users to to my application.   I have run into a problem.
When the script gets to a particular user(s) it will fail and it skips that entire file instead of just skipping that one ID.   This occurs in 2 of my files so far while testing.  I can't modify tabcmd, it's part of an application.

What I would like to do is capture this error and use it to delete the row containing that ID then have the script rerun the file.

===== Error importing processing users CSV file (file reference: 5)
No Active Directory account named <i>usera usera</i>.


I thought about using Try/Catch but I don't know how to capture the error and pass just the id contained in the error to a variable that I can then use to delete the row from the file.   There could be many different problem id's contained in 1 or many different files.  If it has to loop through a file once or many times that is ok with me.  

Any help is appreciated.


Why doesn’t my powershell V.3 on Windows 7 have the get-adgroup commandlet?

$
0
0

My job involves getting lists of AD group members. I’ve installed PS V3; but, it doesn’t have any of the AD related commandlets.  Yes I am a beginner

Get Active Directory Users and Computers in AD Module Powershell

$
0
0

Dears,

I have active directory and exchange 2010, I would like to know how many users active with computer names in my system, I'm looking for AD power shell or any other ways to find all the user information with computer names.

Thanks..

Find and Replace

$
0
0

Hi, I'm doing a find a replace and when I run the below I get this error.  Any suggestions for how to get around this file limitation?  I'm running this Powershell as administrator and running Set-ExecutionPolicy Remotesigned first byitself.

Script:

 

$exclude = @("*.cspkg", "*.doc", "*.docx", "*.txt")
$excludeMatch = @("Archive")
$from = "\\servername\foldername\foldername\foldername"
$to = "\\servername\foldername\foldername\foldername\recover"
Get-ChildItem -Path $from -Recurse -Exclude $exclude | 
          where { $excludeMatch -eq $null -or $_.FullName.Replace($from, "") -notmatch $excludeMatch } |
          Copy-Item -Destination {
            if ($_.PSIsContainer) {
              Join-Path $to $_.Parent.FullName.Substring($from.length)
            } else {
              Join-Path $to $_.FullName.Substring($from.length)
            }
           } -Force -Exclude $exclude 

Start-Sleep -Second 45 

Get-ChildItem "\\servername\foldername\foldername\foldername\recover" -recurse |
    Foreach-Object {
       $c = ($_ | Get-Content) -join "`r`n"

        $c = $c.Replace('value1','value2')

        $c = $c.Replace('value1','value2')

        $c = $c.Replace('value1','value2')

        [IO.File]::WriteAllText($_.FullName, $c)
    }

Errors:

1.  

Copy-Item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characte
rs, and the directory name must be less than 248 characters.
At line:7 char:20
+           Copy-Item <<<<  -Destination {
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], PathTooLongException
    + FullyQualifiedErrorId : System.IO.PathTooLongException,Microsoft.PowerShell.Commands.CopyItemCommand

2.  

Get-Content : Access to the path '\\servername\foldername\folddername\foldername\foldername\foldername' is denied.
At line:19 char:30
+        $c = ($_ | Get-Content <<<< ) -join "`r`n"
    + CategoryInfo          : PermissionDenied: (\\servername\folder...es\recover\foldername:String) [Get-Content], UnauthorizedAccess 
   Exception
    + FullyQualifiedErrorId : GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand

 3.  I basically want files dumped inot the 'recover' directory with the replaced values but when I go to the recover folder I have tons of extra folders that I don't need?

\\Servername\FolderName\recover\Folder1\Folder2\SameFolder1\SameFolder2\SameFolder1\SameFolder2

(Azure) Saving values inside foreach loops and arrays - help me understand the concept!

$
0
0

Hello!

I'm very new to Powershell, but committed to learning this! I've got a pretty simple script that works, but I'd like to pull one more bit of data out of the script and I'm having trouble understand how, but most importantly the concept behind how.  This is using Azure Powershell Module.

The script loops through all available azure subscriptions assigned to me, for each loop iteration it compares the SDK version of each deployment within the subscription to see if it's less (older) than version 2.2.0.0. and displays details on those that match the -lt criteria. So far so good.

The problem is, I'd like to also add the SubscriptionName in the output for each loop iteration, making it possible to see which SubscriptionName matches with the deployment data that's displayed on screen.

Here's the script working without displaying SubscriptionName:

$subscriptionsArray = @()

Get-AzureSubscription |
    foreach{
        Select-AzureSubscription $_.SubscriptionName
        $subscriptionsArray += (

            Get-AzureService |
            Get-AzureDeployment |
            Where-Object -Property SDKVersion -lt "2.2.0.0" |
            select ServiceName, SDKVersion, DeploymentID, DeploymentName | Format-table -AutoSize
            )
    }
write $subscriptionsArray


What I've tried doing (and am having a hard time understand the concept behind 'why' it's not working), is adding this to the array within the loop: Get-AzureSubscription -Current

$subscriptionsArray = @()

Get-AzureSubscription |
    foreach{
        Select-AzureSubscription $_.SubscriptionName
        $subscriptionsArray += (
            Get-AzureSubscription -Current
            Get-AzureService |
            Get-AzureDeployment |
            Where-Object -Property SDKVersion -lt "2.2.0.0" |
            select ServiceName, SDKVersion, DeploymentID, DeploymentName | Format-table -AutoSize
            )
    }
write $subscriptionsArray

But the piping within the array loop obviously will cause some errors.  I would like help understanding how to add additional statements within the array loop without it affected the piped data.  Is there any way to add additional statements within that array loop?  Why/Why not?

In the meantime, I created my own object, which seems to work, just not as clean output as I'd like (I'm like clean formatting!).

#$subscriptionsArray = @()
$sdkObject = New-Object System.Object
Get-AzureSubscription |
    foreach{
        Select-AzureSubscription $_.SubscriptionName
        #$subscriptionsArray += (
            $sdkObject | Add-Member -type NoteProperty -name SubscriptionName -Value $_.SubscriptionName -force
            $sdkObject
            Get-AzureService |
            Get-AzureDeployment |
            Where-Object -Property SDKVersion -lt "2.2.0.0" |
            select ServiceName, SDKVersion, DeploymentID, DeploymentName | Format-table -AutoSize
            #)
    }
#write $subscriptionsArray

Thank you!


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


How run mstsc from PowerShell and keep PowerShell console usable ?

$
0
0

Hi Everyone!

I created a tool intended to start RDP session to server in environment - list of files is taken from file and menu is created in loop.

Start-ServersMenu

For start mstsc.exe I use code like

[String]$Command = 'mstsc /v:' + $ServerIP

$Result = Invoke-Command -Scriptblock { param ($CommandToExec) cmd.exe /C  $CommandToExec } -ArgumentList $Command

mstsc.exe is started successfully but - as you see on screenshot above - PowerShell is not usable :-/

Is it possible to resolve it? I tried with -AsJob but with this parameter GUI for mstsc.exe is not displayed.

Thank you in advance for any help.


Wojciech Sciesinski

A String or not a String..... | MOC 10961B LABA from Module 10

$
0
0

Hi,

I'm a MCT and giving Powershell Classes. I'm teaching the Course 10961 for a while now, but I never figured something out, occuring in the LAB from Module 10 (Putting it all together):

in the Lab you get the "Old Ipaddress" via get-DHCPv4ServerLease and the MACAddress of that Server Core instance.

$OldIPaddress = get-DHCPv4Serverlease -Computername LON-DC1 -ScopeID 10.0.0.0 | where-object {$_.ClientID -eq "WA-TH-EV-ER-00"} | select -expandproperty IPAddress | select -expandproperty IPAddressToString


as a result you get the IP adress saved in the Variable $OldIPAddress.... if you pipe it in get-member you see its a [System.String]

but nonetheless, you have to "place the $OLDIpaddress variable in double quotationmarks, and assign the resulting string to $OLDIpaddress. This will convert the IP Address to a string Object" (Page 10-9 from the offical MOC Course-Book, Exercise 2, Task2, step number 10)

Alright it works... but I don't get why you need to do this.... because it is already a string!

If you do not do this, Setting the trustedHostsList will fail with [i]"cannot convert System.Object[] to System.String"[/i] even though get-Member (or the method gettype()) says that it IS ALREADY a System.String...

Set-Item WSMAN:\localhost\Client\TrustedHosts -Value $OldIPaddress

That really bothers me and I cannot explain this to my Students....

Can anyone help me?

Sorry for bad english... I'm German ;)


Need Help on IF Condition..

$
0
0

 


$BooL = 0
foreach($server in (gc .\ADservers.txt)){
if (Test-Connection $server -Count 1 -Quiet) {
Write-host "$Server is able to connect"
$BooL = 1

break


else {
write-host "$Server - Failed"
$BooL = 0
}

}

If ($BooL = 0) {
write-host "None of the Servers mentioned are reachable, The Script will quit..!!"

exit

}
$BooL
Write-Host "Rest of the Script ... :)"

In the above set of code the $BooL value never changes to 1 and Also the If ($BooL = 0) not showing the output.. Can anybody help me on this.. 


Powershell Find RSAT and install if not installed

$
0
0

Creating a UI for password resets and account unlock tool for supervisors to use (after delegating permissions)

I found one that someone created and modified it quite a bit (cleaned it up, added in some email notification of tool use for security) and it seems to be working well.  The tool has a prerequisite of RSAT on the computer.  I would like to build this into the tool to query and install if not installed. This would be easy with windows server 2012 or windows 8 as they have the new command add-feature etc.

I can not seem to find this for windows 7 though.

Anyone have any ideas of how to query rsat on windows 7, and install if not installed - via powershell

Thanks

John

WSUS and Windows Update

$
0
0
In a workgroup environment, no domain, no group policy, cannot configure registry key on the client.

From my management machine I want to run a powershell script to download patches from a specific patch group in wsus onto this new machine and install the patches.

How can I achieve this with Powershell?
How do I approve patches using powershell.

Learn how to use Powershell with AD, Exchange and Excel

$
0
0

Hi.

I want to learn how to script in Powershell to make my life easier at work.

Now, I'm creating Distribution Lists with cmdlets, and other simple moves, but I'd like understand and use scripts with Excel to make it easier in AD and Exchange.

Can anyone help me find out where I can learn Powershell with those tools? I've searched google and youtube, and bought books, but I'd like to learn especially about AD and Exchange through Excel.

I also have another question, I'm trying to collect the telephonenumbers in one OU in AD, and found this cmdlet:

Get-AdUser -Filter * -Properties OfficePhone | FT OfficePhone,UserPrincipalName

I lined ut the OU path before -Filter, and used * -Properties Telephones Mobile to find the phonenumber in Properties-Telephones-Mobile in Active Directory. But I'm obviously doing something wrong.

Could anyone please help me? 

 

Getting User Attributes from Multiple Domains

$
0
0

Hello,

I have a single AD group that contains users from multiple domains.  I can use the 'Get-ADGroupMember' cmdlet to get the standard attributes of the users, but how would I script it to output the extended attributes?  I'd like to end up with a CSV containing First Name, Last Name, email address, etc.

Any help with this would be greatly appreciated.

-Quinn

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

Script doesn't work in task scheduler

$
0
0

I know it has already posted many times but I have already tried everything and still I can't get it to work.

The script is a simple send email function and it works if executed from the command prompt:

powershell.exe -f .\sendEmail.ps1 test@test.com "Test Subject" "Test Message"

But in the task scheduler it doesn't work and no email is sent. The exit code of the task is 0xFFFD0000:

Task Scheduler successfully completed task "\SendEmailTest" , instance "{15ff2070-ee25-4b2e-9ae1-274eda0d8c3a}"

, action "powershell.exe" with return code 4294770688.

The task is configured to run under the SYSTEM account with highest privilege, powershell ist configured with unrestricted execution policy, why it doesn't work?

I have tried also with a simpler task to create a text file

New-Item c:\scripts\new_file.txt -type file -force -value "This is text added to the file"

But it doesn't work too, so it should be some other missing privilege somewhere but I couldn't find anything in internet.

Thanks for any help


Comparing 3 CSV Files and generating output to 4th One..

$
0
0

Hi,

I was trying to compare 3 different CSV files using the common field EmplID and generate output with the combination of all the CSV's. The fields in the CSV are below

CSV1 : EmplID,HName,Name,PreferredName,Location,Department
CSV2 : HName,EmplID,first_name,last_name,email
CSV3 : Emplid,Extension

I would like to generate the output CSV as below..
OutputCSV :EmplID,Hname,Name,PreferredName,Location,Department,first_name,last_name,email,Extension

The below script works but as it is comparing the data by row by row, it takes huge time to complete.. Can anybody suggest how can i improve the performance of the same... 

$CSV1 = Import-CSV "Abc.CSV"
$CSV2 = Import-CSV "DEF.CSV"
$CSV3 = Import-CSV "GHI.CSV"

$Merged = ForEach($Record in $CSV1){
    Add-Member -InputObject $Record -NotePropertyName 'first_name' -NotePropertyValue ($CSV2|Where{$_.EmplID -eq $Record.EmplID}|Select -Expand first_name)
    Add-Member -InputObject $Record -NotePropertyName 'last_name' -NotePropertyValue ($CSV2|Where{$_.EmplID -eq $Record.EmplID}|Select -Expand last_name)
    Add-Member -InputObject $Record -NotePropertyName 'email' -NotePropertyValue ($CSV2|Where{$_.EmplID -eq $Record.EmplID}|Select -Expand email)
    Add-Member -InputObject $Record -NotePropertyName 'Extension' -NotePropertyValue ($CSV3|Where{$_.EmplID -eq $Record.EmplID}|Select -Expand Extension) -PassThru
}
$Merged | Export-CSV C:\Path\To\New.CSV -NoTypeInfo



Parse text file with regular expression

$
0
0

Hello, dear colleagues.

Help please to parse file with regular expression

x-sender: Chuck.Norris@hotmail.com
x-receiver: ***************************
Received: from ***** with Microsoft SMTPSVC(7.5.7601.17514);
	 Fri, 20 Mar 2015 12:43:03 +0200
In-Reply-To: <********@LocalDomain>
To: *****************************
Bcc:
Subject: Incident ID#: 117 Something wrong, something right, something missing
Message-ID: <*****************************@LocalDomain>
From: Chuck.Norris@hotmail.com
Date: Fri, 20 Mar 2015 12:42:55 +0200
Content-Type: multipart/related; boundary="=_related ********************"
References: <*******************************C@LocalDomain>
MIME-Version: 1.0
X-KeepSent: ****************************; name=$KeepSent; type=4
X-Mailer: Lotus Notes Release 8.5.2FP3 July 11, 2011
X-Disclaimed: 54023
Return-Path: Chuck.Norris@hotmail.com
X-OriginalArrivalTime: 20 Mar 2015 10:43:03.0590 (UTC) FILETIME=[A48E9C60:01D062FA]

--=_related **********************=
Content-Type: multipart/alternative; boundary="=_alternative &**************"



--=_alternative ******************
Content-Type: text/plain; charset="KOI8-R"
Content-Transfer-Encoding: base64

RnJlZXppbmcgbWUsIHRha2UgbWUgYnkgbXkgaGFuZA0KU2hvdyBtZSB0aGluZ3MgSSBjYW4ndCB1
bmRlcnN0YW5kDQpGb3Igbm93IEknbGwgd2FpdCBhbmQgc2VlDQpXaGF0IHdpbGwgYmVjb21lLCB3
aGF0IHdpbGwgYmVjb21lIG9mIG1lDQpBbmQgdGltZSdzIG5vdCBnb25uYSB3YWl0LCBub3QgZm9y
IG9uZSBkYXkNCkl0J3MgZ29ubmEgYnJlYWsgdXMgdGhlIHNhbWUgd2F5DQoNClNvbWUgb2YgdXMg
bG92ZSBhbmQgc29tZSBvZiB1cyBoYXRlDQpBbmQgc29tZSBvZiB1cyBmZWFyIHRoZSBlbmQgd29u
J3QgY29tZSBvdXIgd2F5DQoNCkluIGRlYXRoLCBsaWZlLCB3aGF0J3MgbmV4dD8NClRoZSBvbm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Y2VydGFpbiBpcyBkZWF0aA0KTGlmZSwgd2hhdCdzIG5leHQ/
IElzIGl0IHRoZSBvbmx5IHRoaW5nPw0KDQpJbiBkZWF0aCwgbGlmZSwgd2hhdCdzIG5leHQ/DQpU
aGUgb25seSB0aGluZyBjZXJ0YWluIGlzIGRlYXRoDQpMaWZlLCB3aGF0J3MgbmV4dD8gSXMgaXQg
dGhlIG9ubHkgdGhpbmc/DQpJcyBpdCB0aGUgb25seSB0aGluZyBmb3IgbWU/IA==

--=_alternative ******************
Content-Type: text/plain; charset="KOI8-R"
Content-Transfer-Encoding: base64

to get first peace of base64encoded text between 

Content-Transfer-Encoding: base64

and

--=_alternative ******************

Thanks.

Help with Functions.

$
0
0

I have a code that works:

$IngInterfaceIndex = (Get-WmiObject win32_networkadapter -Filter "netconnectionstatus = 2").InterfaceIndex
Write-Host 'InterfaceIndex is ' $IngInterfaceIndex

If (( $strHostName -match "666") -OR ( $strHostName -match "SFM"))
{
 "Location is 666 and San Fran"
 Set-DnsClientServerAddress -InterfaceIndex $IngInterfaceIndex -ServerAddresses ("1.1.1.1","2.2.2.2")
}

I would like to start using functions, so i tried this:

The idea is to use the function to get the InterfaceIndex.

However i am getting an error:

Set-DnsClientServerAddress : Cannot process argument transformation on parameter 'InterfaceIndex'. Canno
value "InterfaceIndex" to type "System.UInt32[]". Error: "Cannot convert value "InterfaceIndex" to type "System.UInt32". Error: "Input string was not in a correct format.""

When i call the function first time i am getting the correct value. However when i try to use it inside Set-DnsClientServerAddressi get an error.

What am i missing?

Function InterfaceIndex
{
 $IngInterfaceIndex = (Get-WmiObject win32_networkadapter -Filter "netconnectionstatus = 2").InterfaceIndex
 Write-Host 'InterfaceIndex is ' $IngInterfaceIndex
}

If (( $strHostName -match "666") -OR ( $strHostName -match "SFM"))
{
 InterfaceIndex
 "Location is 666 and San Fran"
 Set-DnsClientServerAddress -InterfaceIndex InterfaceIndex -ServerAddresses ("1.1.1.1","2.2.2.2")
}

Thanks for the help.

Issue with Custom Build XML Query in Event Viewer

$
0
0

I'm not yet scripting this but it is the ultimate goal. I did post my issue, in the scripting guy forum, where JRV, tried to help in a very long thread: http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/08b342b3-ddd9-4929-a1f9-af9c295631e2. We have tried many different things but still no success.

The short version, I have 3 CustomView, 2 out of 3 works. My goal is to filter EventID=4662 with AccessList=%%7680. At first I thought the issue was the %%, but after more tests, I found out that the issue only occurs when I try to filter on AccessList

If you want to test this, and try to help on this issue, you will need a Windows 2008R2 with Audit Enabled. To create a 4662 EventID with AccessList %%7680, you will need to create an new Organizationalunit

-----------
#WORKS
<QueryList>
  <Query Id="0" Path="Security">
    <Select Path="Security">
*[System[(EventID='5136')]]
and
*[EventData[Data[@Name='DSType'] and Data='%%14676']]       
</Select>
</Query>
</QueryList>




-----------
# WORKS
<QueryList>
  <Query Id="0" Path="Security">
    <Select Path="Security">
*[System[(EventID='5136')]]
and
*[EventData[Data[@Name='OperationType'] and Data='%%14674']]       
</Select>
</Query>
</QueryList>




-----------
#DOES NOT WORK
<QueryList>
  <Query Id="0" Path="Security">
    <Select Path="Security">
*[System[(EventID='4662')]]
and
*[EventData[Data[@Name='AccessList'] and Data='%%7680']]       
</Select>
</Query>
</QueryList>


TIA


Cyreli

Function to run conditional on CSV and delete line if true

$
0
0

It's Friday and my brain is focusing more on the weekend than work, so I ask your help, oh PowerShell community:

I've been tasked with converting our old VB new user script to Powershell, the input of which is a CSV that HR sends us on a daily basis. On rare occasion they include someone who already exists as a user, and I'd like to write a function to check the CSV for that and remove that line in the CSV before continuing processing. So far I have the following:

Function Clear-Existing
    {
    param
        (
        [string]$path
        )
        $csv_input = import-csv -Delimiter ',' $path -Header @("EmpID","LastName","FirstName","Title","Dept","Status") | % ( $_.EmpID
        foreach ($entry in $csv_input)
            {
            if (Check-ADUser $entry.EmpID -eq $true)
                {
                write-host "user $entry already exists!"
                }
            }
    }

But being said Friday, I can't figure out how to remove the "offending" line from the CSV and save it.



zarberg@gmail.com

Viewing all 21975 articles
Browse latest View live


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