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

Hex constants with 0's above 8th digit are treated as Int32 not Int64

$
0
0
ps> 0x000000180102010.gettype() # 1 in 9th digit
IsPublic IsSerial Name                                     BaseType
True     True     Int64                                    System.ValueType

ps> 0x000000080102010.gettype() # all 0's above 8th digit
IsPublic IsSerial Name                                     BaseType
True     True     Int32                                    System.ValueType

So how do you assign 0x000000080102010 as an Int64?
Any Int64 assignment of this that I try extends the sign digit.

Also... Suppose I have the hex value in a string.
ps> $s='80102010'
How do I assign $a that hex value?

Converting a String value to Int64

$
0
0

Hi,

I have one string value 3GB which I need to convert to Int64 as a datatype constraint in Set-VMMemory command.  how to do it.

Thanks,

Mudit

Unable to Install PowerShell V5 preview on Windows 8.1 X64

$
0
0

Over the weekend, I upgraded my laptop to Windows 8.1 Enterprise (with the 8.1 update). All went well but when I go to install the WMF 5.0 preview, i get :

I have .NET 4.5 loaded and here's my winver:

Any clues to what I need to do to get this to work?


Thomas Lee <DoctorDNS@Gmail.Com>

Quest Set-QADUser bulk Attributes

$
0
0

Hello,

I have a requirement to change the Telephone Number of existing staff. Currently the staff has their officeNumber followed by Ext number.

I can export the existing telephone number and amend the CSV file to match the new number by this command;

Get-QADUser -SearchRoot 'DomainName.com/DomainUsers/Staff' | Select-Object SamAccountName, TelephoneNumber | Expo
rt-Csv C:\Scripts\UsersExtension.csv

The CSV list will be updated to match the new telephone number and will use the updated list to amend the user's telephone number.

I have used the below command but it doesn't work;

Import-Csv c:\Scripts\UsersExtension.csv | ForEach-Object {Set-QADUser -Identity $_.sAMAccountName -ObjectAttributes @{extensionAttribute $_.TelephoneNumber}

Any help to get this done, highly appreciated.

Regards,

need help, script t0 pull the details of Terminal server license server configured on list of terminal severs.

$
0
0

Sccripting gurus..

I need help with a script that can pull the details of Terminal server license server configured on list of terminal severs. 

Terminal Servers are all windows server 2003 x63

Collection of non standard PowerShell objects - how ?

$
0
0

Hi!

I write PowerShell advanced function to to query Active Directory using Exchange 2010 management shell (PowerShell 2.0).

In my function I query recipients and next for any recipient I take email addresses (proxy addresses). As a results  as a result I would like create custom objects collection.

For create any item for collection I use construction like this

$Result = New-Object PSObject

$Result | Add-Member -Type 'NoteProperty' -Name RecipientIdentifier -Value $CurrentRecipientIdentifier

$Result | Add-Member -type 'NoteProperty' -name RecipientAlias -value $CurrentRecipient.Alias

next I enumerate addresses by prefixes (using loops) and create next properties for $Result variable e.g.

[String]$CurrentPrefixAddressCountColumnName = "{0}{1}{2}" -f "AddressesForPrefix_", $CurrentPrefix, "_Count"

$Result | Add-Member -Type 'NoteProperty' -Name $CurrentPrefixAddressCountColumnName -Value $EmailsWithPrefixCount

at the end I add my $Result to $Results variable (which is intialized as $Results = @() ) using $Results += Result .

And the issue is that $Results has only properties which were added by the first $Result subobject

The full function is published at  GitHub .

Thank you in advance for any help.

      


Wojciech Sciesinski

Remove Last Element

$
0
0

Hi developer,

Get-Content .\test.txt| ForEach {
    $numberic = ($_ -split ' ')[-1].Trim()
    $numberic
    
}

aa aa aa 4
bb bb bb 3
cc cc cc 5
dd dd dd 1
ee ee ee 2

How to remove last element [3] (Numberic)?

Thanks


saperated comma and no new line after regular expression

$
0
0

Hi developer,

i am trying to read in text file. The file name is test.txt:

aa aa aa 4
bb bb bb 3
cc cc cc 5
dd dd dd 1
ee ee ee 2

Here is my sample windows powershell script:

$reg = ".........."
Get-Content .\Test.txt|Select-String -Pattern  $reg -AllMatches | ForEach-Object { $_.Matches } |
ForEach-Object { $_.Groups[0].value}

output:
aa
aa
aa
4
bb
bb
bb
3
cc
cc
cc
5
dd
dd
dd
1
ee
ee
ee
2

I want to display output like this:
aa,aa,aa,4
bb,bb,bb,3
cc,cc,cc,5
dd,dd,dd,1
ee,ee,ee,2

How to saperated comma and no new line after regular expression?

Thanks



PowerShell to search AD user attributes

$
0
0

I have searched far and wide but cannot find an answer to this problem. I was hoping a powershell guru could tell me if it is even possible.

Is there a way to use power shell to search all user attributes for a specific string? I have Office 365 yelling at me that I have a duplicate and I cannot think of where it could be. If I could search for the proxyaddress attribute and see which two users have the same it would save me from looking at every user.

Thanks in advance!

Command equivalent Sed in powershell ! please

$
0
0

Hello everyone,

I make a shell script to extract a figure on.

Here's an example where I seek to get the figure:

S-1-5-21-2266954777-2911002515-1883294743

result:

PS C: \ Users \ HACKMED \ Searches \ Pictures \ Documents \ script> whoami / ALL

User Information
------------------------

Username SID
================== ================================ ==============
hackmed-pc \ hackmed S-1-5-21-2266954777-2911002515-1883294743-1000

thank you



thank you


win32_process create fails with Unknown failure for service account user

$
0
0

I have a windows service account user, using which i'm trying to create a background process using the WMI win32_proces. But fails with Unknown Failure. (Tried this with administrator, nonadmin, domain admin, domain nonadmin users. works fine)

$process = [WMICLASS]"\\$computername\ROOT\CIMV2:win32_process"
$processinfo = $process.Create("powershell.exe -WindowStyle Hidden test.ps1")
Write-Host $processinfo.returncode

Employee separation script prompting twice for identity

$
0
0

New to Powershell here. I created the script below from a combination of several different scripts I found on the internet. We use the script for disabling accounts when we have employee separations at our company. In addition to disabling the account it also makes some changes to the user's account information in Exchange and AD.

You will notice I had to call the AD module at the end in order to handle the iPPhone value since that is not a value that can be modified through exchange.

You will also notice that the second line of the script prompts the user for the account Alias stored in value $alias. I tried to use the same $alias variable later in the script during the AD portion but for some reason it prompts me again for "Identity" and i have to put the alias in again to continue the script. Ideally I would like to only have to type the alias in one time and have it apply to the entire script. Any ideas?

#Set $alias to whatever account you want to modify
$alias = Read-Host 'Account Alias?'
#Get today's date for the description field
$date = Get-Date -Format g
#Hide account from GAL and delete all user info
Set-Mailbox -HiddenFromAddressListsEnabled $true -Identity $alias
Set-User -Phone '' -Pager '' -Fax '' -HomePhone '' -MobilePhone '' -Identity $alias
#Get AD Module
Import-Module ActiveDirectory
#Remove all groups except "Domain Users" from the user account
Get-ADPrincipalGroupMembership -Identity $alias | Where-Object {$_ -notmatch "CN=Domain Users,CN=Users,DC=domainname,DC=local"} | % {Remove-ADPrincipalGroupMembership -Identity $alias -MemberOf $_ -confirm:$false}
#Clear ipPhone attribute
$user = Get-ADUser $alias -Properties ipPhone
$user.ipPhone = $null
Set-ADUser -Instance $user
#Add today's date to description
$date = Get-Date -Format g
$disabledMsg = "Disabled on " + $date
Set-ADUser -Description $disabledMsg
#Disable and move to Disabled Users OU
Get-ADUser -Identity $alias | Disable-ADAccount
Get-ADUser -Identity $alias | Move-ADObject -TargetPath "OU=Users,OU=Disabled,DC=domainname,DC=local" -PassThru



Our Mission is to Honor and Empower Wounded Warriors...



Get-ADUser lastLogonTimestamp is reporting blank

$
0
0

Hey guys,

I'm simply looking to get a list of users and their last login, in it's simplest form I'm trying this:

Get-ADUser -filter * -searchbase 'CN=Users,DC=domain,DC=com,DC=au' -Properties name,lastLogonTimestamp | select name,lastLogonTimestamp | out-gridview

Which works in a way, the problem is that most of the 'lastLoginTimestamp' properties are empty. If I go through AD Explorer (from SysInternals) there is definitely a value in that property.  Even if I test with my own user name that logs in every day it returns blank.

If they were all blank I would look at a problem in the script, but some of them DO return the correct value.

Is there something I'm missing?


Powershell command for adding permissions in the "winrm configsddl wmi" menu

$
0
0

Hello,

I was wondering if there was any powershell command that would be the equivalent of adding a user in the menu brought up by typing

winrm configsddl wmi

I want to be able to add Read permission for users.

Thanks,

Brian

Description field in AD

$
0
0

I like to pull “Description” field in AD under the general tab of the service account.
Any suggestion?
Thanks.


Ping multiple servers from a list of IP addresses using Powershell and find out the least response time

$
0
0

Hi,

I have a CSV file wherein i have a list of IP addresses. I would like to use Test-Connection to ping 3 domain controllers one from each of my sites from each IP address in the list to verify which gives me the least response time. So the Test connection needs to be between each IP address in the CSV and three domain controllers. A script to compare the response time between the three with each IP and return the domain controller with the least for that IP address.

I used Test-connection like 

Test-Connection -Source Server02 -ComputerName Server01

where Server02 is the IP address in the CSV and Server01 is the domain controller. However i get the error : The RPC Server is unavailable.

Please help!!

Fetch client IP addresses from the Netlogon.log file of all domain controllers in the domain

$
0
0

Hi,

The event ID 5807 is logged in the system logs of domain controllers as a result of which the IP addresses for the missing subnets are logged in Netlogon.log under %systemroot%/debug. The end goal is to fetch the IP addresses along with rest of the respective attributes from the Netlogon.log for all the domain controllers in the domain. I have the following script however, it gives me a 0KB file despite the fact that the Netlogon.log on the DC contains ample entries from last two months. 

function GetDomainControllers {
    $DCs=[system.directoryservices.activedirectory.domain]::GetCurrentDomain() | ForEach-Object {$_.DomainControllers} | ForEach-Object {$_.Name}
    return $DCs

}

function GetNetLogonFile ($server) {
    $path= '\\' + $server + '\c$\windows\debug\netlogon.log'
    try {$netlogon=get-content -Path $path -ErrorAction stop}
    catch { "Can't open $path"}
    #reverse the array's order to the end of the file
    [array]::Reverse($netlogon)
    $IPs=@()
    foreach ($line in $netlogon) {
        #split the line into pieces using a space as the delimiter
        $splitline=$line.split(' ')
        #Get the date stamp which is in the mm/dd format
        $logdate=$splitline[0]
        #split the date
        $logdatesplit=($logdate.split('/'))
        [int]$logmonth=$logdatesplit[0]
#last month and this month
        if (($logmonth -eq $thismonth) -or ($logmonth -eq $lastmonth)) {
            #only push it into an array if it matches an IP address format
            if ($splitline[5] -match '\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b'){
                $objuser = new-object system.object
                $objuser | add-member -type NoteProperty -name IPaddress -value $splitline[5]
                $objuser | add-member -type NoteProperty -name Computername -value $splitline[4]
                $objuser | add-member -type NoteProperty -name Server -value $server
                $objuser | add-member -type NoteProperty -name Date -value $splitline[0]
                $objuser | add-member -type NoteProperty -name Time -value $splitline[1]
                $IPs+=$objuser
            }
        } else {
            #break out of loop if the date is not this month or last month
            break
        }
    }
    return $IPs
}

#Get last month's date
$thismonth=(get-date).month
$lastmonth=((get-date).addmonths(-1)).month

#get all the domain controllers
$DomainControllers=GetDomainControllers
#Get the Netlogon.log from each DC
Foreach ($DomainController in $DomainControllers) {
    $IPsFromDC=GetNetLogonFile($DomainController)
    $allIPs+=$IPsFromDC
}

$allIPs | Sort-Object -Property IPaddress -Unique | Export-Csv "E:\bin\NetlogonIPs.csv"

PLEASE HELP!!

Get Listing of HKEY_USERS hive

$
0
0

I am looking to get only the printer names under HKEY_USERS\SID\Software\Microsoft\Windows NT\CurrentVersion\Devices. Just  the name. This is what I get so far:

get-childitem "HKEY_USERS\S-1-5-21-53361137-2144680551-1845911597-29023\Software\Microsoft\Windows NT\CurrentVersion\Devices" -Recurse | select name

But I am no getting any results. 

Importing multiple CSV files to a single XLSX file

$
0
0

I've got a powershell script that does a weekly compare of 2 large files, then divides the results up to create 9 or 10 CSV files.  I want to take those files and import the data into an XLSX file in one step.

$Excel = New-Object -ComObject excel.application
$Excel.visible = $true
$workbooks = $excel.Workbooks.Add()
$worksheets = $workbooks.worksheets
$worksheets.add()
$worksheets.add()
$worksheets.add()
$worksheets.add()
$worksheets.add()
$worksheets.add()
$worksheets.add()
$worksheets.add()
$worksheets.add()


$worksheet1 = $workbooks.sheets.Item(1)
$worksheet1.Name = "All"
$worksheet2 = $workbooks.sheets.Item(2)
$worksheet2.Name = "UAC"
$worksheet3 = $workbooks.sheets.Item(3)
$worksheet3.Name = "AS"
$worksheet4 = $workbooks.sheets.Item(4)
$worksheet4.Name = "BT"
$worksheet5 = $workbooks.sheets.Item(5)
$worksheet5.Name = "CR"
$worksheet6 = $workbooks.sheets.Item(6)
$worksheet6.Name = "CS"
$worksheet7 = $workbooks.sheets.Item(7)
$worksheet7.Name = "CE"
$worksheet8 = $workbooks.sheets.Item(8)
$worksheet8.Name = "CN"
$worksheet9 = $workbooks.sheets.Item(9)
$worksheet9.Name = "PH"
$worksheet10 = $workbooks.sheets.Item(10)
$worksheet10.Name = "Other"

#Define the connection string and where the data is supposed to go
$TxtConnector = ("TEXT;" + $exportfileexcel)
$CellRef = $worksheet1.Range("A1")

#Build, use and remove the text file connector
$Connector = $worksheet1.QueryTables.add($TxtConnector,$CellRef)
$worksheet1.QueryTables.item($Connector.name).TextFileCommaDelimiter = $True
$worksheet1.QueryTables.item($Connector.name).TextFileParseType  = 1
$worksheet1.QueryTables.item($Connector.name).Refresh()
$worksheet1.QueryTables.item($Connector.name).delete()

$worksheet1.UsedRange.EntireColumn.AutoFit()


#Define the connection string and where the data is supposed to go
$TxtConnector2 = ("TEXT;" + $export00excel)
$CellRef2 = $worksheet2.Range("A1")
#Build, use and remove the text file connector
$Connector2 = $worksheet2.QueryTables.add($TxtConnector2,$CellRef2)
$worksheet2.QueryTables.item($Connector2.name).TextFileCommaDelimiter = $True
$worksheet2.QueryTables.item($Connector2.name).TextFileParseType  = 1
$worksheet2.QueryTables.item($Connector2.name).Refresh()
$worksheet2.QueryTables.item($Connector2.name).delete()
$worksheet2.UsedRange.EntireColumn.AutoFit()

#Define the connection string and where the data is supposed to go
$TxtConnector = ("TEXT;" + $exportASexcel)
$CellRef = $worksheet3.Range("A1")
#Build, use and remove the text file connector
$Connector = $worksheet3.QueryTables.add($TxtConnector,$CellRef)
$worksheet3.QueryTables.item($Connector.name).TextFileCommaDelimiter = $True
$worksheet3.QueryTables.item($Connector.name).TextFileParseType  = 1
$worksheet3.QueryTables.item($Connector.name).Refresh()
$worksheet3.QueryTables.item($Connector.name).delete()
$worksheet3.UsedRange.EntireColumn.AutoFit()

#Define the connection string and where the data is supposed to go
$TxtConnector = ("TEXT;" + $exportBTexcel)
$CellRef = $worksheet4.Range("A1")
#Build, use and remove the text file connector
$Connector = $worksheet4.QueryTables.add($TxtConnector,$CellRef)
$worksheet4.QueryTables.item($Connector.name).TextFileCommaDelimiter = $True
$worksheet4.QueryTables.item($Connector.name).TextFileParseType  = 1
$worksheet4.QueryTables.item($Connector.name).Refresh()
$worksheet4.QueryTables.item($Connector.name).delete()
$worksheet4.UsedRange.EntireColumn.AutoFit()

#Define the connection string and where the data is supposed to go
$TxtConnector = ("TEXT;" + $exportCRexcel)
$CellRef = $worksheet5.Range("A1")
#Build, use and remove the text file connector
$Connector = $worksheet5.QueryTables.add($TxtConnector,$CellRef)
$worksheet5.QueryTables.item($Connector.name).TextFileCommaDelimiter = $True
$worksheet5.QueryTables.item($Connector.name).TextFileParseType  = 1
$worksheet5.QueryTables.item($Connector.name).Refresh()
$worksheet5.QueryTables.item($Connector.name).delete()
$worksheet5.UsedRange.EntireColumn.AutoFit()

#Define the connection string and where the data is supposed to go
$TxtConnector = ("TEXT;" + $exportCSexcel)
$CellRef = $worksheet6.Range("A1")
#Build, use and remove the text file connector
$Connector = $worksheet6.QueryTables.add($TxtConnector,$CellRef)
$worksheet6.QueryTables.item($Connector.name).TextFileCommaDelimiter = $True
$worksheet6.QueryTables.item($Connector.name).TextFileParseType  = 1
$worksheet6.QueryTables.item($Connector.name).Refresh()
$worksheet6.QueryTables.item($Connector.name).delete()
$worksheet6.UsedRange.EntireColumn.AutoFit()

#Define the connection string and where the data is supposed to go
$TxtConnector = ("TEXT;" + $exportEDexcel)
$CellRef = $worksheet7.Range("A1")
#Build, use and remove the text file connector
$Connector = $worksheet7.QueryTables.add($TxtConnector,$CellRef)
$worksheet7.QueryTables.item($Connector.name).TextFileCommaDelimiter = $True
$worksheet7.QueryTables.item($Connector.name).TextFileParseType  = 1
$worksheet7.QueryTables.item($Connector.name).Refresh()
$worksheet7.QueryTables.item($Connector.name).delete()
$worksheet7.UsedRange.EntireColumn.AutoFit()

#Define the connection string and where the data is supposed to go
$TxtConnector = ("TEXT;" + $exportNUexcel)
$CellRef = $worksheet8.Range("A1")
#Build, use and remove the text file connector
$Connector = $worksheet8.QueryTables.add($TxtConnector,$CellRef)
$worksheet8.QueryTables.item($Connector.name).TextFileCommaDelimiter = $True
$worksheet8.QueryTables.item($Connector.name).TextFileParseType  = 1
$worksheet8.QueryTables.item($Connector.name).Refresh()
$worksheet8.QueryTables.item($Connector.name).delete()
$worksheet8.UsedRange.EntireColumn.AutoFit()

#Define the connection string and where the data is supposed to go
$TxtConnector = ("TEXT;" + $exportPUexcel)
$CellRef = $worksheet9.Range("A1")
#Build, use and remove the text file connector
$Connector = $worksheet9.QueryTables.add($TxtConnector,$CellRef)
$worksheet9.QueryTables.item($Connector.name).TextFileCommaDelimiter = $True
$worksheet9.QueryTables.item($Connector.name).TextFileParseType  = 1
$worksheet9.QueryTables.item($Connector.name).Refresh()
$worksheet9.QueryTables.item($Connector.name).delete()
$worksheet9.UsedRange.EntireColumn.AutoFit()

#Define the connection string and where the data is supposed to go
$TxtConnector = ("TEXT;" + $exportOTexcel)
$CellRef = $worksheet10.Range("A1")
#Build, use and remove the text file connector
$Connector = $worksheet10.QueryTables.add($TxtConnector,$CellRef)
$worksheet10.QueryTables.item($Connector.name).TextFileCommaDelimiter = $True
$worksheet10.QueryTables.item($Connector.name).TextFileParseType  = 1
$worksheet10.QueryTables.item($Connector.name).Refresh()
$worksheet10.QueryTables.item($Connector.name).delete()
$worksheet10.UsedRange.EntireColumn.AutoFit()

This script opens Excel and creates/renames all of the tabs, then populates the first worksheet with the correct data.  However, the rest of the worksheets don't import and I get these errors:

"Exception calling "Add" with "2" argument(s):  "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"

Help please Powershell : Script telnet to test multiple server's

$
0
0

Hello,

I am writing to you, I look a little script in powershell for testing:

 telnet www.s.code42.fr 2345

telnet localhost 23

telnet localhost 10000

 

after the execution should show me if OK for access or Failed to access for the three test.

 

thank you a lot.

 This a code but just for one test 


achraf

Viewing all 21975 articles
Browse latest View live


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